Example #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;
}
Example #2
0
<?php

/*
+---------------------------------------------------------------------------+
| Revive Adserver                                                           |
| http://www.revive-adserver.com                                            |
|                                                                           |
| Copyright: See the COPYRIGHT.txt file.                                    |
| License: GPLv2 or later, see the LICENSE.txt file.                        |
+---------------------------------------------------------------------------+
*/
// Require the initialisation file
require_once '../../init-delivery.php';
// Required files
require_once MAX_PATH . '/lib/max/Delivery/cache.php';
// Register input variables
if (!empty($_GET['trackerid'])) {
    $trackerId = $_GET['trackerid'];
    $serverConvId = isset($_GET['server_conv_id']) ? $_GET['server_conv_id'] : null;
    $serverRawIp = isset($_GET['server_raw_ip']) ? $_GET['server_raw_ip'] : null;
    $aVariables = MAX_cacheGetTrackerVariables($trackerId);
    MAX_Delivery_log_logVariableValues($aVariables, $trackerId, $serverConvId, $serverRawIp);
}
 /**
  * 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);
 }
 /**
  * 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
 }
Example #5
0
require_once MAX_PATH . '/lib/max/Delivery/cache.php';
require_once MAX_PATH . '/lib/max/Delivery/javascript.php';
require_once MAX_PATH . '/lib/max/Delivery/tracker.php';
// No Caching
MAX_commonSetNoCacheHeaders();
//Register any script specific input variables
MAX_commonRegisterGlobalsArray(array('trackerid'));
if (empty($trackerid)) {
    $trackerid = 0;
}
// Log the tracker impression
if ($conf['logging']['trackerImpressions']) {
    $aConversion = MAX_trackerCheckForValidAction($trackerid);
    if (!empty($aConversion)) {
        $aConversionInfo = MAX_Delivery_log_logConversion($trackerid, $aConversion);
        foreach ($aConversionInfo as $pluginId => $aData) {
            $serverConvId = $serverRawIp = null;
            if (isset($aData['server_conv_id'])) {
                $serverConvId = $aData['server_conv_id'];
            }
            if (isset($aData['server_raw_ip'])) {
                $serverRawIp = $aData['server_raw_ip'];
            }
            // Log tracker impression variable values
            MAX_Delivery_log_logVariableValues(MAX_cacheGetTrackerVariables($trackerid), $trackerid, $serverConvId, $serverRawIp, $pluginId);
        }
    }
}
MAX_cookieFlush();
// Send a 1 x 1 gif
MAX_commonDisplay1x1();
 /**
  * Method tests invalidateGetTrackerVariablesCache method
  */
 function test_invalidateGetTrackerVariablesCache()
 {
     $aIds = $this->_createTestData();
     $this->_createTestCacheFiles($aIds);
     $cachedData = MAX_cacheGetTrackerVariables($aIds['tracker'][0]);
     // Add new variable to the tracker
     $doVariables = OA_Dal::factoryDO('variables');
     $doVariables->trackerid = $aIds['trackers'][0];
     DataGenerator::generateOne($doVariables);
     // Expect no changes in cache
     $this->assertEqual(MAX_cacheGetTrackerVariables($aIds['tracker'][0]), $cachedData);
     $this->oDeliveryCacheCommon->invalidateGetTrackerVariablesCache($aIds['trackers'][0]);
     // Now expect changes in cache
     $this->assertNotEqual(MAX_cacheGetTrackerVariables($aIds['trackers'][0]), $cachedData);
 }