Reputation: 3666
I created a google analytics account for my website and created google tag manager account too. And both of the accounts are linked and working well.
I have a new requirement which is , my client wants users to allow chance to edit there webpage and create custom templates.
Scenario is ,
User log in to the system Go to genaral page Use genaral page or edit genaral page and create custom template for it Next time user log in to the system and go to the genaral page , User created Custom template appear as genaral page, But same URL
If you can get the point , Same URL but the content is different ,
I applied google tag manager to track those pages, Because of having same URL its tracking as a same url,
But I want to track the page by content and track user if user used my genaral template or custom template.
Hope any one will have a idea to how to create Google Tag or Macro or Rule , Or custom java script for it.
Thanks in advance
Upvotes: 0
Views: 157
Reputation: 32780
By far the best way would be to include a dataLayer variable into your templates that indicated which template is being used. Best to include it above the tag manager code:
<body>
<script>
dataLayer = [{
'template': 'default',
}];
</script>
<!-- Google Tag Manager -->
...
<!-- End Google Tag Manager -->
so it's immediatly available when the GTM code loads. Then create a dataLayer variable in GTM that reads the value for the "template" key from the dataLayer and pass it as a hit based custom dimension to Google Analytics (i.e. in the property settings in GA under "custom definitions" you create a new custom dimension and set the scope to "hit"; in GTM you go to "more settings/custom dimensions", add the numeric index of the dimension you have just created and pass your new dataLayer variable as dimension value). Then you can segment your page hits in Google Analytics based on template type.
I'm sure it would be also possible to track by content (i.e. you could load the content into a js string variable, create a hash value from the string and send that as a custom dimension), but that would mean even fixing typos would result in a new id. Using a variable per template seems much more prudent.
Upvotes: 3
Reputation: 422
If supposedly your different templates have some ID's in the code - you can use this ID as identifier for the template and create variable to check if the ID is present, then fire it in GA, in similar way as the Eike's description.
But this is the sloppy way, and it's an option if you have no way to create dataLayer push for the new templates, as described by Eike. Otherwise the dataLayer push is the better way to do the job.
Upvotes: 0