After a few hours head scratching I was finally able to make sense of the lunametrics code which essentially looks for embedded YouTube video(s) on your page and triggers event tracking on Google Analytics for:

  • Unstarted
  • Play
  • Watch to End
  • Pause
  • Buffering
  • Cueing

1. Insert the following code into page inside the body tags:

<script src="//"></script>

*Page obviously must have Google Analytics tracking code within the <head> tags

HTML page e.g.:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', 'UA-XXXXXXX-XX', 'auto');
ga('send', 'pageview');



<script src="//"></script>
<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>

2. You can download Lunametrics script from here and place anywhere within the website directory if you wish to host the script.

*If not in the same location as the web page change the script src in step one to match script location. e.g. <script src=”/path/to/lunametrics-youtube-v7.gtm.js”>

3. Open page and Play, Pause etc. video. Now take a look at Real Time within Google Analytics. You should see something similar to:



Credit goes to –

Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: