mickey / videojs-ga

Google Analytics plugin for video.js
MIT License
138 stars 109 forks source link

Update to handle Google Tag Manager using dataLayer #13

Open penguinstampede opened 10 years ago

penguinstampede commented 10 years ago

I needed the script to work with GTM, so I added a bit of code to check for the dataLayer variable. See https://developers.google.com/tag-manager/devguide

mickey commented 10 years ago

Hey @penguinstampede thanks for the PR. I'm not very familiar with GTM but according to the documentation the dataLayer can eventually be renamed.

Ideally I would detect the dataLayer whatever his name is. I searched a couple of minutes and didn't find any way to do this. I'll check againg tonight or t-row. If I don't, I'm inclined to accept your PR + add an option to pass the dataLayer. What do you think?

Cheers

phildpearce commented 9 years ago

@mickey & @penguinstampede

Great plugin & a life saver!

But, needs some small refinements...

  1. Its strongly recommended to use eventNonInteraction (NOT nonInteraction)
  2. eventNonInteraction is incorrect set to "true" on the play click and percent played. Both these interactions should improve bounce rate. Pls change to: sendbeacon('play', false, currentTime); // PP changed to false sendbeacon('percent played', false, percent); // PP changed to false
  3. It is best to explicitly declare 'eventCategory': 'video' (even though this is the same as 'event': 'video').
  4. Please add 'videoId' this is needed for GA`s new server-side data append feature called dimension widening via CSV upload.

Updated example... http://83.223.104.160/~searchph/_testing_script/__itv/gtm-code-examples/videojs-ga-f20f7478752c221ebde9a98e6602f1394d26c3e7/dist/videojs.ga.js

dataLayer.push({ 'event': 'video', 'eventCategory': 'video', // Added 'eventAction': action, 'eventLabel': eventLabel, 'eventValue': value, 'eventNonInteraction': nonInteraction, // Changed 'videoId': '' // Added - CustomDimension - Used for server-side data append });

Thanks

Phil. GTM specialist Useful ReadMe: http://bit.ly/gtmdevguide2

tylerhunt commented 8 years ago

Any updates on this?

Gaebou commented 7 years ago

This js https://github.com/BrightcoveOS/videojs-ga-videocloud handles GTM. You just need to adjust labels to merge datas in analytics.