﻿/*************************************************************************
* jquery.TrackIt.js - Version 2.2.8
*************************************************************************
* @author Adam S. Kirschner (me@adamskirschner.com)
* Copyright (C) 2010 
*************************************************************************
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>. 
************************************************************************/
var Void = function () { }; if (!("console" in window)) { window.console = {} } $.each(["groupCollapsed", "groupEnd", "group", "warn", "info", "dir", "warn", "error", "log"], function (a, b) { if (!(b in console)) { window.console[b] = Void } }); var cloneObj = function (b) { var d = {}; for (var a in b) { if (b[a] !== undefined) { if (typeof b[a] === "object") { d[a] = cloneObj(b[a]) } else { d[a] = b[a] } } } return d }; String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, "") }; (function (a) { a.TrackIt = function (d, c) { var b = this; this.settings = a.extend(this.defaults, c.Settings); if (this.settings.ShowDebugInfo) { console.group("$.TrackIt() - Init") } if (this.settings.TestMode && this.settings.ShowDebugInfo) { console.groupCollapsed("$.TrackIt() - Test Mode is Enabled, Tracking Disabled!") } else { if (this.settings.ShowDebugInfo) { console.info("$.TrackIt() - Tracking Enabled. Debug Mode On.") } } this.InitDudLink(); this.loadTrackingModule(d); this.__READY = []; this.__TRACK_QUEUE = []; this.ExcludeAttribute("key"); this.ExcludeAttribute("type"); if (c.Holders) { a.extend(this.Holders, c.Holders) } a(this.settings.TrackKeyCssSelector).live("click", function () { b.HandleGenericClick(this) }); this.__CALLBACK_EVENTS = {}; a.each(this.__GLOBAL_EVENTS, function () { b.__CALLBACK_EVENTS[this + ""] = [] }); if (c.Plugins) { a.each(c.Plugins, function () { if (this["Init"] && a.isFunction(this["Init"])) { this.Init.apply(b) } }) } if (this.settings.ShowDebugInfo) { console.groupEnd() } if (c.XmlUrl) { this.loadXml(c.XmlUrl, c.Data) } else { this.Data = a.extend({}, c.Data); this.ready() } }; a.extend(a.TrackIt.prototype, { __GLOBAL_EVENTS: ["afterProcessHolders", "beforeProcessHolders", "beforeTrack", "afterTrack"], __INDIVIDUAL_EVENTS: ["afterProcessHolders", "beforeProcessHolders", "beforeTrack", "afterTrack"], __EXCLUDE_VARS: [], defaults: { TrackKeyCssSelector: "*[trackKey]", TestMode: false, TrackKeyAttribute: "trackKey", EnableUrlMappingWithDeepLink: false, ShowMissingHolderWarnings: false, ShowDebugInfo: false, SanityCheckEnabled: false, SanityCheckMissingOnly: false, SanityCheckFromFlash: false, ShowOnlyReportedData: false }, HandleGenericClick: function (c) { var b = a(c).attr(this.settings.TrackKeyAttribute); if (b !== undefined && b.length > 0) { this.track(b, { ele: c }) } }, InitDudLink: function () { if (a.TrackIt.DudHtmlLink !== undefined && this.DudHtmlLink === undefined) { this.DudHtmlLink = a.TrackIt.DudHtmlLink } else { if (this.DudHtmlLink === undefined) { a.TrackIt.DudHtmlLink = this.DudHtmlLink = a("<a></a>").css("display", "none").attr("href", "#nojs"); a(document.body).append(this.DudHtmlLink) } } }, loadTrackingModule: function (b) { switch (b.toLowerCase()) { case "googleanalytics": case "google": case "ga": a.extend(this, window.TrackItModules.GoogleAnalytics); break; case "omniture": case "omni": a.extend(this, window.TrackItModules.Omniture); break; default: console.error("WARNING: No valid tracking module was specified!") } }, loadXml: function (c, d) { var b = this; a.ajax({ url: c, complete: function (e) { if (e.responseText.length > 0) { b.Data = a.extend(b.parseXml(e.responseText), d) } b.ready() } }) }, parseXml: function (c) { var d = {}; var b = this; c = this.getXmlObject(c).getElementsByTagName("trackEvent"); a(c).each(function () { if (this.tagName) { var e = a(this); var g = {}; for (var f = 0; f < this.attributes.length; f++) { var h = this.attributes[f].nodeName; if (h.toLowerCase() != "key") { g[h] = e.attr(h); if (a(b.__EXCLUDE_VARS).index(h) < 0) { b.__EXCLUDE_VARS.push(h) } } } a(this.childNodes).each(function () { if (this.tagName) { g[this.tagName] = a(this).text() } }); d[e.attr("key")] = g } }); return d }, getXmlObject: function (f) { var c; try { var b = (a.browser.msie) ? new ActiveXObject("Microsoft.XMLDOM") : new DOMParser(); b.async = false } catch (d) { throw new Error("XML Parser could not be instantiated") } try { if (a.browser.msie) { c = (b.loadXML(f)) ? b : false } else { c = b.parseFromString(f, "text/xml") } } catch (d) { throw new Error("Error parsing XML string") } return c }, isReady: false, ready: function (c) { var b = this; if (this.isReady) { c.apply(b, []) } else { if (a.isFunction(c)) { this.__READY.push(c) } else { if (arguments.length === 0) { this.isReady = true; a.each(this.__READY, function () { this.apply(b, []) }); delete this.__READY; this.RunTrackQueue() } } } }, addCallback: function (b, c) { if (this.settings.ShowDebugInfo) { console.info("$.TrackIt.addCallback() - Adding Callback to '" + b + "'", c) } if (a.inArray(b, this.__GLOBAL_EVENTS > -1)) { this.__CALLBACK_EVENTS[b].push(c) } else { if (this.settings.ShowDebugInfo) { console.warn("$.TrackIt.addCallback() - Failed to add callback to '" + b + "'! ", c) } } }, fireEvent: function (c, e) { var d = true; var b = this; if (typeof c === "string") { if (this.__CALLBACK_EVENTS[c] && this.__CALLBACK_EVENTS[c].length > 0) { if (this.settings.ShowDebugInfo) { console.group("$.TrackIt.fireEvent() - Firing Global Event '" + c + "'") } a.each(this.__CALLBACK_EVENTS[c], function () { if (this.apply(b, [e]) === false) { d = false } }); if (this.settings.ShowDebugInfo) { console.groupEnd() } } if (e && e.key && this.Data[e.key] && this.Data[e.key][c] && a.isFunction(this.Data[e.key][c])) { if (this.settings.ShowDebugInfo) { console.info("$.TrackIt.fireEvent() - Firing Local Event '" + c + "'") } if (this.Data[e.key][c].apply(b, [e]) === false) { d = false } } } return d }, track: function (c, b) { if (!this.isReady) { this.QueueTrackEvent(c, b); return } if (typeof b === "string") { b = window["eval"]("(" + b + ")") } else { if (b == null) { b = {} } } if (this.Data[c] !== undefined) { if (this.settings.ShowDebugInfo) { console.groupCollapsed("$.TrackIt.track() - key='", c, "' options=", b) } var d = this.GetParsedData(c, b); if (this.fireEvent("beforeTrack", { key: c, options: b, parsedData: d })) { if (d.type && d.type.toLowerCase() == "pageview") { if (this.settings.ShowDebugInfo) { console.info('$.TrackIt.track()-->DoTrackPageView("' + c + '")') } this.DoTrackPageView(d, b) } else { if (this.settings.ShowDebugInfo) { console.info('$.TrackIt.track()-->DoTrackEvent("' + c + '")') } this.DoTrackEvent(d, b) } this.fireEvent("afterTrack", { key: c, options: b, parsedData: d }) } else { if (this.settings.ShowDebugInfo) { console.info("$.TrackIt.track() - beforeTrack returned false. Skipping track.") } } if (this.settings.ShowDebugInfo) { console.groupEnd() } } else { if (this.settings.ShowDebugInfo) { console.error("$.TrackIt.track() - Key Not Found! - key='", c, "' options=", b) } } }, QueueTrackEvent: function (c, b) { this.__TRACK_QUEUE.push({ key: c, options: b }) }, RunTrackQueue: function () { var b = null; while (this.__TRACK_QUEUE.length > 0) { b = this.__TRACK_QUEUE.pop(); this.track(b.key, b.options) } }, ExcludeAttribute: function (b) { this.__EXCLUDE_VARS.push(b) }, GetParsedData: function (c, b) { var d = null; if (this.Data[c]) { d = cloneObj(this.Data[c]); for (var e in d) { if (!a.isFunction(d[e])) { d[e] = unescape(this.ReplaceHolders(d[e], c, b)) } } } return d }, GetPlaceHolderArray: function (b) { return b.match(/\[[^\]]+\]/g) }, Holders: { TEXT: function () { return a(this).text().trim() }, TITLE: function () { return document.title.trim() }, H1: function () { return a("H1").text().trim() }, ALT: function () { return a(this).attr("alt") }, HREF: function () { var b = a(this).attr("href"); if (b.indexOf(location.host) > -1) { b = b.substr(b.indexOf(location.host) + location.host.length) } return b }, ATTR: function (b) { return a(this).attr(b.value) }, "ATTR+": function (c) { var b = a(this).parents("*[" + c.value + "]"); if (b.length > 0) { return a(b[0]).attr(c.value) } }, PAGENAME: function () { var b = window.location.pathname.split("/"); return b[b.length - 1] }, URL: function () { return document.location.pathname } }, ReplaceHolders: function (h, k, l) { var b = true; if (this.Data[k]["beforeReplaceHolders"] && a.isFunction(this.Data[k]["beforeReplaceHolders"])) { b = this.Data[k]["beforeReplaceHolders"].apply(this, [{ key: k, str: h, options: l}]) } var c = this.GetPlaceHolderArray(h); if (c && b !== false) { for (var g = 0; g < c.length; g++) { var i = c[g]; var d = ""; var f = i.toString().substring(1, (i.length - 1)).toString().split(":"); var e = f[0]; var j = f[1]; if (a.isFunction(this.Data[k][e])) { d = this.Data[k][e].apply(l.ele || null, [{ instance: this, key: k, value: j}]) } else { if (typeof this.Data[k][e] === "string") { d = this.Data[k][e] } else { if (l && a.isFunction(l[e])) { d = l[e].apply(l.ele || null, [{ instance: this, key: k, value: j}]) } else { if (l && typeof l[e] == "string") { d = l[e] } else { if (this.Holders[e] && a.isFunction(this.Holders[e])) { d = this.Holders[e].apply(l.ele || null, [{ instance: this, key: k, value: j}]) } else { if (this.Holders[e] && typeof this.Holders[e] === "string") { d = this.Holders[e] } else { if (this.settings.ShowMissingHolderWarnings && this.settings.ShowDebugInfo) { console.warn("$.TrackIt.HandleBuiltInHolder() - Missing Holder Detected - '" + e + "' in key '" + k + "'") } } } } } } } if (this.Data[k]["afterReplaceHolders"] && a.isFunction(this.Data[k]["afterReplaceHolders"])) { retVal = this.Data[k]["afterReplaceHolders"].apply(this, [{ key: k, str: h, options: l}]); if (retVal) { h = retVal } } h = h.replace(i, d); h = this.ReplaceHolders(h, k, l) } } return h } }) })(jQuery); (function (a) { window.TrackItModules = { GoogleAnalytics: { Type: "Google Analytics", DoTrackEvent: function (c, b) { if (this.settings.TestMode && (this.settings.ShowOnlyReportedData || this.settings.ShowDebugInfo)) { console.groupCollapsed("TrackItModules.GoogleAnalytics.DoTrackEvent() - Track Event Skipped:"); console.dir({ data: c }); console.groupEnd() } else { pageTracker._trackEvent(c.category, c.action, c.opt_label, c.opt_value); if (this.settings.ShowDebugInfo || this.settings.ShowOnlyReportedData) { console.groupCollapsed("TrackItModules.GoogleAnalytics.DoTrackEvent() - Event tracked successfully."); console.dir({ data: c }); console.groupEnd() } } }, DoTrackPageView: function (b) { if (this.settings.TestMode && (this.settings.ShowOnlyReportedData || this.settings.ShowDebugInfo)) { console.groupCollapsed("TrackItModules.GoogleAnalytics.DoTrackPageView() - Track Event Skipped:"); console.dir({ data: b }); console.groupEnd() } else { pageTracker._trackPageview(b.pageName); if (this.settings.ShowDebugInfo || this.settings.ShowOnlyReportedData) { console.groupCollapsed("TrackItModules.GoogleAnalytics.DoTrackPageView() - Event tracked successfully."); console.dir({ data: b }); console.groupEnd() } } } }, Omniture: { Type: "Omniture", DoTrackEvent: function (e, c) { var s = s_gi(s_account); a.extend(s, e); a.each(this.__EXCLUDE_VARS, function () { delete s[this] }); var b = []; for (var f in e) { if (a(this.__EXCLUDE_VARS).index(f) == -1) { b.push(f) } } s.linkTrackVars = b.join(","); if (s.events && s.events.length > 0) { s.linkTrackEvents = s.events } if (this.settings.TestMode && (this.settings.ShowOnlyReportedData || this.settings.ShowDebugInfo)) { console.groupCollapsed("TrackItModules.Omniture.DoTrackEvent() - Track Event Skipped:"); console.dir({ s: s, data: e }); console.groupEnd() } else { if (e.dudLinkUrl && e.dudLinkText) { this.DudHtmlLink.attr("href", e.customLinkUrl).text(e.dudLinkText) } s.tl(c.ele || this.DudHtmlLink.get(0), e.customLinkType || "o", e.customLinkName || null); if (this.settings.ShowDebugInfo || this.settings.ShowOnlyReportedData) { console.groupCollapsed("TrackItModules.Omniture.DoTrackEvent() - Event tracked successfully."); console.dir({ s: s, data: e }); console.groupEnd() } this.DudHtmlLink.attr("href", "#nojs").text(""); for (var d in e) { delete s[d] } } }, DoTrackPageView: function (c) { a.extend(s, c); a.each(this.__EXCLUDE_VARS, function () { delete s[this] }); if (this.settings.TestMode && (this.settings.ShowOnlyReportedData || this.settings.ShowDebugInfo)) { console.groupCollapsed("TrackItModules.Omniture.DoTrackPageView() - Page View tracking is being skipped."); console.dir({ s: s, data: c }); console.groupEnd() } if (!this.settings.TestMode) { s.t(); if (this.settings.ShowDebugInfo || this.settings.ShowOnlyReportedData) { console.groupCollapsed("TrackItModules.Omniture.DoTrackPageView() - Page View tracked successfully."); console.dir({ s: s, data: c }); console.groupEnd() } } /*for (var b in c) { delete s[b] }*/ } }} })(jQuery); (function (a) { a.TrackItPlugins = { DataSanityCheck: { Init: function () { this.ready(a.TrackItPlugins.DataSanityCheck.Go) }, Go: function (l, d) { holderStatus = {}; if (!l) { l = {} } if (!d) { d = {} } for (var m in this.Data) { if (!this.settings.SanityCheckMissingOnly) { holderStatus[m] = {} } keyData = cloneObj(this.Data[m]); for (var e in keyData) { var h = keyData[e]; if (typeof h == "string") { var b = this.GetPlaceHolderArray(h); if (b) { for (var f = 0; f < b.length; f++) { var j = b[f]; var g = j.toString().substring(1, (j.length - 1)).toString().split(":"); var c = g[0]; var k = g[1]; if (!(this.Holders[c]) && !(keyData[c]) && !(l[c])) { if (!holderStatus[m]) { holderStatus[m] = {} } holderStatus[m][c] = false } else { if (!this.settings.SanityCheckMissingOnly) { holderStatus[m][c] = true } else { if (holderStatus[m] && holderStatus[m][c]) { delete holderStatus[m][c] } } } } } } } } if (this.settings.ShowDebugInfo) { console.groupCollapsed("$.TrackItPlugins.DataSanityCheck() - Results"); console.dir(holderStatus); console.groupEnd() } } }, CopyPropToEVar: { Init: function () { this.ready(a.TrackItPlugins.CopyPropToEVar.Go) }, Go: function () { if (this.settings.ShowDebugInfo) { console.groupCollapsed("TrackItPlugins.CopyPropToEVar.Go() - Results") } var d = new RegExp("(\\d+)", "g"); var e = {}; for (var c in this.Data) { keyData = this.Data[c]; for (var f in keyData) { if (f.indexOf("prop") > -1) { var b = f.match(d)[0]; keyData["eVar" + b] = keyData["prop" + b]; if (!e[c]) { e[c] = {} } e[c]["eVar" + b] = keyData[f] } } } if (this.settings.ShowDebugInfo) { console.dir(e); console.groupEnd() } } }, CheckUrlMapping: { Init: function () { this.ExcludeAttribute("urlMap"); this.ready(a.TrackItPlugins.CheckUrlMapping.Go) }, Go: function () { var d = this; if (document.location.hash.length > 0 && !this.settings.EnableUrlMappingWithDeepLink) { if (this.settings.ShowDebugInfo) { console.info("$.TrackItPlugins.CheckUrlMapping.Go() - Deep Link Detected, Disabling Url Mapping") } } else { if (this.settings.ShowDebugInfo) { console.group("$.TrackItPlugins.CheckUrlMapping.Go() - Enabled") } if (this.settings.ShowDebugInfo) { console.info("$.TrackItPlugins.CheckUrlMapping.Go() - Check against URL: ", document.location.pathname) } var e = false; for (var c in this.Data) { var f = this.Data[c]; if (f.urlMap) { var b = f.urlMap.split("|"); a.each(b, function () { var g = this.replace("[", "\\["); g = g.replace("]", "\\]"); g = g.replace("*", ".*"); if (!e && (new RegExp("^" + g + "$", "i")).test(unescape(document.location.pathname))) { if (d.settings.ShowDebugInfo) { console.info("TrackItPlugins.CheckUrlMapping.Go() - Found Key: '" + c + "'") } d.track(c); e = true } }) } } if (this.settings.ShowDebugInfo && !e) { console.info("TrackItPlugins.CheckUrlMapping.Go() - Key Not Found!") } } if (this.settings.ShowDebugInfo) { console.groupEnd() } } }, RecordLastTrack: { Init: function () { this.__LAST_REPORT = {}; this.addCallback("afterTrack", function (b) { a.TrackItPlugins.RecordLastTrack.__LAST_REPORT = a.extend(a.TrackItPlugins.RecordLastTrack.__LAST_REPORT, b.parsedData); if (this.settings.ShowDebugInfo) { console.info("TrackItPlugins.RecordLastTrack() - Last data set saved!") } }); this.Holders.LAST = a.TrackItPlugins.RecordLastTrack.LastHolder }, LastHolder: function (b) { if (a.TrackItPlugins.RecordLastTrack.__LAST_REPORT && a.TrackItPlugins.RecordLastTrack.__LAST_REPORT[b.value]) { return a.TrackItPlugins.RecordLastTrack.__LAST_REPORT[b.value] } else { if (b.instance.settings.ShowDebugInfo) { console.warn("TrackItPlugins.RecordLastTrack() - LAST value request not found '" + b.value + "'") } } } }, CssSelector: { Init: function () { this.ExcludeAttribute("cssSelector"); this.ready(a.TrackItPlugins.CssSelector.Go) }, Go: function () { var c = this; if (c.settings.ShowDebugInfo) { console.groupCollapsed("$.TrackItPlugins.CssSelector() - Enabled'") } for (var d in c.Data) { var b = this.Data[d].cssSelector; if (b && b.length > 0) { (function (e, f) { a(e).live("click", function () { c.track(f, { ele: this }) }) } (b, d)); if (c.settings.ShowDebugInfo) { console.info('"' + b + '" --> "' + d + '"') } } } if (c.settings.ShowDebugInfo) { console.groupEnd() } } }, ToLowerCase: { Init: function () { this.addCallback("beforeTrack", a.TrackItPlugins.ToLowerCase.Go); if (this.settings.ShowDebugInfo) { console.info("$.TrackItPlugins.ToLowerCase() - Enabled'") } }, Go: function (c) { var b = this; if (b.settings.ShowDebugInfo) { console.group("$.TrackItPlugins.ToLowerCase() - Executing'") } var e = c.parsedData; for (var d in e) { if (a.isFunction(e[d].toLowerCase)) { e[d] = e[d].toLowerCase() } } if (b.settings.ShowDebugInfo) { console.groupEnd() } } }} })(jQuery);

