google-analyticsgoogle-tag-managerdata-layers

Display data passed into dataLayer in Google Analytics using GTM


How can I display data passed into dataLayer in Google Analytics using GTM?

Let me share with you what I was able to do so far.

1 There is a part in my client side JavaScript code from where I am sending a data. I am doing it in this way: dataLayer.push({startedPlaying: true});.

2 Now in GTM I am getting the data in a Message format: enter image description here

Now I would like to send the data directly to Google Analytics. And in Google Analytics I would like to keep track of how many times such a message was sent from the client (in my example it means how many times a song play button was clicked).

I understand that the question may be a little bit too broad, but if it is so, then answer it is broadly as well, so that I got my next learning directions in the matter. Thank you.


Solution

  • So instead of sending startedPlaying: true, try sending event: 'started-playing'this is how you send a datalayer event.

    Then configure a custom event trigger in GTM to trigger off of the "started-playing" datalayer event. enter image description here

    Then create a Google Analytics tag of the "event" type and put in all the event information about this event to be sent to GA and attach the trigger created above. Like so: enter image description here