This will track if a user Plays, Pauses or Finished a video. It will also record progress of the video that has been watched in increments of 25. So it will track 25%, 50% and 75% on top of the initial 3.
This is not my original work, I have just modified it a bit from another source to work in the case I need. Such as adding the title as an available attribute for Analytics sake.
Original Repo: https://github.com/lunametrics/youtube-google-analytics
I have automated this the best I can so you can just import gtm-import.json and just update the UA code. You can also update the category if you would like to customize how it will show up in Analytics.
To update your UA code after you have imported the json file go to Tags > YouTube Video Interaction and update the Web Property ID to yours. This can be found in your Analytics Dashboard in the properties section of UA project you wish to track the data too.
Make sure you are in your GTM container, then follow the steps :)
-
Creating DataLayers
-
Triggers
Go to Tags and do the following 2 steps
-
Send Data to Analytics
- Create a New Tag
- Choose Universal Analytics
- Enter your Analytics ID from your Analytics Property
- Track Type: Event
- Category: YouTube Video Tracking (you can make this whatever you want)
- Action:
{{Video Interaction}}
- This will report, PLay, Pause, 25% Watched, etc
- This can be adjusted in the JS file if you need and know what you are doing.
- Label:
{{Video Title}}
- This could also be sorted by the URL using
{{Video URL}}
- This could also be sorted by the URL using
- Add a trigger and choose YouTube Video Interaction
-
Custom HTML