Coder Social home page Coder Social logo

youtube-google-analytics's Introduction

YouTube Google Analytics & GTM Plugin

As of 9/12/17, Google Tag Manager offers native support for tracking YouTube videos (including proper titles!). If you're looking to use GTM to track YouTube videos, we'd recommend using their native integration over our script.

This is a plug-and-play tracking solution for tracking user interaction with YouTube videos in Google Analytics. It will detect if GTM, Universal Analytics, or Classic Analytics is installed on the page, in that order, and use the first syntax it matches unless configured otherwise. It include support for delivering hits directly to Universal or Classic Google Analytics, or for pushing Data Layer events to be used by Google Tag Manager.

Once installed, the plugin will fire events with the following settings:

  • Event Category: Videos
  • Event Action: <Action, e.g. Play, Pause>
  • Event Label: <URL of the video>

By default, the plugin will track Play, Pause, Watch to End, and 10%, 25%, 50%, 75% , and 90% viewed events. The plugin can be configured to track whatever percentages are desired and/or not track Play, Pause, or Watch to End events.

The plugin will automatically bind to all videos on the page on DOMContentLoaded (window.load on IE8). The plugin will also bind to videos added inserted dynamically after DOMContentLoaded, as long as the following parameters are present in the src attribute of the iframe, e.g.:

<iframe src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1&origin=http%3A%2F%2Fwww.example.com"></iframe>    

Installation & Documentation

For installation instructions and complete documentation, visit http://www.lunametrics.com/labs/recipes/youtube-tracking/#documentation.

License

Licensed under the MIT License. For a complete copy of the license, please refer to the LICENSE.md file included with this repository.

Acknowledgements

Created by the honest folks at LunaMetrics, a digital marketing & Google Analytics consultancy. For questions, please drop us a line here or on our blog.

Written by Dan Wilkerson. Versions 1 - 6 written by Sayf Sharif.

youtube-google-analytics's People

Contributors

bgradin avatar danherd avatar danilopolani avatar danwilkerson avatar jevy avatar lunametrics avatar lunasayf avatar plugin-kevin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

youtube-google-analytics's Issues

Using getVideoData for Video Titles - KNOWN ISSUE

This comes up frequently enough that I've decided to post this as a known issue: we're aware of the getVideoData method that the API loads in. However, in testing, we found this API method was frequently not included in the library delivered by YouTube, resulting in an exception being thrown and no data being collected.

Rather than engineer it to degrade/fallback to something, we decided to just use the URL for the sake of consistency, ease of use, and durability.

Feature Request: Named Trackers

Hi,

I noticed that the Plugin does not support named Trackers.
In my setup I need to track with mutliple Tracking Codes.

e.g.
ga('create', 'UA-XXXXXXXX-1', 'auto',{'name': 'Tracker00'});
ga('Tracker00.set', 'anonymizeIp', true);
ga('Tracker00.send', 'pageview');
ga('create', 'UA-XXXXXXXX-2', 'auto',{'name': 'Tracker01'});
ga('Tracker01.set', 'anonymizeIp', true);
ga('Tracker01.send', 'pageview');

The Script seemingly does not support that.
I am getting in to work to add the Name to the unminified JS in line 388.
But that is not Ideal.

Update: I found the property datalayername, but that should be for GTM, right?

Making events available for use before being sent off to GA

Hi,

I have been working on pulling Video event information into my application for my own use. I have experimented with two ways of doing so - pulling the information from Google Analytics after this library has sent it there, and pulling the information before it gets sent. I like pulling the information before it gets sent better - fewer API calls. I've been tweaking your library so that I can pull tracking data from the library for use in my application, and was wondering if you might welcome a pull request which adds the ability for everyone who uses this library to do so. It may be outside the scope of this project, but I've been working on the code anyway so I thought I would pass it by you.

Thank you for this library - it's been amazingly helpful and working with it has taught me quite a lot about how to interact with both YouTube and Google Analytics.

Have a good afternoon!

missing VAR declaration in function

I was getting a "key is undefined" error. You need to add the VAR declaration in your for loop in the checkCompletion function (line 203).

for(var key in marks)

% tracked for related videos

The % tracked events fire only for the primary embedded video. If the user watches the video to the end and click on a related video, only the Play, Pause, Watch to End and other related events are pushed to the data layer by Tag Manager, but not the % watched. It would be useful to track the % watched in all videos that the user watches.

Add support for gtag

Analytics now promotes using the gtag.js API.

Add a forceSyntax/fallback that does this:

//window[_ga]('send', 'event', 'Videos', state, videoUrl);
gtag('event', 'play', {
  'event_category': 'Videos',
  'event_label': videoUrl,
  'event_action': state
});

Not working

It's not working anymore, there are no console errors.

Error in GTM when importing JSON

I am following the Instructions in the Container Import (recommended) section of the installation guide. When I Import the luna-youtube-tracking.json file into GTM, it fails on Step 7 "Click Continue, then Confirm". It can't proceed as GTM says "the file format is invalid" and JSON parsing error: no viable alternative at input '"en"'. See screenshot. Thanks

2016-01-03_20-35-31

getVideoData is not a function error

When the script binds to an element that already is an YT player, it breaks. We can fix this by checking to see if YT.get(elementId || 'widget' + n), where n is the count of YouTube iframes we're on. If this is the case, we might be able to attach an event listener.

Ajax loaded video, multiple video

does not track ajax loaded video.
So i tried calling trackYouTube(); after ajax call
Now it tracks the ajax loaded video but gives error on video that was already present on page.

event.target.getVideoUrl is not a function.

GTM native integration?

Your README says

As of 9/12/17, Google Tag Manager offers native support for tracking YouTube videos ... we'd recommend using their native integration over our script.

If I search for "YouTube GTM" or similar, all I can find are YouTube videos about GTM instead of GTM docs about YouTube. Could you please add a link to the README about where to find the documentation related to the 9/12/17 announcement?

Caching mechanism isn't working

The caching mechanism, though well intended, isn't working as hoped. This seems to occur whenever we create a new YT.Player, which #36 should address.

Mixed content HTTP/HTTPS

When using the library within a page loaded via HTTPS, Firefox would display the following error message:

Blocked loading mixed active content
This is because line 183 of the lunametrics-youtube-v6.js file hardcodes the http protocol in the URL used for retrieving video data rather than using the protocol used for the current page request. The following stackoverflow.com article pointed to simply removing the protocol from the URL, and this worked in my case:
http://stackoverflow.com/questions/18251128/why-am-i-suddenly-getting-a-blocked-loading-mixed-active-content-issue-in-fire

Please choose a software license (not a Creative Commons license)

My concern is that I'm not clear what the attribution requirement means for software.

I would go with an MIT license for this particular project:
https://opensource.org/licenses/MIT

Note that Creative Commons does not recommend using their licenses for software:
https://wiki.creativecommons.org/index.php/Frequently_Asked_Questions#Can_I_apply_a_Creative_Commons_license_to_software.3F

We recommend against using Creative Commons licenses for software. Instead, we strongly encourage you to use one of the very good software licenses which are already available. We recommend considering licenses made available by the Free Software Foundation or listed as “open source” by the Open Source Initiative.

Unlike software-specific licenses, CC licenses do not contain specific terms about the distribution of source code, which is often important to ensuring the free reuse and modifiability of software. Many software licenses also address patent rights, which are important to software but may not be applicable to other copyrightable works. Additionally, our licenses are currently not compatible with the major software licenses, so it would be difficult to integrate CC-licensed work with other free software. Existing software licenses were designed specifically for use with software and offer a similar set of rights to the Creative Commons licenses.

Add graceful degradation for Classic

As a non-technical marketer, I would like this code to gracefully degrade to Classic Analytics in case I don't have Universal, so that I can use the same code and not make any changes to it (plug and play).

Add percentage completion tracking

As a web analyst, I would like to see the percentage of a video that my user has watched so that I can better understand how they consume my video content.

Percentages are not tracked on "replays" of videos

Currently, if a user replays the video in-place, the percentages will not be tracked. This could by resetting the player and video ID specific cache when the 'Watch to End' event occurs, but simply resetting it in the for loop going through the marks doesn't do the trick.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.