Created
September 14, 2023 10:04
-
-
Save marten-cz/0ce6dc26e8ee978e74bac9fa1a68af48 to your computer and use it in GitHub Desktop.
Tracking code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SporeTracking(clientID) | |
{ | |
this._address = "http://trackingpic.marten-online.com/trac/tracking.gif?"; | |
this._clientID = clientID; | |
this.DebugElement = null; | |
this._prefixTime = "smdt"; | |
if (!this._defined) | |
{ | |
SporeTracking.prototype._defined = true; | |
//////////////////////////////////////////////// | |
//PageInfo:Object | |
function PageInfo() | |
{ | |
this._customParams = new Array(); | |
} | |
PageInfo.prototype._actualPageHash = "assalt"; | |
PageInfo.prototype._clientIDName = "TracDevClientID"; | |
PageInfo.prototype._sessionIDName = "TracDevSessionID"; | |
PageInfo.prototype._reffererMarkerName = "TracDevRefferer"; | |
PageInfo.prototype._classCode = "pi"; // Page info | |
PageInfo.prototype._prefixReferrer = "pirf"; | |
PageInfo.prototype._prefixActualPage = "pavref"; | |
PageInfo.prototype._prefixClassCode = "picc" | |
PageInfo.prototype._prefixIsOriginal = "piio"; // If is site from external referrer or not | |
PageInfo.prototype._prefixSessionID = "pisid"; // Seesion - will expire with browser window | |
PageInfo.prototype._prefixClientID = "picid"; // Long time session | |
PageInfo.prototype._prefixPageTitle = "pitit"; // Page title | |
//PageInfo.prototype._prefixTime = "smdt"; // Page title | |
PageInfo.prototype._prefixPageID = "pavpid"; | |
PageInfo.prototype._prefixCategoryID = "pavcid"; | |
PageInfo.prototype._prefixElementName = "elnm"; | |
PageInfo.prototype._prefixElementID = "elid"; | |
PageInfo.prototype._getRandomChars = function(fromStr, length) | |
{ | |
fromStr += (new Date()).getMilliseconds().toString(); | |
var retVal = "", counter = 0, curChar; | |
while(counter < length) | |
{ | |
curChar = fromStr.charAt(Math.round(Math.random() * (fromStr.length - 1))); | |
if (curChar == " ") continue; | |
retVal += curChar; | |
fromStr += (new Date()).getMilliseconds().toString(); | |
counter++; | |
} | |
return retVal; | |
} | |
PageInfo.prototype._generateID = function() | |
{ | |
return this._getRandomChars(navigator.userAgent, 15) + this._getRandomChars(location, 15); | |
} | |
PageInfo.prototype._actualPageHashValue = PageInfo.prototype._generateID(); | |
PageInfo.prototype._getCookie = function(cookieName) | |
{ | |
cookieName += "="; | |
var retVal = ""; | |
if (document.cookie.length > 0) | |
{ | |
var cookieArray = document.cookie.split(";") | |
for (var counter = 0;counter < cookieArray.length; counter++) | |
{ | |
if (cookieArray[counter].indexOf(cookieName) > -1) | |
{ | |
retVal = unescape(cookieArray[counter].split("=")[1]); | |
break; | |
} | |
} | |
} | |
return retVal; | |
} | |
PageInfo.prototype._setCookie = function(cookieName,uniqueID,expDays) | |
{ | |
var expDate = expDays?(";expires=" + (new Date((new Date).getTime() + expDays * 1000 * 60 * 60 * 24 )).toGMTString()):""; | |
var cookieVal = cookieName + "=" + escape(uniqueID) + expDate + ";path=/"; | |
document.cookie = cookieVal; | |
} | |
PageInfo.prototype._isOriginal = function() | |
{ | |
if (!document.referrer || document.referrer.split("?")[0].indexOf(document.location.hostname,0) > -1 || document.location == this._getReferrerMarker()) | |
return 0; | |
this._setReferrerMarker(document.location); | |
return 1; | |
} | |
PageInfo.prototype._getClientID = function() | |
{ | |
var id = this._getCookie(this._clientIDName); | |
if (!id) | |
{ | |
id = this._generateID(); | |
this._setCookie(this._clientIDName,id,360); | |
} | |
return id; | |
} | |
PageInfo.prototype._getSessionID = function() | |
{ | |
var id = this._getCookie(this._sessionIDName); | |
if (!id) | |
{ | |
id = this._generateID(); | |
this._setCookie(this._sessionIDName, id); | |
} | |
return id; | |
} | |
PageInfo.prototype._getReferrerMarker = function() | |
{ | |
return this._getCookie(this._reffererMarkerName); | |
} | |
PageInfo.prototype._setReferrerMarker = function(refferer) | |
{ | |
this._setCookie(this._reffererMarkerName,refferer); | |
} | |
/* | |
PageInfo.prototype.addCustomParam = function(propCode,propValue) | |
{ | |
this._customParams.push({"propCode":propCode,"propValue":propValue}); | |
return this; | |
} | |
*/ | |
PageInfo.prototype.serializeProp = function(propCode,propValue) | |
{ | |
return propValue?(propCode + "=" + escape(propValue) + "&"):""; | |
} | |
PageInfo.prototype.serializeToURL = function() | |
{ | |
var serVals =""; | |
/* | |
for (var counter = 0; counter < this._customParams.length; counter++) | |
{ | |
serVals += this.serializeProp("picp" + this._customParams[counter].propCode, this._customParams[counter].propValue); | |
} | |
*/ | |
return serVals | |
+ this.serializeProp(this._prefixClassCode, this._classCode) | |
+ this.serializeProp(this._prefixActualPage, location) | |
+ this.serializeProp(this._prefixIsOriginal, this._isOriginal()) | |
+ this.serializeProp(this._prefixReferrer, document.referrer) | |
+ this.serializeProp(this._prefixSessionID, this._getSessionID()) | |
+ this.serializeProp(this._prefixClientID, this._getClientID()) | |
+ this.serializeProp(this._prefixPageTitle, document.title) | |
; | |
} | |
//END PageInfo:Object | |
//////////////////////////////////////////////// | |
//////////////////////////////////////////////// | |
//PageView:PageInfo | |
function PageView(pageID, recordID) | |
{ | |
this._pageID = pageID; | |
this._recordID = recordID; | |
} | |
PageView.prototype = new PageInfo; | |
PageView.prototype._classCode = "clsPageView"; // piv | |
PageView.prototype.serializeToURL = function() | |
{ | |
return PageInfo.prototype.serializeToURL.call(this) | |
+ this.serializeProp(this._prefixPageID, this._pageID) | |
+ this.serializeProp(this._prefixCategoryID, this._recordID); | |
} | |
//END PageView:PageInfo | |
//////////////////////////////////////////////// | |
//////////////////////////////////////////////// | |
//ElementClick:PageInfo | |
function ElementClick(elementName, elementID, e) | |
{ | |
this._elementName = elementName; | |
this._elementID = elementID; | |
this._element = e; | |
} | |
ElementClick.prototype = new PageInfo; | |
ElementClick.prototype._classCode = "elemClick"; | |
ElementClick.prototype.serializeToURL = function() | |
{ | |
return PageInfo.prototype.serializeToURL.call(this) | |
+ this.serializeProp(this._prefixElementName, this._elementName) | |
+ this.serializeProp(this._prefixElementID, this._elementID); | |
} | |
//END ElementClick:PageInfo | |
//////////////////////////////////////////////// | |
SporeTracking.prototype.getPageView = function(pageID, categoryID) | |
{ | |
return new PageView(pageID, categoryID); | |
} | |
SporeTracking.prototype.getElementClick = function(elementName, elementID) | |
{ | |
var el = new ElementClick(elementName, elementID); | |
SporeTracking.sendInfo(el); | |
} | |
SporeTracking.prototype.sendInfo = function(pageInfo) | |
{ | |
var src = this._address | |
+ this._serializeProp("ver",this._version) | |
+ this._serializeProp("clid",this._clientID) | |
+ pageInfo.serializeToURL() | |
+ this._serializeProp(PageInfo.prototype._actualPageHash, PageInfo.prototype._actualPageHashValue) | |
+ this._prefixTime + "=" + (new Date()).getTime() | |
; | |
if(this.DebugElement == null) | |
{ | |
document.write("<img src='" + src + "' style='display: none' />"); | |
} | |
else | |
{ | |
//document.write("<img src='" + src + "' style='display: none' />"); | |
document.getElementById(this.DebugElement).innerHTML = src; | |
} | |
this.registerUnload(); | |
return src; | |
} | |
SporeTracking.prototype.registerUnload = function() | |
{ | |
var tmp = window.onunload; | |
//if(window == null) | |
window.onunload = function () { SporeTracking.sendPing(); }; | |
//else | |
//window.onunload = function () { SporeTracking.sendPing(); tmp(); }; | |
} | |
SporeTracking.prototype.sendPing = function() | |
{ | |
try | |
{ | |
var src = this._address | |
+ this._serializeProp("ver",this._version) | |
+ this._serializeProp("clid",this._clientID) | |
+ this._serializeProp(PageInfo.prototype._prefixClassCode, "_ping_") | |
+ this._serializeProp(PageInfo.prototype._prefixSessionID, PageInfo.prototype._getSessionID()) | |
+ this._serializeProp(PageInfo.prototype._prefixClientID, PageInfo.prototype._getClientID()) | |
+ this._serializeProp(PageInfo.prototype._actualPageHash, PageInfo.prototype._actualPageHashValue) | |
+ this._prefixTime + "=" + (new Date()).getTime() | |
; | |
if(this.DebugElement == null) | |
{ | |
// Call image. It needs to be done this way | |
var img = new Image(1,1); | |
img.src = src; | |
} | |
else | |
{ | |
document.getElementById(this.DebugElement).innerHTML = src; | |
alert("unload"); | |
} | |
return src; | |
} | |
catch(err) {} | |
} | |
SporeTracking.prototype._serializeProp = function(propCode,propValue) | |
{ | |
//return propValue?(this._classCode + propCode + "=" + escape(propValue) + "&"):""; | |
return propValue?(propCode + "=" + escape(propValue) + "&"):""; | |
} | |
SporeTracking.prototype._version = "0.1"; | |
//SporeTracking.prototype._classCode = "spore"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment