简体   繁体   中英

Pushing Events to DataLayer in Google Tag Manager

I was studying Google Tag Manager and I am not able to understand Pushing Events to DataLayer

Pushing events to the dataLayer allows you to separate your application code from tags you might want to fire in response to those events.

What does it mean by separating application code from tags?What is DataLayer?

and whats is below line doing-

dataLayer.pushEvent("openScreen", DataLayer.mapOf("screenName", screenName));

What is openScreen and screenName .Are these tags registered for this app in Google Tag Manager? Please explain in simple words?

I think the documentation explains the dataLayer rather well when it says

The data layer is a map holding generic information about the application. It uses a standard set of keys so it can be read by any party that understands the specification. The data layer state is updated through its API.

Conceptually the dataLayer is a container for application information that can be updated at runtime.

You have actions in your application that you want to track, eg when somebody opens a certain "page", or screen in your app - that would the openScreen event in your example.

Opening a new screen means that new information becomes available that need to be tracked, in this case the name of the new screen. That's the DataLayer.mapOf("screenName", screenName) part - you have a value that is set via the screenName variable in your application and can be access in the dataLayer by the key of (in this example also) 'screenName' (the key is the name in quotes, the value is the variable that follows).

In theory you could make your application code respond directly to an event, like firing a call to your analytics software and/or your marketing partners etc. when a new screen is opened. However by todays standards this is considered inefficient, not in the least because you'd need a new version of the app every time you change tracking software.

So instead you put the information in your generic container, the dataLayer. Then the tag manager software inspects the dataLayer any time you push an event; it pick ups the added information and can distribute it to one or many tracking tags that are configured in your GTM backend.

So now you have "separated application code from tag" by putting the tag manager with its dataLayer in place as an intermediate layer that takes information from the application code at one side and distributes it to multiple configurable marketing tags on the other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM