I have users that belong to different groups. Let’s assume it’s just group “a” and group “b”. I now want to create a segment for each of the two groups. I then want to use the segments to view the reports only for users of group “a” or group “b”.
I’m using the the SDK like so:
import { DataLayer as PiwikDataLayer } from '@piwikpro/react-piwik-pro';
PiwikDataLayer.push({ group: 'a' });
Please make sure you only set the dimension value when you have a value, because the last value you push, will be that value that is stored and available in Analytics.
By the way, custom variables are depricated, so I wouldn’t use them.
Thanks for getting back to me. Unfortunately, I’m super confused and stuck again.
I followed “Create a session custom dimension” in the link you provided. I successfully set up a session dimension and once I have the information in the frontend, I do the following:
import { DataLayer as PiwikDataLayer } from '@piwikpro/react-piwik-pro';
PiwikDataLayer.push(['setCustomDimensionValue', 2, 'a']);
However, I’m stuck at step 14 “Set up the variable”. What exactly do I have to do here?
Naively, I believed that after creating a session dimension, I could immediately go to “Add a segment” in the Analytics settings and do the following:
When I do this, however, it says there is no data. So I assume the steps from 14 onwards in your guide can’t be skipped. By why is it necessary to set up a session dimension, a variable and a tag before I can create the actual segment?
I want to show again what I’m trying to achieve. I want to have two segments “Group A” and “Group B” and I want to filter the data in the reports to see the data only for visitors from group A or group B.
The confusion probably is coming from the fat that you are currently sending data to the dataLayer (this is a great way to use the tagManager and use triggers and tag for certain events or values)
What you need to do to send the data to Analytics, is either use the Tag Manager and connect the dataLayer values to analytics, or send the data directly to analytics via the custom dimensions method:
Make sure to set the custom dimension value before sending the pageview event, because the setCustomDimensionValue sets a custom dimension value to be used later (it will be added to the next action you send to Analytics, e.g. a Page View, custom event ping or Goal)