1

I am really newbie in all this marketing stuff, so I understand everything much better on the software layer. Phrases like : "Add this script to your page directly after body tag and it will work" confuse me.
So I want to get understanding of GTM and Data Layer
Here are most important questions for me.
This is how I understand this stuff.

  1. As far as I know, GTM is just piece of JavaScript code loaded with the page, it is useful because as I can guess this part of the code provided by Tag Manager Account ( I will use GTM_JS name for it) is used to send request to the Google Tag Manager server, it contains your credentials and retrieves information set up in your personal GTM account like tag.GTM_JS After retrieving information from the server, for instance piece of HTML and JS code like Google Analytics inserts it in the DOM. The same if you add required code Google Analytics manually. And it works the same, but the benefit here is that you can dynamically include any code without editing sources of your template or php files, only GTM_JS is required.

  2. What is exactly Data Layer is. I understand that this is just an array of data you need to pass somewhere. I can only guess that while GTM_JS is loaded it checks dataLayer variable if it contains any information, if so send it to the GTM Server, GTM Server in turn checks all your Macros and Regex (I don't know all features of GTM), and parses dataLayer variable, only after that it starts processing all created tags, because, some tags code may contain macro definition like {{product_price}} and if it finds such definition it inserts in output tag code specific variable.

  3. After that GTM Server does some other stuff and returns just simple HTML code as a response to GTM_JS, and than this code is added to the DOM.

And questions

  1. Why I cannot find tag source code in Page Source, but it works ? Is it hidden somehow ?
  2. As I can guess, data pushed to the data layer, should be generated firstly with server side script like php,ruby,python, for example User id is available only while generating output HTML in some Php session variable and you need output like <script> var dataLayer.userId = $user_id;</script> (pseudocode). So why I cannot dynamically use my generated variable without dataLayer, just to specify it in desired script code inserted to the page (the same as for dataLayer) ? What is the benefit of using DataLayer than ?

I would be grateful for any response. Thanks.

1

1) The tag source is included at runtime from GTM_JS. You won't be able to see it, just the GTM snippet.

2) You are correct that you could go ahead and use the variable in your page. Where the magic happens in GTM is when you need a variable in one of your tags. For example, I set a user's status (logged in or anonymous) as a Custom Dimension in Google Analytics. The only way to pass this status is through the data layer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.