示例#1
-1
function track($campaign, $keyword)
{
    # Piwik URL
    PiwikTracker::$URL = $GLOBALS['config']['piwik_url'];
    # PiwikTracker
    $piwik = new PiwikTracker($GLOBALS['config']['idsite']);
    # required for setIP()
    $piwik->setTokenAuth($GLOBALS['config']['piwik_token']);
    # IP of the remote client
    $piwik->setIP($_SERVER['REMOTE_ADDR']);
    # User Agent String of the client
    $piwik->setUserAgent($_SERVER['HTTP_USER_AGENT']);
    # get the schema
    $schema = 'https://';
    if (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] === 'off') {
        $schema = 'http://';
    }
    # set the tracked URL
    $piwik->setUrl($schema . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
    # referer
    $piwik->setUrlReferrer($_SERVER['HTTP_REFERER']);
    # set attribution info (keyword, campaign, et al)
    # http://developer.piwik.org/api-reference/PHP-Piwik-Tracker#setattributioninfo
    # 0 - campaign name
    # 1 - keyword
    # 2 - timestamp
    # 3 - referrer
    $att = json_encode(array($campaign, $keyword, time(), $_SERVER['HTTP_REFERER']));
    $piwik->setAttributionInfo($att);
    if (defined("DEBUG") and DEBUG) {
        header("X-Debug-Referred: from " . $_SERVER['HTTP_REFERER']);
        header("X-Debug-AttInfo: {$att}");
    }
    # do track the page view
    if (empty($keyword)) {
        $keyword = 'none';
    }
    $piwik->doTrackPageView("Reprint Tracker for: {$campaign} (keyword: {$keyword})");
    if (defined("DEBUG") and DEBUG) {
        header('X-Last-Piwik-Call: ' . $piwik::$DEBUG_LAST_REQUESTED_URL);
    }
}