Skip to content

Commit

Permalink
Cherry picked changes from videojs#568 to add analytics to CDN as hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
heff committed Jun 11, 2013
1 parent d6c1e66 commit 1fecec1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module.exports = function(grunt) {
var pkg, s3, semver, version, verParts;
var pkg, s3, semver, version, verParts, uglify;

semver = require('semver');
pkg = grunt.file.readJSON('package.json');
uglify = require('uglify-js');

try {
s3 = grunt.file.readJSON('.s3config.json');
Expand Down Expand Up @@ -233,7 +234,7 @@ module.exports = function(grunt) {
grunt.registerTask('dist', 'Creating distribution', function(){
var exec = require('child_process').exec;
var done = this.async();
var css, jsmin, jsdev;
var css, jsmin, jsdev, cdnjs;

// Manually copy each source file
grunt.file.copy('build/files/minified.video.js', 'dist/video-js/video.js');
Expand Down Expand Up @@ -263,6 +264,12 @@ module.exports = function(grunt) {
css = css.replace(/font\//g, '../f/1/');
grunt.file.write('dist/cdn/video-js.css', css);

// Add CDN-specfic JS
jsmin = grunt.file.read('dist/cdn/video.js');
// GA Tracking Pixel (manually building the pixel URL)
cdnjs = uglify.minify('src/js/cdn.js').code.replace('v0.0.0', 'v'+version.full);
grunt.file.write('dist/cdn/video.js', jsmin + cdnjs);

// Zip up into video-js-VERSION.zip
exec('cd dist && zip -r video-js-'+version.full+'.zip video-js && cd ..', { maxBuffer: 500*1024 }, function(err, stdout, stderr){

Expand Down
56 changes: 56 additions & 0 deletions src/js/cdn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Google Analytics tracking pixel for the freely hosted version of Video.js
* at vjs.zencdn.net. We'll use this data to develop a support matrix of
* browsers and devices, and possibly track errors.
*
* This code generates the GA tracking URL without requiring the GA javascript
* library.
*
* @type {Image}
*/
;(function(i,w,n,e,l){
l=w.location;

// Setting the source of an image will load the URL even without adding to dom
// Using //www, still seems to work for https even though ssl.google is used by google
i.src='//www.google-analytics.com/__utm.gif'
// Version
+'?utmwv=5.4.2'
// ID
+'&utmac=UA-16505296-2'
// Sessions
// &utms=2
// Cache breaker (using utmcc to do this)
+'&utmn='+1
+'&utmhn='+e(l.hostname)
// Encoding
// &utmcs=UTF-8
+'&utmsr='+w.screen.availWidth+'x'+w.screen.availHeight
// Browser window
// &utmvp=1057x1105
// Color depth
// &utmsc=24-bit
+'&utmul='+(n.language||n.userLanguage)
// Java
// &utmje=1
// Flash version
// &utmfl=11.7%20r700
// Page title
// &utmdt=HTML5%20Video%20Player%20%7C%20Video.js
// Adsense
// &utmhid=1112291628
// Referrer, '-' is none
// Using current page as referrer so stats show up cleaner than "Direct"
+'&utmr='+e(l.href)
+'&utmp='+e(l.hostname+l.pathname)
// Current time stamp
// &utmht=1370890439353
// ?
// &utmu=q
// Cookies! Manually setting visitor ID and setting everything else to 1
// Random number used as cache buster instead of utmn
+'&utmcc=__utma%3D1.'+Math.floor(Math.random()*1e10)+'.1.1.1.1%3B'
// Custom Var: vjsv is the variable name and 1.0.0 is the VJS version
+'&utme=8(vjsv)9(v0.0.0)'
;
})(new Image(),window,navigator,encodeURIComponent);

0 comments on commit 1fecec1

Please sign in to comment.