I want to put a GTM container on my webpage, just to add scripts without modify html of my page (I will no longer have acces).
1)Currently, I just put the GTM code after , created a tag on my GTM account (tag type = GA), added UA-XXXXX-Y of my GA account : it’s work, I can see visit from my GA acc.
2)Then, I tried to change the type of my tag created on GTM : I choose Custom HTML type, and I put the code given by GA (with correct UA)
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-Y']);
_gaq.push(['_setDomainName', 'example.com']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
It’s work too, I see visit from GA interface
3) I want to modify the code given by GA, especially add trackPageview with param (using server variable, here’s my problem…)
So I just modified code that I used in 2), just adding :
_gaq.push(['_trackPageview', '/Page1/$!{VAR}/Page2/$']);
and it doesn’t work.
Did I do something wrong? Should I use macro?
Thanks
Serverside variables are not going to work with GTM (since the code is inserted via javascript from a different server) so yes, a macro ist the way to go.
Create a data layer (a JSON var that is inserted after the opening body tag just before the GTM tag:
Now you can access myVar as a macro in GTM ( “{{myVar}}” ):
This also works with the GA tag template in GTM (there is an option to insert a virtual url, you can use macros there).