I will tell you how to configure GTM and GA for an event.
Follow the below steps, and maybe you can modify to your own particular requirement.
- First create variables which you are going to use in your datalayer.
ex -
window.dataLayer = window.dataLayer || [];
window.addEventListener('scroll', function (event) {
window.dataLayer.push({
'event': 'scroll',//event name configured in trigger
'username': '123456', //configured as variable in Tags
});
});
The above example will send data to GA every time you scroll the page.You can create your event listener based on your requirements.
So in above example create a variable named username.Click on New in User Defined variables,click on variable configuration and select data layer variable.
- Click on Triggers and create an custom event,the event name should be same as event in your datalayer.
- Create a Tag Google Analytics - Universal Analytics with trigger filtering pointing to the previous trigger you created.While configuring GA fields you can use previously created variables which will be visible like this-{{username}}.
You can test this in preview mode and see which triggers are fired and what is the datalayer that is pushed to google analytics.
In GA to see live data of your debugging, go to Real Time -> Events