Skip to content

Instantly share code, notes, and snippets.

@Haraldson
Created November 15, 2012 16:30
Show Gist options
  • Save Haraldson/4079552 to your computer and use it in GitHub Desktop.
Save Haraldson/4079552 to your computer and use it in GitHub Desktop.
Fjord Tours tracking alpha
if(!Array.prototype.indexOf)
{
Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
"use strict";
if (this == null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (len === 0) {
return -1;
}
var n = 0;
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n != n) { // shortcut for verifying if it's NaN
n = 0;
} else if (n != 0 && n != Infinity && n != -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1;
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
}
}
$(function()
{
var currentDomain = window.location.host,
currentDomainParts = currentDomain.split('.'),
siteDomains = [
'fjordtours.no',
'fjordtours.com',
'norgeietnotteskall.no',
'norwaynutshell.com',
'rallarvegen.no',
'fjordpass.no',
'fjord-pass.com',
'skibillett.no',
'skibillett-voss.no'
];
if(currentDomainParts.length > 2)
{
var sliceFrom = currentDomainParts.length - 2;
currentDomain = currentDomainParts.slice(sliceFrom).join('.');
}
$('a').on('click', 'body', function()
{
// target domain is different from current AND target domain is within the site
if(
$(this).attr('href').indexOf(currentDomain) === -1
&& siteDomains.indexOf(currentDomain) > -1
){
if(!$(this).closest('li').hasClass('notrack'))
{
_gaq.push(['_link', $(this).attr('href')]);
(e.preventDefault) ? e.preventDefault() : e.returnValue = false;
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment