setAttributionInfo() public method

This must be a JSON encoded string that would typically be fetched from the JS API: piwikTracker.getAttributionInfo() and that you have JSON encoded via JSON2.stringify() If you call enableCookies() then these referral attribution values will be set to the 'ref' first party cookie storing referral information.
See also: function getAttributionInfo() in https://github.com/piwik/piwik/blob/master/js/piwik.js
public setAttributionInfo ( string $jsonEncoded )
$jsonEncoded string JSON encoded array containing Attribution info
Exemplo n.º 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);
    }
}