//******************************************************************** // // Copyright (c) 2002-2008 MindLab GmbH // All rights reserved. // //==================================================================== // // Project : netmind // Filename : nm_tr_combined.js // //==================================================================== // /** * @file * This script can be used to implement a pixeltracking on your website * * @author $Felix Engemann$ * @version $Name: V2_5_1 $ * @date $Date: 2009-07-01 08:36:31 $ *@listofchanges cha adaption for postbank help-div 2007/09/07 *@listofchanges cha adaption for postbank clientStat tracking Pixelhelp-div 2007/11/13 *@listofchanges cha adaption for postbank clientStat tracking Pixelhelp-div 2007/11/16 *@listofchanges asc generalisation for netmind 4.0 release 2007/12/10 $Log: nm_tr_combined.js,v $ Revision 1.7 2009-07-01 08:36:31 pohl Updated documentation, combined and minimized versions of the scripts Revision 1.6 2009-04-28 09:04:23 pohl Added HTTP POST functionallity Added JSON encoding Revision 1.10 2009-04-27 13:53:01 pohl Added HTTP POST functionallity Added JSON encoding Revision 1.9 2009-01-21 12:33:18 pohl Added techinfo parameters nm_javascript and changed parameter nm_cookies to nm_cookie. Added functionallity to test/debug pixel tracking by logging configuration and request values to separate window. Revision 1.8 2008-12-02 14:18:41 pohl Added configuration options to enable/disable individual tech plugin detection Revision 1.7 2008/09/09 12:03:48 pohl Fixes/improvements for SID timestamp handling Revision 1.6 2008/09/08 14:31:01 pohl Added method setParameter Revision 1.5 2008/09/03 13:33:57 pohl Added new logic to inject a netmind SID via URL parameter. */ //******************************************************************** //config Object //******************************************************************** function cConfigPixel() { //----------------------------------------------------- // members //----------------------------------------------------- //true = Tracker uses Cookies //false= tracker uses Session IDs in Urls this.m_bCookieTracking = true; // true = Use content side tracking. // The nm_track.js script needs to be available on the // tracked web server and the m_strPixelJSPath value needs // to be set accordingly. // false = Use tracker side tracking. // The scripts nm_tr_config, nm_tr_remote.js and the image // nm_track.gif need to be available on the tracked web server // and the m_strPixelPath value needs to be set accordingly. this.m_bContentSideTracking = false; // Session timeout for tracker side tracking without tracker cookies. // we will treat a session as timed out if more than this amount // of seconds has passed between two clicks this.m_nNetMindSessionTimeout = 1800; //set to true, if you want to get the params automatically this.m_bAutoparams = true; //set to true, if you want to send the pixel automatically this.m_bAutosend = true; //The protocol to use for getting the pixel, could be either http //or https this.m_strPixelProtocol = location.href.substr(0, location.href.indexOf(":")); //the servername to get the pixel from (no protocol here, and //no path here), you can append a port or prepend an authendication //like: user:passwort@myserver.mydomain.com:12345 //where "user:password@" is the authentication // "myserver.mydomain.com" is the fully qualified servername // ":12345" is a port-Number // this.m_strPixelServer = "nmt01.dus.dg-i.net"; this.m_strPixelServer = "pc.peterhahn.de"; //the path to request from the given server, this path could of //course include CGI-Parameters //example: "/mywebbug?thisismyparameter=value" this.m_strPixelJSPath = "/nm_track.js?nm.customer.id=peterhahn"; this.m_strPixelPath = "/nm_track.gif?nm.customer.id=peterhahn"; // this value defines CGI parameter to inject the SID from outside. this.m_strSIDParam = "nmsid"; // this flag allows to explicitly disable SID injection via CGI parameters this.m_bSIDParamDisabled = false; //Send Url by default this.m_bSendUrl = true; //Send Referrer by default this.m_bSendReferrer = true; //Send MetaTags by default this.m_bSendMetaTags = true; //Send Browser Setting, Screen Infos etc. this.m_bSendTech = true; //Send Browser Setting, Screen Infos etc. this.m_bSendUrlHash = false; //Send CGI Params of the current location as Parameters of the Pixel this.m_bSendCGIParams = false; //Indicates whether an HTTP POST request (using the XMLHttpRequest class) //should be used this.m_bUseHttpPost = false; //Indicates whether object parameters should be converted to a //JSON-repesentation before sending it this.m_bConvertToJSON = false; //to workaround problems with IE and unclosed DOM objects (body), //the ID of an existing dummy HTML element to receive the //temporary DOM objects can be specified here. this.m_strPostParentId = false; //-------------------------------------------------------- // metatags to be parsed //-------------------------------------------------------- this.m_aMetatag = new Array( "nm.*" ); //-------------------------------------------------------- // Hashed parameter to be parsed //-------------------------------------------------------- this.m_aHashParameter = new Array( "test", "key" ); this.m_oTechPlugins = new Object(); this.m_oTechPlugins['Director'] = false; this.m_oTechPlugins['MediaPlayer'] = false; this.m_oTechPlugins['Flash'] = false; this.m_oTechPlugins['RealPlayer'] = false; this.m_oTechPlugins['AcroRead'] = false; // flag to enable debugging. // if enabled, a window is opened, displaying the pixel configuration and the // pixel request for each request. this.m_bDebug = false; } // end class cConfigPixel //========================================================== // getAutoParams //========================================================== function config_getSendUrlHash () { return this.m_bSendUrlHash; } //========================================================== // getAutoParams //========================================================== function config_getAutoParams () { return this.m_bAutoparams; } //========================================================== // getAutoSend //========================================================== function config_getAutoSend () { return this.m_bAutosend; } //========================================================== // getSendUrl //========================================================== function config_getSendUrl () { return this.m_bSendUrl; } //========================================================== // getSendReferrer //========================================================== function config_getSendReferrer () { return this.m_bSendReferrer; } //========================================================== // getSendMetatags //========================================================== function config_getSendMetatags () { return this.m_bSendMetaTags; } //========================================================== // getSendTech //========================================================== function config_getSendTech () { return this.m_bSendTech; } //========================================================== // getSendTechPlugin // strPlugin = 'Director', 'MediaPlayer', 'Flash', // 'RealPlayer', 'AcroRead' //========================================================== function config_getSendTechPlugin( strPlugin ) { if ( this.m_oTechPlugins ) { return this.m_oTechPlugins[strPlugin]; } return false; } //========================================================== // getSendCGIParams //========================================================== function config_getSendCGIParams () { return this.m_bSendCGIParams; } //========================================================== // getPixelUrl // // return the URL to the tracking pixel or script. //========================================================== function config_getPixelUrl () { return this.m_strPixelProtocol+"://"+this.m_strPixelServer + this.getPixelPath(); } //========================================================== // getProtocol //========================================================== function config_getProtocol () { return this.m_strPixelProtocol; } //========================================================== // getPixelServer //========================================================== function config_getPixelServer () { return this.m_strPixelServer; } //========================================================== // getPixelPath //========================================================== function config_getPixelPath () { if (this.m_bContentSideTracking) { return this.m_strPixelJSPath; } else { return this.m_strPixelPath; } } //========================================================== // getSIDParam //========================================================== function config_getSIDParam () { return this.m_strSIDParam; } //========================================================== // getSIDParamDisabled //========================================================== function config_getSIDParamDisabled () { return this.m_bSIDParamDisabled; } //========================================================== // isCookieTracking //========================================================== function config_isCookieTracking () { return this.m_bCookieTracking; } //========================================================== // isContentSideTracking //========================================================== function config_isContentSideTracking () { return this.m_bContentSideTracking; } //========================================================== // getSessionTimeout //========================================================== function config_getSessionTimeout () { return this.m_nNetMindSessionTimeout; } //========================================================== // isHttpPostEnabled //========================================================== function config_isHttpPostEnabled() { return this.m_bUseHttpPost; } //========================================================== // isJSONEnabled // returns whether to use JSON encoding for object // values. // Returns only true, if m_bConvertToJSON is set AND // the JSON object is available. //========================================================== function config_isJSONEnabled() { return ( typeof(JSON) == 'object' && this.m_bConvertToJSON ); } //========================================================== //Definition of Prototypes //========================================================== //methoden zur Klasse hinzufuegen cConfigPixel.prototype.isCookieTracking = config_isCookieTracking; cConfigPixel.prototype.isContentSideTracking = config_isContentSideTracking; cConfigPixel.prototype.getPixelUrl = config_getPixelUrl; cConfigPixel.prototype.getProtocol = config_getProtocol; cConfigPixel.prototype.getPixelServer = config_getPixelServer; cConfigPixel.prototype.getPixelPath = config_getPixelPath; cConfigPixel.prototype.getSIDParam = config_getSIDParam; cConfigPixel.prototype.getSIDParamDisabled = config_getSIDParamDisabled; cConfigPixel.prototype.getAutoParams = config_getAutoParams; cConfigPixel.prototype.getAutoSend = config_getAutoSend; cConfigPixel.prototype.getSendUrl = config_getSendUrl; cConfigPixel.prototype.getSendUrlHash = config_getSendUrlHash; cConfigPixel.prototype.getSendReferrer = config_getSendReferrer; cConfigPixel.prototype.getSendMetatags = config_getSendMetatags; cConfigPixel.prototype.getSendTech = config_getSendTech; cConfigPixel.prototype.getSendTechPlugin = config_getSendTechPlugin; cConfigPixel.prototype.getSendCGIParams = config_getSendCGIParams; cConfigPixel.prototype.getSessionTimeout = config_getSessionTimeout; cConfigPixel.prototype.isHttpPostEnabled = config_isHttpPostEnabled; cConfigPixel.prototype.isJSONEnabled = config_isJSONEnabled; //******************************************************************** //Session-Management //******************************************************************** //******************************************************************** //Session-Object //******************************************************************** //========================================================== //Constructor for Session-Object //========================================================== function cRemoteSession( oConfig ) { //----------------------------------------------------- // members //----------------------------------------------------- //this is the SessionID returned at the end this.m_strNetMindSID = ""; this.m_oConfig = oConfig; // flag indicating whether to use the injected SID from the CGI parameter // or whether to use the more recent SID provided by the tracker // via cookie or URI replacement this.m_bCgiSIDHandled = false; // remember pixel time initialization // needed to adjust timestamp for subsequent JS pixel requests // when using injected SID. this.nPixelTime = new Date().getTime() / 1000; }//end function cRemoteSession() //========================================================== //method for object Session: returns the Session ID //========================================================== function remotesession_getSessionID() { var strNetMindSID = ""; // get cookie string var strCookie = document.cookie //split into cookies var arCookies = strCookie.split("; "); //loop through cookies and get NetMind-Cookie var nLoopCount = 0; var strActCookieName = ""; if ( strNetMindSID == "" ) { while (nLoopCount < arCookies.length) { var strActCookie = arCookies[nLoopCount]; var arActCookie = strActCookie.split("="); var strActCookieName = arActCookie[0]; if (strActCookieName == "NETMIND_SID") { strNetMindSID = arActCookie[1]; } nLoopCount++; }//end while ((strActCookieName != "NETMIND_SID") && (nLoopCount < arCookies.length)) if (!oNMConfig.isContentSideTracking() && !oNMConfig.isCookieTracking()) { // // tracker-side tracking with URL rewriting. // SID should be set in the following variable: // var strSID_trackerside="/"; var strNewSID = ""; var nNewTS = 0; if (strSID_trackerside != "/") { strNewSID = strSID_trackerside.substr (6, 54); nNewTS = parseInt( String(parseInt( strNewSID.substring(44) ) + (new Date().getTime() / 1000 - this.nPixelTime))); } // check whether session from cookie is still valid: if (strNetMindSID != "" && strNewSID != "" ) { var nOldTS = parseInt( strNetMindSID.substr(44) ); if ( nOldTS <= nNewTS ) { // cookie session did not exceed timeout, // use cookie and update timestamp of SID if ( this.m_bCgiSIDHandled ) { // use netmind SID from cookie, set via CGI param strNetMindSID = strNetMindSID.substr(0,43) + "-" + nNewTS; } else { // use netmind SID provided by the tracker strNetMindSID = strNewSID.substr(0,43) + "-" + nNewTS; } } else { strNetMindSID = strNewSID; } } else { // no SID from cookie, use new SID if available strNetMindSID = strNewSID; } if ( strNetMindSID != "") { document.cookie = "NETMIND_SID="+strNetMindSID+"; path=/"; } } } strCgiSID = this.getCGISessionID(); if ( strCgiSID != null ) { strNetMindSID = strCgiSID; document.cookie = "NETMIND_SID="+strNetMindSID+"; path=/"; } this.m_strNetMindSID = strNetMindSID; return this.m_strNetMindSID; }//end function session_getSessionID() //========================================================== // getCGISessionID() // extract the session ID injected via CGI parameter. // returns null if no such parameter, or disabled, or if // already handled, i.e. the injected SID is available // as cookie. //========================================================== function remotesession_getCGISessionID() { if ( this.m_bCgiSIDHandled ) { // remote CGI SID already extracted. Must be available in the cookies. return null; } if ( !this.m_oConfig.getSIDParamDisabled || !this.m_oConfig.getSIDParamDisabled() ) { var strSIDParam = "nmsid"; if ( this.m_oConfig.getSIDParam ) { strSIDParam = this.m_oConfig.getSIDParam(); } if ( strSIDParam ) { this.m_bCgiSIDHandled = true; var strCgiSID = remotepixel_extractCGIParam( strSIDParam ); if ( strCgiSID == "" ) { return null; } return strCgiSID; } } return null; } // end function remotesession_getCGISessionID //========================================================== //add methods to class cSession //========================================================== cRemoteSession.prototype.getSessionID = remotesession_getSessionID; cRemoteSession.prototype.getCGISessionID = remotesession_getCGISessionID; //******************************************************************** //Pixel-Object //******************************************************************** //Contstructor for Pixel-Object function cRemotePixel(oConfig) { //----------------------------------------------------- // members //----------------------------------------------------- //pixel object constructor this.m_arParameterList = new Array(); this.m_nParameterCount = 0; //Configuration this.m_oConfig = oConfig; this.m_strPixelURL = oConfig.getPixelUrl(); this.m_strPixelURLPrefix = oConfig.getProtocol()+"://"+oConfig.getPixelServer() + "/"; this.m_strPixelURLSuffix = ""; var strPixelpath = oConfig.getPixelPath(); if (strPixelpath.charAt(0) == "/") { this.m_strPixelURLSuffix = strPixelpath.substr(1); } else { this.m_strPixelURLSuffix = strPixelpath; }//end else (PixelPath.charAt(0) == "/") if ( oConfig.m_bDebug ) { this.m_oDbgWin = window.open( "", "PixelDebug", "height=550,dependent=yes,scrollbars=yes,resizable=yes" ); if ( !this.m_oDbgWin.document.getElementById('_log_config') ) { this.m_oDbgWin.document.write( "PixelDebugConfig values:

Tracked values:

" ); this.writeConfig( true ); } else { this.writeConfig( false ); } } this.m_oIFrame = null; this.m_oBody = null; }//end function cRemotePixel() function remotepixel_writeConfig( bAppend ) { var oConfig = this.m_oConfig; this.writeDebug( document.URL, "_log_config", bAppend, true ); if ( oConfig.m_bDebug ) { if ( oConfig.isCookieTracking() ) { this.writeDebug( "Cookie Tracking enabled", "_log_config", true ); } else { this.writeDebug( "URL rewriting enabled
", "_log_config", true ); } if ( oConfig.isContentSideTracking() ) { this.writeDebug( "Contentside Tracking enabled", "_log_config", true ); } else { this.writeDebug( "Trackerside Tracking enabled", "_log_config", true ); } if ( oConfig.isHttpPostEnabled() ) { this.writeDebug( "HTTP POST enabled", "_log_config", true ); } else { this.writeDebug( "HTTP GET enabled", "_log_config", true ); } this.writeDebug( "Netmind Session Timeout: " + oConfig.m_nNetMindSessionTimeout, "_log_config", true ); this.writeDebug( "Autoparams: " + oConfig.m_bAutoparams, "_log_config", true ); this.writeDebug( "Autosend: " + oConfig.m_bAutosend, "_log_config", true ); this.writeDebug( "Send URL: " + oConfig.m_bSendUrl, "_log_config", true ); this.writeDebug( "Send Referrer: " + oConfig.m_bSendReferrer, "_log_config", true ); this.writeDebug( "Send MetaTags: " + oConfig.m_bSendMetaTags, "_log_config", true ); this.writeDebug( "Send TechInfo: " + oConfig.m_bSendTech, "_log_config", true ); this.writeDebug( "Send Url Hash: " + oConfig.m_bSendUrlHash, "_log_config", true ); this.writeDebug( "Send CGI-Params: " + oConfig.m_bSendCGIParams, "_log_config", true ); this.writeDebug( "Plugins to check:", "_log_config", true ); } } //========================================================== // Wenn der Debugging-Mode aktiviert wurde // (cConfigPixel.m_bDebug), wird der angegebene String im // Debug-Fenster ausgegeben. //========================================================== function remotepixel_writeDebug( strDebug, strElementId, bAppend, bBold ) { var oElem = null; if ( this.m_oDbgWin ) { if ( strElementId ) { oElem = this.m_oDbgWin.document.getElementById( strElementId ); } if ( !oElem ) { oElem = this.m_oDbgWin.document.getElementsByTagName( "body" )[0]; } if ( oElem ) { if ( !bAppend ) { oElem.nodeValue = ""; } if ( bBold ) { var oBold = this.m_oDbgWin.document.createElement("b"); oElem.appendChild( oBold ); oElem = oBold; } var oTextNode = this.m_oDbgWin.document.createTextNode( strDebug ); oElem.appendChild( oTextNode ); oElem.appendChild( this.m_oDbgWin.document.createElement("br") ); } } } //========================================================== // Method to convert the given value to a valid // representation. // Normally this method just returns the given value except: // * the value is of type object // * the JSON object is available // * and JSON is enabled in the config //========================================================== function remotepixel_convertValue(value) { if ( oNMConfig.isJSONEnabled() && typeof(value) == 'object' ) { return JSON.stringify(value); } return value; } //========================================================== //methode fuer Objekt Pixel: Fuegt einen Parameter hinzu //========================================================== function remotepixel_addParameter(key, value) { arPair = new Array(key, this.convertValue( value) ); this.m_arParameterList[this.m_nParameterCount] = arPair; this.m_nParameterCount++; }//end function pixel_add_parameter() //========================================================== // methode fuer Objekt Pixel: setzt einen Parameter. // wurde der Parameter bereits gesetzt, so wird er mit dem // neuen Wert ersetzt. //========================================================== function remotepixel_setParameter(key, value) { var arPair = new Array( key, this.convertValue( value ) ); var arExist; var nIdx; var bFound = false; for ( nIdx = 0; nIdx < this.m_nParameterCount; nIdx ++ ) { arExist = this.m_arParameterList[nIdx]; if ( arExist[0] == arPair[0] ) { // parameter already set, replace with new value bFound = true; this.m_arParameterList[nIdx] = arPair; break; } } if ( !bFound ) { // add new parameter: this.m_arParameterList[this.m_nParameterCount] = arPair; this.m_nParameterCount++; } } //========================================================== //method for object Pixel: add affiliate //========================================================== function remotepixel_addAffiliate(name) { this.addParameter("affiliate", name); this.writeDebug( "affiliate = '" + affiliate + "'", "_log_values", true ); }//end function remotepixel_addAffiliate(name) //========================================================== //method for object Pixel: add url // // // Customization // cha - 25.06.2008 - Cgi Paramter des aktuellen URI werden automatisiert als Paramter angehängt. // //========================================================== function remotepixel_addUrl() { var strUrlParam = document.URL; this.addParameter("url", strUrlParam); this.writeDebug( "url = '" + strUrlParam + "'", "_log_values", true ); }//end function remotepixel_addAffiliate(name) //========================================================== //method for object Pixel: add referrer //========================================================== function remotepixel_addReferrer() { this.addParameter("referrer", document.referrer); this.writeDebug( "referer = '" + document.referrer + "'", "_log_values", true ); }//end function remotepixel_addAffiliate(name) //========================================================== //method for object Pixel: add parameter to URL //========================================================== function remotepixel_addParamToUrl(strUrl, arParameterList) { if (strUrl.indexOf ("?") == -1) { strUrl = strUrl + "?"; } else { strUrl = strUrl + "&"; } for(var i=0; i0) strUrl += "&"; strUrl += escape(arParameterList[i][0])+"="+escape(arParameterList[i][1]); }//end for(i=0; i