How to create data layer for Google tag manager

Vote:
 

Hi,

I want to create data layer for Google Tag Manager which will be a script with dynamic data in body section of all pages.

Can anyone please explain how can we implement it(through SitePageData etc) with an example.

Thanks in advance.

Best Regards,

Sanket Mahimkar

#151536
Jul 27, 2016 11:43
Vote:
 

Put the script in your layout view and populate the values from your model or logic, e.g:

<script>
window.dataLayer = window.dataLayer||[];
window.dataLayer.push({
	'content.pagetype': '@Model.PageTypeName',
.......
});
</script>
#162123
Oct 11, 2016 12:33
Vote:
 

Hi!

On the same topic...

I would like to push to the datalayer for Google Tag Manager when a visitor visits a specific page, but the issue is the push needs to come before the GTM container. 

Since it is only for a specific type of page I can not place it in the head of global Layout-file.

Now I am wondering, how do I manage to get the push before the GTM container loads on the page? 

Thanks in advance!

Regards, 

Sophie Hillebrant

#215839
Jan 15, 2020 13:55
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.