/**
* @overview
*
* This is a tool to track as much as possible from a small image fetch.<p />
*
* Though cookie tracking is done, it does not create cookies.<br />
* This is because cookies created by the http request cannot be altered by the javascript.<br />
* Attempts to create identical cookies results in two cookies stored by the browser.<p>
*
* Instead, all parameters except the tracking cookie itself are stored as request arguments.<p />
*
* Because state tracking is no longer needed, this library has been reduced from a class to a single function<br />
* that is called when the page is loaded.<p />
*
* Of note, is the use of the Valve Fingerprint2 library (https://github.com/Valve/fingerprintjs2), which is signifantly larger than this.<br />
* It is the main purpose of having this codebase.<br />
*
* Fingerprints are a way of uniquely identifying a browser if cookies are turned off or unreliable by getting every piece of <br />
* information about a system that is available to the browser and concatenating and MD5summing it in order to generate a unique system key.
*
* @module Pxcel Tracker
* @author Rusty Phillips
* @version 0.1
*/
/**
* Adds an image to the page.
*
* @param {hash} attributes - A tuple containing name value pairs that are added to the source of the image.
*/
function Pxcel(attributes) {
var path = document.location.protocol + '//www.pxcels.com/1x1.gif';
/**
* Returns the cookie with the given name by parsing the cookie file.
* @private
*/
getCookie = function(cname) {
var name = cname + "=";
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);
if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
}
return null;
};
/**
* Returns the fingerprint of the current browser.
* @private
*/
pxcel_ff = function() {
fp_cookie = getCookie('hpy_f');
if (fp_cookie !== null)
return fp_cookie;
if (typeof(self.pxcel_f) == 'undefined')
new Fingerprint2().get(function(md5) {
self.pxcel_f = md5;
});
return self.pxcel_f;
};
/* This approach is probably not going to be used because of the way we need to do https.
if (attributes) {
var node = document.createElement('img');
src = path + "?hpy_f=" + self.pxcel_ff();
for (var key in attributes) {
src += '&' + key + '=' + attributes[key];
}
node.setAttribute("src", src);
document.getelementsbytagname('body')[0].appendchild(node);
}
*/
if (_pxl) {
for (i = 0; i < _pxl.length; i++) {
var node = document.createElement('img');
var src = path + "?hpy_f=" + self.pxcel_ff();
for (var val in _pxl[i])
src += '&' + val + '=' + _pxl[i][val];
node.setAttribute("src", src);
document.getElementsByTagName('body')[0].appendChild(node);
}
}
}
Pxcel();