Beispiel #1
0
function MAX_trackerCheckForValidAction($trackerid)
{
    $aTrackerLinkedAds = MAX_cacheGetTrackerLinkedCreatives($trackerid);
    if (empty($aTrackerLinkedAds)) {
        return false;
    }
    $aPossibleActions = _getActionTypes();
    $now = MAX_commonGetTimeNow();
    $aConf = $GLOBALS['_MAX']['CONF'];
    $aMatchingActions = array();
    foreach ($aTrackerLinkedAds as $creativeId => $aLinkedInfo) {
        foreach ($aPossibleActions as $actionId => $action) {
            if (!empty($aLinkedInfo[$action . '_window']) && !empty($_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId])) {
                if (stristr($_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId], ' ')) {
                    list($value, $extra) = explode(' ', $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId], 2);
                    $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId] = $value;
                } else {
                    $extra = '';
                }
                list($lastAction, $zoneId) = explode('-', $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId]);
                $lastAction = MAX_commonUnCompressInt($lastAction);
                $lastSeenSecondsAgo = $now - $lastAction;
                if ($lastSeenSecondsAgo <= $aLinkedInfo[$action . '_window'] && $lastSeenSecondsAgo > 0) {
                    $aMatchingActions[$lastSeenSecondsAgo] = array('action_type' => $actionId, 'tracker_type' => $aLinkedInfo['tracker_type'], 'status' => $aLinkedInfo['status'], 'cid' => $creativeId, 'zid' => $zoneId, 'dt' => $lastAction, 'window' => $aLinkedInfo[$action . '_window'], 'extra' => $extra);
                }
            }
        }
    }
    if (empty($aMatchingActions)) {
        return false;
    }
    ksort($aMatchingActions);
    return array_shift($aMatchingActions);
}
Beispiel #2
0
/**
 * This function checks if the specified tracker connects back to a valid action
 *
 * @param integer $trackerid The ID of the tracker to look up in the database
 * @return mixed If action occurred: array indexed on [#s since action] => array('type' => <connection type>, 'id' => <creative ID>
 *               else false
 */
function MAX_trackerCheckForValidAction($trackerid)
{
    // Get all creatives that are linked to this tracker
    $aTrackerLinkedAds = MAX_cacheGetTrackerLinkedCreatives($trackerid);
    // This tracker is not linked to any creatives
    if (empty($aTrackerLinkedAds)) {
        return false;
    }
    // Note: Constants are not included n the delivery engine, the values below map to the values defined in constants.php
    $aPossibleActions = _getActionTypes();
    $now = MAX_commonGetTimeNow();
    $aConf = $GLOBALS['_MAX']['CONF'];
    $aMatchingActions = array();
    // Iterate over all creatives linked to this tracker...
    foreach ($aTrackerLinkedAds as $creativeId => $aLinkedInfo) {
        // Iterate over all possible actions (currently only "view" and "click")
        foreach ($aPossibleActions as $actionId => $action) {
            // If there is both a connection window set, and this creative has been actioned
            if (!empty($aLinkedInfo[$action . '_window']) && !empty($_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId])) {
                // Check for any custom data which a plugin may have stored in the cookie
                if (stristr($_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId], ' ')) {
                    list($value, $extra) = explode(' ', $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId], 2);
                    $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId] = $value;
                } else {
                    $extra = '';
                }
                list($lastAction, $zoneId) = explode('-', $_COOKIE[$aConf['var']['last' . ucfirst($action)]][$creativeId]);
                // Decode the base32 timestamp
                $lastAction = MAX_commonUnCompressInt($lastAction);
                // Calculate how long ago this action occurred
                $lastSeenSecondsAgo = $now - $lastAction;
                // If the action occurred within the window (and sanity check that it's > 0), record this as a matching action
                if ($lastSeenSecondsAgo <= $aLinkedInfo[$action . '_window'] && $lastSeenSecondsAgo > 0) {
                    // Index the matching array against the # seconds ago that the action occurred
                    $aMatchingActions[$lastSeenSecondsAgo] = array('action_type' => $actionId, 'tracker_type' => $aLinkedInfo['tracker_type'], 'status' => $aLinkedInfo['status'], 'cid' => $creativeId, 'zid' => $zoneId, 'dt' => $lastAction, 'window' => $aLinkedInfo[$action . '_window'], 'extra' => $extra);
                }
            }
        }
    }
    // If no actions matched, return false
    if (empty($aMatchingActions)) {
        return false;
    }
    // Sort by ascending #seconds since action
    ksort($aMatchingActions);
    // Return the first matching action
    return array_shift($aMatchingActions);
}