0

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.

Yaroslav Trofimov
  • 313
  • 2
  • 4
  • 16

1 Answers1

1

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

XTOTHEL
  • 5,098
  • 1
  • 9
  • 17
  • Ok, thank you a lot. I was able to do everything you explained. But how can I keep a count of how many times the audio was started on my website in Google Analytics? In other words how can I increment a value in Google analytics each time someone starts to listen an audio? – Yaroslav Trofimov Nov 03 '18 at 21:29
  • Actually I see no point in using event instead of a raw variable. Could you explain why it is better to use an event, please? – Yaroslav Trofimov Nov 03 '18 at 21:41
  • Why do you want to increment it? Using an event so that you can use GTM to create a trigger easily. What additional information do you gain for using "started-playing: true"? – XTOTHEL Nov 03 '18 at 22:37
  • Ok, I see the point now, thank you. One last question, what GA and GTM should I cover in order to implement the following: there is an audio file on my website, I want to see in GA how many users started listening the audio, how many reached 25% of audio, 50% etc. I have no issue accessing the data inside website itself (for one user), now I want to be able to see the data (for all users) in GA and send the data from website to GA through GTM. I am very new to GA, what should I cover to be able to implement the above? Thank you. – Yaroslav Trofimov Nov 03 '18 at 22:52
  • How is the audio file hosted? Do you know how to get the % reached? – XTOTHEL Nov 03 '18 at 23:02
  • Yes, I possess all the needed data when on client side. It is just a matter of presenting the data in the correct format and sending it to GTM and then restructuring it there and sending up to GA for displaying. – Yaroslav Trofimov Nov 03 '18 at 23:09
  • Could you create a short chat for us? I believe I lack privileges right now. – Yaroslav Trofimov Nov 03 '18 at 23:09
  • https://chat.stackoverflow.com/rooms/183065/display-data-passed-into-datalayer-in-google-analytics-using-gtm – XTOTHEL Nov 03 '18 at 23:12