Try our conversational search powered by Generative AI!

How to create data layer for Google tag manager



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

Jul 27, 2016 11:43

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

window.dataLayer = window.dataLayer||[];
	'content.pagetype': '@Model.PageTypeName',
Oct 11, 2016 12:33


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!


Sophie Hillebrant

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.