Вопрос

Need some advice in relation to giving our developers the code for the dataLayer that is to be used along with the GTM code. If the dataLayer is to be on every page along with the container tag code, how do i define all variables for many events across the domain?

dataLayer = [];

I've read that using macros is the best way going forward, which should mean less time dealing with the developers in the future. I'm not a coder so i'm struggling to understand what code to give. Struggling with the current lack of documentation for non-developers.

The website is a non-ecommerce site but we track many events as micro-conversions.

Это было полезно?

Решение

Ninjasys,

your code is correct :-). You have successfully implemented GTM data layer (it should be before GTM tag itself in the source code of your webpage).

The only thing you need to do now is to fill it. You can either specify its items when the page loads (if there is a need for that), or you can push updates to it when a user does something (like clicks on the button / selects a drop-down value).

Using onclick attributes is the easiest way -- simply add:

onclick="dataLayer.push({'event': 'EventFire-TopMenu', 'EventCategory': 'Navigation', 'EventAction': 'Menu', 'EventLabel': 'QuickCheck'});"

With this code, you are telling GTM to track an event. Setup 3 macros that will retrieve the values from data layer (EventCategory, EventAction and EventLabel) and then set a rule to trigger a Google Analytics Event Tag with the condition being event equals EventFire-TopMenu.

Keep in mind that you can pick any names you want, I just copied the example above from one of my webpages. I would also suggest reading few articles about event listeners that GTM introduced few months back, it makes your life a lot easier.

But I hope this simple example will get you started.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top