Exemplo n.º 1
0
/**
 * This function builds the JavaScript to track variables for a tracker-impression via JavaScript
 *
 * @todo Ask Matteo what the $trackerJsCode is for
 *
 * @param int $trackerid                The ID of the tracker
 * @param array $conversionInfo         An array of the information from the tracker impression
 * @param unknown_type $trackerJsCode   Unknown
 *
 * @return string   The JavaScript to pick up the variables from the page, and pass them in to the
 *                  conversionvars script
 */
function MAX_trackerbuildJSVariablesScript($trackerid, $conversionInfo, $trackerJsCode = null)
{
    $conf = $GLOBALS['_MAX']['CONF'];
    $buffer = '';
    $url = MAX_commonGetDeliveryUrl($conf['file']['conversionvars']);
    $tracker = MAX_cacheGetTracker($trackerid);
    $variables = MAX_cacheGetTrackerVariables($trackerid);
    $variableQuerystring = '';
    if (empty($trackerJsCode)) {
        $trackerJsCode = md5(uniqid('', true));
    } else {
        // Appended tracker - set method to default
        $tracker['variablemethod'] = 'default';
    }
    if (!empty($variables)) {
        if ($tracker['variablemethod'] == 'dom') {
            $buffer .= "\n    function MAX_extractTextDom(o)\n    {\n        var txt = '';\n\n        if (o.nodeType == 3) {\n            txt = o.data;\n        } else {\n            for (var i = 0; i < o.childNodes.length; i++) {\n                txt += MAX_extractTextDom(o.childNodes[i]);\n            }\n        }\n\n        return txt;\n    }\n\n    function MAX_TrackVarDom(id, v)\n    {\n        if (max_trv[id][v]) { return; }\n        var o = document.getElementById(v);\n        if (o) {\n            max_trv[id][v] = escape(o.tagName == 'INPUT' ? o.value : MAX_extractTextDom(o));\n        }\n    }";
            $funcName = 'MAX_TrackVarDom';
        } elseif ($tracker['variablemethod'] == 'default') {
            $buffer .= "\n    function MAX_TrackVarDefault(id, v)\n    {\n        if (max_trv[id][v]) { return; }\n        if (typeof(window[v]) == undefined) { return; }\n        max_trv[id][v] = window[v];\n    }";
            $funcName = 'MAX_TrackVarDefault';
        } else {
            $buffer .= "\n    function MAX_TrackVarJs(id, v, c)\n    {\n        if (max_trv[id][v]) { return; }\n        if (typeof(window[v]) == undefined) { return; }\n        if (typeof(c) != 'undefined') {\n            eval(c);\n        }\n        max_trv[id][v] = window[v];\n    }";
            $funcName = 'MAX_TrackVarJs';
        }
        $buffer .= "\n    if (!max_trv) { var max_trv = new Array(); }\n    if (!max_trv['{$trackerJsCode}']) { max_trv['{$trackerJsCode}'] = new Array(); }";
        foreach ($variables as $key => $variable) {
            $variableQuerystring .= "&{$variable['name']}=\"+max_trv['{$trackerJsCode}']['{$variable['name']}']+\"";
            if ($tracker['variablemethod'] == 'custom') {
                $buffer .= "\n    {$funcName}('{$trackerJsCode}', '{$variable['name']}', '" . addcslashes($variable['variablecode'], "'") . "');";
            } else {
                $buffer .= "\n    {$funcName}('{$trackerJsCode}', '{$variable['name']}');";
            }
        }
        if (!empty($variableQuerystring)) {
            $buffer .= "\n    document.write (\"<\" + \"script language='JavaScript' type='text/javascript' src='\");\n    document.write (\"{$url}?trackerid={$trackerid}&server_conv_id={$conversionInfo['server_conv_id']}&server_raw_ip={$conversionInfo['server_raw_ip']}{$variableQuerystring}'\");";
            $buffer .= "\n\tdocument.write (\"><\\/scr\"+\"ipt>\");";
        }
    }
    if (!empty($tracker['appendcode'])) {
        // Add the correct "inherit" parameter if a OpenX trackercode was found
        $tracker['appendcode'] = preg_replace('/("\\?trackerid=\\d+&amp;inherit)=1/', '$1=' . $trackerJsCode, $tracker['appendcode']);
        $jscode = MAX_javascriptToHTML($tracker['appendcode'], "MAX_{$trackerid}_appendcode");
        // Replace template style variables
        $jscode = preg_replace("/\\{m3_trackervariable:(.+?)\\}/", "\"+max_trv['{$trackerJsCode}']['\$1']+\"", $jscode);
        $buffer .= "\n" . preg_replace('/^/m', "\t", $jscode) . "\n";
    }
    if (empty($buffer)) {
        $buffer = "document.write(\"\");";
    }
    return $buffer;
}
 /**
  * Method tests invalidateTrackerCache method
  */
 function test_invalidateTrackerCache()
 {
     $cachedTrackerData = MAX_cacheGetTracker($this->_aIds['tracker'][0]);
     $cachedTrackerVariablesData = MAX_cacheGetTrackerVariables($this->_aIds['tracker'][0]);
     // Do some changes in tracker
     $doTracker = OA_Dal::factoryDO('trackers');
     $doTracker->get($this->_aIds['trackers'][0]);
     $doTracker->description = 'new description';
     $doTracker->update();
     // Add new variable to the tracker
     $doVariables = OA_Dal::factoryDO('variables');
     $doVariables->trackerid = $this->_aIds['trackers'][0];
     DataGenerator::generateOne($doVariables);
     // Expect no changes in cache
     $this->assertEqual(MAX_cacheGetTracker($this->_aIds['tracker'][0]), $cachedTrackerData);
     $this->assertEqual(MAX_cacheGetTrackerVariables($this->_aIds['tracker'][0]), $cachedTrackerVariablesData);
     $this->oDeliveryCacheManager->invalidateTrackerCache($this->_aIds['trackers'][0]);
     // Now expect changes in cache
     $this->assertNotEqual(MAX_cacheGetTracker($this->_aIds['trackers'][0]), $cachedTrackerData);
     $this->assertNotEqual(MAX_cacheGetTrackerVariables($this->_aIds['trackers'][0]), $cachedTrackerVariablesData);
 }
 /**
  * Method tests invalidateGetTrackerCache method
  */
 function test_invalidateGetTrackerCache()
 {
     $aIds = $this->_createTestData();
     $this->_createTestCacheFiles($aIds);
     $cachedData = MAX_cacheGetTracker($aIds['tracker'][0]);
     // Do some changes in tracker
     $doTracker = OA_Dal::factoryDO('trackers');
     $doTracker->get($aIds['trackers'][0]);
     $doTracker->description = 'new description';
     $doTracker->update();
     // Expect no changes in cache
     $this->assertEqual(MAX_cacheGetTracker($aIds['tracker'][0]), $cachedData);
     $this->oDeliveryCacheCommon->invalidateGetTrackerCache($aIds['trackers'][0]);
     // Now expect changes in cache
     $this->assertNotEqual(MAX_cacheGetTracker($aIds['trackers'][0]), $cachedData);
 }
 /**
  * Creates all possible delivert cache files
  *
  * @param array $aIds array of DB Ids returned by _createTestData
  * @see _createTestData
  */
 function _createTestCacheFiles($aIds)
 {
     // Create cache files not related to DB Objects
     MAX_cacheGetAccountTZs();
     MAX_cacheCheckIfMaintenanceShouldRun();
     MAX_cacheGetGoogleJavaScript();
     // Create cache files for banners and images
     foreach ($aIds['banners'] as $bannerId) {
         MAX_cacheGetAd($bannerId);
     }
     foreach ($aIds['images'] as $filename) {
         MAX_cacheGetCreative($filename);
     }
     // Create cache files for zones
     foreach ($aIds['zones'] as $zoneId) {
         MAX_cacheGetZoneLinkedAds($zoneId);
         MAX_cacheGetZoneInfo($zoneId);
     }
     // Create cache files for websites
     foreach ($aIds['affiliates'] as $affiliateid) {
         OA_cacheGetPublisherZones($affiliateid);
     }
     // Create cache files for trackers
     foreach ($aIds['trackers'] as $trackerid) {
         MAX_cacheGetTracker($trackerid);
         MAX_cacheGetTrackerVariables($trackerid);
     }
     // Create cache files for channels
     foreach ($aIds['channel'] as $channelid) {
         MAX_cacheGetChannelLimitations($channelid);
     }
     // cache files for direct-selection are not created
     // due to problems with invalidating MAX_cacheGetLinkedAds
 }
Exemplo n.º 5
0
        }
        $logVars = true;
    }
}
MAX_cookieFlush();
// Write the code for tracking the variable values, and any
// additional appended tracker code
if ($logVars) {
    // The $logVars variable contains the code for tracking
    // the variable values (if required by the tracker), and
    // also the code for appending any additional tracker code
    // IF there was a conversion
    echo "{$variablesScript}";
} else {
    if ($append == true) {
        // As $logVars was empty, this could mean that there are
        // no variable values to track and there is no additional
        // appended code required; but it could also mean that
        // although there is additional appended code required, there
        // was no conversion recorded. As the $append variable
        // is true, double check to see if there is any additional
        // appended tracker code, and if so, send it
        $aTracker = MAX_cacheGetTracker($trackerid);
        if (!empty($aTracker['appendcode'])) {
            $appendScript = MAX_javascriptToHTML($aTracker['appendcode'], "MAX_{$trackerid}_appendcode", true);
            echo $appendScript;
        }
    }
}
// Post tracker render hook
OX_Delivery_Common_hook('postTrackerRender', array(&$aConversion, &$aConversionInfo, &$trackerid, &$inherit));