// This javascript automatically makes page view calls to the GA server. // As well, it tags file downloads and external links in Google Analytics. // You need to be using the Google Analytics New Tracking Code (ga.js) // for this script to work. // To use this file, place the script reference to this file on all pages just below the // Google Analytics code that includes GA.js. See the accompanying example file prweb_basic_tracking.html // // For automatic file download and external link tracking, a call to gaTagConfig must be made in the on-page code // The code is executed by a call to startListening as in the following example code: // startListening(window, ‘load’, function () {gaTagConfig(‘pdf’, false, false, false);}); // This will attach event listeners to the correct links AFTER the page has loaded, thus ensuring all // links are tagged // All outbound links and links to non-html files should now be automatically tracked. // Please see the accompanying file prweb_pdf_tracking.html for an example. // try { var cookieDomain = ""; var strHost = document.location.host; var strPhpIp = document.strIP; cookieDomain = getMainDomain(); var mainTracker; if (document.WebPropertyId) var mainTracker = _gat._getTracker(document.WebPropertyId); else var mainTracker = _gat._getTracker("UA-11373184-1"); mainTracker._setDomainName(cookieDomain); var intGoogDomainHash = getDomainHash(cookieDomain); mainTracker._setAllowLinker(true); mainTracker._setAllowHash(true); if (document.strUDV) setVar(mainTracker, document.strUDV); strPhpIp = strPhpIp ? '/' + strPhpIp.substring(0, 3) + '/' : ''; if (document.strTrackPageView) { document.strTrackPageView = document.strTrackPageView; } else { document.strTrackPageView = document.location.toString(); //.pathname; } document.strTrackPageView = document.strTrackPageView.replace(/\/\//g, '/'); mainTracker._trackPageview(document.strTrackPageView); document.tagConfigFunc = function (){gaTagConfig(false, true, true, false)}; if (!document.tagConfigFunc) gaTagConfig(); else document.tagConfigFunc(); //} catch (e) {} /* Configuration options required: 1. Select which external links to listen for 2. If document downloads, specify which ones or accept the default list. */ var isDocs = true; var isMailto = true; var isExternal = true; var isVirtual = true; var patternDocslist = /\.(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|js|css|rar|exe|wma|mov|avi|wmv|mp3)($|\&|\?)/; // Syntax: gaTagConfig([true|false|string of bar-delimited extensions [, true|false [, true|false [, true|false]]]]) ; If all false, don't bother loading script function gaTagConfig(docslist, mailto, external, virtual) { isDocs = (typeof docslist == 'boolean') ? docslist : docslist > ''; // Determine isDocs if (typeof docslist == 'string' && docslist > '') patternDocslist = new RegExp('\\.(?:' + docslist + ')($|\\&|\\?)'); // updated by erikvold added \? in second group: isMailto = (mailto !== undefined) ? mailto : true; isExternal = (external !== undefined) ? external : true; isVirtual = (virtual !== undefined) ? virtual : true; gaAutoTag(); } function gaAutoTag() { if ((isDocs || isMailto || isExternal || isVirtual) && document.getElementsByTagName) { // Initialize external link handlers var hrefs = document.getElementsByTagName("a"); for (var h = 0; h < hrefs.length; h++) { // try {} catch{} block added by erikvold try{ //protocol, host, hostname, port, pathname, search, hash if (isMailto && hrefs[h].protocol == "mailto:") { startListening(hrefs[h],"click",trackMailto); } else if (isDocs && hrefs[h].hostname == location.host) { //BK 080820 var path = hrefs[h].pathname + hrefs[h].search; var isDoc = path.match(patternDocslist); if (isDoc) { //startListening(hrefs[h],"click",trackExternalLinks); startListening(hrefs[h],"mousedown",trackExternalLinks); } } else if (isExternal && hrefs[h].hostname && hrefs[h].hostname !== location.host) { startListening(hrefs[h],"mousedown",trackExternalLinks); } } catch(e){ continue; } } } } function startListening (obj,evnt,func) { if (obj.addEventListener) { obj.addEventListener(evnt,func,false); } else if (obj.attachEvent) { obj.attachEvent("on" + evnt,func); } if(document.cookie.search(/debug(ging)?=(?!no)[^;]*/i) !== -1) obj.innerHTML += '.'; } function trackMailto (evnt) { var href = evnt.srcElement ? evnt.srcElement.href : this.href; var mailto = "/mailto/" + href.substring(7); if (typeof(mainTracker) == "object") mainTracker._trackPageview(mailto); } function trackExternalLinks (evnt) { var e = (evnt.srcElement) ? evnt.srcElement : this; while (e.tagName !== "A") { e = e.parentNode; } var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname; if (e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search; if (e.hostname !== location.host) lnk = "/external/" + e.hostname + lnk; mainTracker._trackPageview(lnk); } function getMainDomain() { var strHost = document.location.host; mainDomain = strHost.match(/([^.]*\.)*([^.]+\.[^.]+)/); return '.' + mainDomain[mainDomain.length-1]; } function accumTrans(orderID, affiliate, total, tax, shipping, city, state, country, SKU, productName, category, price, qty) { addTrans(orderID, affiliate, total, tax, shipping, city, state, country); addItem(orderID, SKU, productName, category, price, qty); trackTrans(); } function addTrans(orderID, affiliate, total, tax, shipping, city, state, country) { mainTracker._addTrans( orderID, affiliate, total, tax, shipping, city, state, country); } function addItem(orderID, SKU, productName, category, price, qty) { mainTracker._addItem( orderID, SKU, productName, category, price, qty); } function trackTrans() { mainTracker._trackTrans(); } function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; domain=" + cookieDomain + "; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } function appendOrigin(str, orig) { // append the originating site to the string return '[-' + orig + '-] ' + str; } function setVar(t, strUDV) { var d = new Date(); if (strUDV && !readCookie('udvset')) { strUDV = d.getTime() + '.' + strUDV; t._setVar(strUDV); createCookie('udvset', strUDV, 60); } } function getDomainHash(strDomainName) { fromGaJs_h = function (e) { return undefined == e || "-" == e || "" == e }; fromGaJs_s = function (e) { var k = 1, a = 0, j, i; if (!fromGaJs_h(e)) { k = 0; for (j = e.length - 1; j >= 0; j--) { i = e.charCodeAt(j); k = (k << 6 & 268435455) + i + (i << 14); a = k & 266338304; k = a != 0 ? k ^ a >> 21 : k } } return k }; return fromGaJs_s(strDomainName) ; }