PHP Class PiwikTracker, piwik-php-tracker

Inheritance: extends Tracker
显示文件 Open project: piwik/piwik-php-tracker Class Usage Examples

Public Properties

Property Type Description
$DEBUG_APPEND_URL
$DEBUG_LAST_REQUESTED_URL Used in tests to output useful error messages.
$URL string Piwik base URL, for example http://example.org/piwik/ Must be set before using the class by calling PiwikTracker::$URL = 'http://yourwebsite.org/piwik/';

Public Methods

Method Description
__construct ( integer $idSite, string $apiUrl = '' ) Builds a PiwikTracker object, used to track visits, pages and Goal conversions for a specific website, by using the Piwik Tracking API.
addEcommerceItem ( string $sku, string $name = '', string | array $category = '', float | integer $price, integer $quantity = 1 ) Adds an item in the Ecommerce order.
clearCustomTrackingParameters ( ) Clear / reset all previously set custom tracking parameters.
clearCustomVariables ( ) Clears any Custom Variable that may be have been set.
deleteCookies ( ) Deletes all first party cookies from the client
disableCookieSupport ( ) By default, PiwikTracker will read first party cookies from the request and write updated cookies in the response (using setrawcookie).
disableSendImageResponse ( ) If image response is disabled Piwik will respond with a HTTP 204 header instead of responding with a gif.
doBulkTrack ( ) : string Sends all stored tracking actions at once. Only has an effect if bulk tracking is enabled.
doPing ( ) : mixed Sends a ping request.
doTrackAction ( string $actionUrl, string $actionType ) : mixed Tracks a download or outlink
doTrackContentImpression ( string $contentName, string $contentPiece = 'Unknown', string | boolean $contentTarget = false ) : mixed Tracks a content impression
doTrackContentInteraction ( string $interaction, string $contentName, string $contentPiece = 'Unknown', string | boolean $contentTarget = false ) : mixed Tracks a content interaction. Make sure you have tracked a content impression using the same content name and content piece, otherwise it will not count. To do so you should call the method doTrackContentImpression();
doTrackEcommerceCartUpdate ( float $grandTotal ) : mixed Tracks a Cart Update (add item, remove item, update item).
doTrackEcommerceOrder ( string | integer $orderId, float $grandTotal, float $subTotal, float $tax, float $shipping, float $discount ) : mixed Tracks an Ecommerce order.
doTrackEvent ( string $category, string $action, string | boolean $name = false, float | boolean $value = false ) : mixed Tracks an event
doTrackGoal ( integer $idGoal, float $revenue ) : mixed Records a Goal conversion
doTrackPageView ( string $documentTitle ) : mixed Tracks a page view
doTrackSiteSearch ( string $keyword, string $category = '', boolean | integer $countResults = false ) : mixed Tracks an internal Site Search query, and optionally tracks the Search Category, and Search results Count.
enableBulkTracking ( ) Enables the bulk request feature. When used, each tracking action is stored until the doBulkTrack method is called. This method will send all tracking data at once.
enableCookies ( string $domain = '', string $path = '/' ) Enable Cookie Creation - this will cause a first party VisitorId cookie to be set when the VisitorId is set or reset
getAttributionInfo ( ) : string Returns the currently assigned Attribution Information stored in a first party cookie.
getCustomVariable ( integer $id, string $scope = 'visit' ) : mixed Returns the currently assigned Custom Variable.
getRequestTimeout ( ) Returns the maximum number of seconds the tracker will spend waiting for a response from Piwik. Defaults to 600 seconds.
getUrlTrackAction ( string $actionUrl, string $actionType ) : string Builds URL to track a new action.
getUrlTrackContentImpression ( string $contentName, string $contentPiece, string | false $contentTarget ) : string Builds URL to track a content impression.
getUrlTrackContentInteraction ( string $interaction, string $contentName, string $contentPiece, string | false $contentTarget ) : string Builds URL to track a content impression.
getUrlTrackEcommerceCartUpdate ( $grandTotal ) Returns URL used to track Ecommerce Cart updates Calling this function will reinitializes the property ecommerceItems to empty array so items will have to be added again via addEcommerceItem()
getUrlTrackEcommerceOrder ( $orderId, $grandTotal, $subTotal, $tax, $shipping, $discount ) Returns URL used to track Ecommerce Orders Calling this function will reinitializes the property ecommerceItems to empty array so items will have to be added again via addEcommerceItem()
getUrlTrackEvent ( string $category, string $action, string | boolean $name = false, float | boolean $value = false ) : string Builds URL to track a custom event.
getUrlTrackGoal ( integer $idGoal, float $revenue ) : string Builds URL to track a goal with idGoal and revenue.
getUrlTrackPageView ( string $documentTitle = '' ) : string Builds URL to track a page view.
getUrlTrackSiteSearch ( string $keyword, string $category, integer $countResults ) : string Builds URL to track a site search.
getUserId ( ) : boolean Returns the User ID string, which may have been set via: $v->setUserId('[email protected]');
getUserIdHashed ( $id ) : string Hash function used internally by Piwik to hash a User ID into the Visitor ID.
getVisitorId ( ) : string If the user initiating the request has the Piwik first party cookie, this function will try and return the ID parsed from this first party cookie (found in $_COOKIE).
setAttributionInfo ( string $jsonEncoded ) Sets the attribution information to the visit, so that subsequent Goal conversions are properly attributed to the right Referrer URL, timestamp, Campaign Name & Keyword.
setBrowserHasCookies ( boolean $bool ) Sets if the browser supports cookies This is reported in "List of plugins" report in Piwik.
setBrowserLanguage ( string $acceptLanguage ) Sets the Browser language. Used to guess visitor countries when GeoIP is not enabled
setCity ( string $city ) Sets the city of the visitor. If not used, Piwik may try to find the city using the visitor's IP address (if configured to do so).
setCountry ( string $country ) Sets the country of the visitor. If not used, Piwik will try to find the country using either the visitor's IP address or language.
setCustomTrackingParameter ( string $trackingApiParameter, string $value ) Sets a custom tracking parameter. This is useful if you need to send any tracking parameters for a 3rd party plugin that is not shipped with Piwik itself. Please note that custom parameters are cleared after each tracking request.
setCustomVariable ( integer $id, string $name, string $value, string $scope = 'visit' ) Sets Visit Custom Variable.
setDebugStringAppend ( string $string ) Will append a custom string at the end of the Tracking request.
setEcommerceView ( string $sku = '', string $name = '', string | array $category = '', float $price ) Sets the current page view as an item (product) page view, or an Ecommerce Category page view.
setForceNewVisit ( ) Forces Piwik to create a new visit for the tracking request.
setForceVisitDateTime ( string $dateTime ) Overrides server date and time for the tracking requests.
setGenerationTime ( integer $timeMs ) Sets the time that generating the document on the server side took.
setIdSite ( integer $idSite ) Sets the current site ID.
setIp ( string $ip ) Overrides IP address
setLatitude ( float $lat ) Sets the latitude of the visitor. If not used, Piwik may try to find the visitor's latitude using the visitor's IP address (if configured to do so).
setLocalTime ( string $time ) Sets local visitor time
setLongitude ( float $long ) Sets the longitude of the visitor. If not used, Piwik may try to find the visitor's longitude using the visitor's IP address (if configured to do so).
setNewVisitorId ( ) Sets the current visitor ID to a random new one.
setPageCharset ( string $charset = '' ) By default, Piwik expects utf-8 encoded values, for example for the page URL parameter values, Page Title, etc.
setPlugins ( boolean $flash = false, boolean $java = false, boolean $director = false, boolean $quickTime = false, boolean $realPlayer = false, boolean $pdf = false, boolean $windowsMedia = false, boolean $gears = false, boolean $silverlight = false ) Sets visitor browser supported plugins
setProxy ( string $proxy, integer $proxyPort = 80 ) If a proxy is needed to look up the address of the Piwik site, set it with this
setRegion ( string $region ) Sets the region of the visitor. If not used, Piwik may try to find the region using the visitor's IP address (if configured to do so).
setRequestTimeout ( integer $timeout ) Sets the maximum number of seconds that the tracker will spend waiting for a response from Piwik.
setResolution ( integer $width, integer $height ) Sets user resolution width and height.
setTokenAuth ( string $token_auth ) Some Tracking API functionality requires express authentication, using either the Super User token_auth, or a user with 'admin' access to the website.
setUrl ( string $url ) Sets the current URL being tracked
setUrlReferer ( $url )
setUrlReferrer ( string $url ) Sets the URL referrer used to track Referrers details for new visits.
setUserAgent ( string $userAgent ) Sets the user agent, used to detect OS and browser.
setUserId ( string $userId ) Force the action to be recorded for a specific User. The User ID is a string representing a given user in your system.
setVisitorId ( string $visitorId ) Forces the requests to be recorded for the specified Visitor ID.

Protected Methods

Method Description
domainFixup ( $domain ) Fix-up domain
getBaseUrl ( ) Returns the base URL for the piwik server.
getCookieMatchingName ( string $name ) : string Returns a first party cookie which name contains $name
getCookieName ( string $cookieName ) : string Get cookie name with prefix and domain hash
getCurrentHost ( ) : string If current URL is "http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return "http://example.org"
getCurrentQueryString ( ) : string If current URL is "http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return "?param1=value1¶m2=value2"
getCurrentScheme ( ) : string If the current URL is 'http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return 'http'
getCurrentScriptName ( ) : string If current URL is "http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return "/dir1/dir2/index.php"
getCurrentUrl ( ) : string Returns the current full URL (scheme, host, path and query string.
getCustomVariablesFromCookie ( ) : boolean | mixed
getRequest ( $idSite )
getTimestamp ( ) : string | integer Returns current timestamp, or forced timestamp/datetime if it was set
getUrlTrackEcommerce ( $grandTotal, $subTotal, $tax, $shipping, $discount ) Returns URL used to track Ecommerce orders
loadVisitorIdCookie ( ) : boolean Loads values from the VisitorId Cookie
sendRequest ( $url, $method = 'GET', $data = null, $force = false )
setCookie ( $cookieName, $cookieValue, $cookieTTL ) Sets a first party cookie to the client to improve dual JS-PHP tracking.
setFirstPartyCookies ( ) Sets the first party cookies as would the piwik.js All cookies are supported: 'id' and 'ses' and 'ref' and 'cvar' cookies.

Private Methods

Method Description
forceDotAsSeparatorForDecimalPoint ( float | string $value ) : string Force the separator for decimal point to be a dot. See https://github.com/piwik/piwik/issues/6435 If for instance a German locale is used it would be a comma otherwise.
getProxy ( ) If the proxy IP and the proxy port have been set, with the setProxy() function returns a string, like "173.234.92.107:80"

Method Details

__construct() public method

Builds a PiwikTracker object, used to track visits, pages and Goal conversions for a specific website, by using the Piwik Tracking API.
public __construct ( integer $idSite, string $apiUrl = '' )
$idSite integer Id site to be tracked
$apiUrl string "http://example.org/piwik/" or "http://piwik.example.org/" If set, will overwrite PiwikTracker::$URL

addEcommerceItem() public method

This should be called before doTrackEcommerceOrder(), or before doTrackEcommerceCartUpdate(). This function can be called for all individual products in the cart (or order). SKU parameter is mandatory. Other parameters are optional (set to false if value not known). Ecommerce items added via this function are automatically cleared when doTrackEcommerceOrder() or getUrlTrackEcommerceOrder() is called.
public addEcommerceItem ( string $sku, string $name = '', string | array $category = '', float | integer $price, integer $quantity = 1 )
$sku string (required) SKU, Product identifier
$name string (optional) Product name
$category string | array (optional) Product category, or array of product categories (up to 5 categories can be specified for a given product)
$price float | integer (optional) Individual product price (supports integer and decimal prices)
$quantity integer (optional) Product quantity. If not specified, will default to 1 in the Reports

clearCustomTrackingParameters() public method

Clear / reset all previously set custom tracking parameters.

clearCustomVariables() public method

This can be useful when you have enabled bulk requests, and you wish to clear Custom Variables of 'visit' scope.

deleteCookies() public method

Deletes all first party cookies from the client
public deleteCookies ( )

disableCookieSupport() public method

This can be disabled by calling this function.

disableSendImageResponse() public method

If image response is disabled Piwik will respond with a HTTP 204 header instead of responding with a gif.

doBulkTrack() public method

To enable bulk tracking, call enableBulkTracking().
public doBulkTrack ( ) : string
return string Response

doPing() public method

Ping requests do not track new actions. If they are sent within the standard visit length (see global.ini.php), they will extend the existing visit and the current last action for the visit. If after the standard visit length, ping requests will create a new visit using the last action in the last known visit.
public doPing ( ) : mixed
return mixed Response or true if using bulk request

doTrackAction() public method

Tracks a download or outlink
public doTrackAction ( string $actionUrl, string $actionType ) : mixed
$actionUrl string URL of the download or outlink
$actionType string Type of the action: 'download' or 'link'
return mixed Response or true if using bulk request

doTrackContentImpression() public method

Tracks a content impression
public doTrackContentImpression ( string $contentName, string $contentPiece = 'Unknown', string | boolean $contentTarget = false ) : mixed
$contentName string The name of the content. For instance 'Ad Foo Bar'
$contentPiece string The actual content. For instance the path to an image, video, audio, any text
$contentTarget string | boolean (optional) The target of the content. For instance the URL of a landing page.
return mixed Response string or true if using bulk requests.

doTrackContentInteraction() public method

Tracks a content interaction. Make sure you have tracked a content impression using the same content name and content piece, otherwise it will not count. To do so you should call the method doTrackContentImpression();
public doTrackContentInteraction ( string $interaction, string $contentName, string $contentPiece = 'Unknown', string | boolean $contentTarget = false ) : mixed
$interaction string The name of the interaction with the content. For instance a 'click'
$contentName string The name of the content. For instance 'Ad Foo Bar'
$contentPiece string The actual content. For instance the path to an image, video, audio, any text
$contentTarget string | boolean (optional) The target the content leading to when an interaction occurs. For instance the URL of a landing page.
return mixed Response string or true if using bulk requests.

doTrackEcommerceCartUpdate() public method

On every Cart update, you must call addEcommerceItem() for each item (product) in the cart, including the items that haven't been updated since the last cart update. Items which were in the previous cart and are not sent in later Cart updates will be deleted from the cart (in the database).
public doTrackEcommerceCartUpdate ( float $grandTotal ) : mixed
$grandTotal float Cart grandTotal (typically the sum of all items' prices)
return mixed Response or true if using bulk request

doTrackEcommerceOrder() public method

If the Ecommerce order contains items (products), you must call first the addEcommerceItem() for each item in the order. All revenues (grandTotal, subTotal, tax, shipping, discount) will be individually summed and reported in Piwik reports. Only the parameters $orderId and $grandTotal are required.
public doTrackEcommerceOrder ( string | integer $orderId, float $grandTotal, float $subTotal, float $tax, float $shipping, float $discount ) : mixed
$orderId string | integer (required) Unique Order ID. This will be used to count this order only once in the event the order page is reloaded several times. orderId must be unique for each transaction, even on different days, or the transaction will not be recorded by Piwik.
$grandTotal float (required) Grand Total revenue of the transaction (including tax, shipping, etc.)
$subTotal float (optional) Sub total amount, typically the sum of items prices for all items in this order (before Tax and Shipping costs are applied)
$tax float (optional) Tax amount for this order
$shipping float (optional) Shipping amount for this order
$discount float (optional) Discounted amount in this order
return mixed Response or true if using bulk request

doTrackEvent() public method

Tracks an event
public doTrackEvent ( string $category, string $action, string | boolean $name = false, float | boolean $value = false ) : mixed
$category string The Event Category (Videos, Music, Games...)
$action string The Event's Action (Play, Pause, Duration, Add Playlist, Downloaded, Clicked...)
$name string | boolean (optional) The Event's object Name (a particular Movie name, or Song name, or File name...)
$value float | boolean (optional) The Event's value
return mixed Response string or true if using bulk requests.

doTrackGoal() public method

Records a Goal conversion
public doTrackGoal ( integer $idGoal, float $revenue ) : mixed
$idGoal integer Id Goal to record a conversion
$revenue float Revenue for this conversion
return mixed Response or true if using bulk request

doTrackPageView() public method

Tracks a page view
public doTrackPageView ( string $documentTitle ) : mixed
$documentTitle string Page title as it will appear in the Actions > Page titles report
return mixed Response string or true if using bulk requests.

doTrackSiteSearch() public method

These are used to populate reports in Actions > Site Search.
public doTrackSiteSearch ( string $keyword, string $category = '', boolean | integer $countResults = false ) : mixed
$keyword string Searched query on the site
$category string (optional) Search engine category if applicable
$countResults boolean | integer (optional) results displayed on the search result page. Used to track "zero result" keywords.
return mixed Response or true if using bulk requests.

domainFixup() protected static method

Fix-up domain
protected static domainFixup ( $domain )

enableBulkTracking() public method

Enables the bulk request feature. When used, each tracking action is stored until the doBulkTrack method is called. This method will send all tracking data at once.
public enableBulkTracking ( )

enableCookies() public method

Enable Cookie Creation - this will cause a first party VisitorId cookie to be set when the VisitorId is set or reset
public enableCookies ( string $domain = '', string $path = '/' )
$domain string (optional) Set first-party cookie domain. Accepted values: example.com, *.example.com (same as .example.com) or subdomain.example.com
$path string (optional) Set first-party cookie path

getAttributionInfo() public method

This function will only work if the user is initiating the current request, and his cookies can be read by PHP from the $_COOKIE array.
public getAttributionInfo ( ) : string
return string JSON Encoded string containing the Referrer information for Goal conversion attribution. Will return false if the cookie could not be found

getBaseUrl() protected method

Returns the base URL for the piwik server.
protected getBaseUrl ( )

getCookieMatchingName() protected method

Returns a first party cookie which name contains $name
protected getCookieMatchingName ( string $name ) : string
$name string
return string String value of cookie, or false if not found

getCookieName() protected method

Get cookie name with prefix and domain hash
protected getCookieName ( string $cookieName ) : string
$cookieName string
return string

getCurrentHost() protected static method

If current URL is "http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return "http://example.org"
protected static getCurrentHost ( ) : string
return string

getCurrentQueryString() protected static method

If current URL is "http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return "?param1=value1¶m2=value2"
protected static getCurrentQueryString ( ) : string
return string

getCurrentScheme() protected static method

If the current URL is 'http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return 'http'
protected static getCurrentScheme ( ) : string
return string 'https' or 'http'

getCurrentScriptName() protected static method

If current URL is "http://example.org/dir1/dir2/index.php?param1=value1¶m2=value2" will return "/dir1/dir2/index.php"
protected static getCurrentScriptName ( ) : string
return string

getCurrentUrl() protected static method

Returns the current full URL (scheme, host, path and query string.
protected static getCurrentUrl ( ) : string
return string

getCustomVariable() public method

If scope is 'visit', it will attempt to read the value set in the first party cookie created by Piwik Tracker ($_COOKIE array).
public getCustomVariable ( integer $id, string $scope = 'visit' ) : mixed
$id integer Custom Variable integer index to fetch from cookie. Should be a value from 1 to 5
$scope string Custom variable scope. Possible values: visit, page, event
return mixed An array with this format: array( 0 => CustomVariableName, 1 => CustomVariableValue ) or false

getCustomVariablesFromCookie() protected method

getRequest() protected method

protected getRequest ( $idSite )

getRequestTimeout() public method

Returns the maximum number of seconds the tracker will spend waiting for a response from Piwik. Defaults to 600 seconds.
public getRequestTimeout ( )

getTimestamp() protected method

Returns current timestamp, or forced timestamp/datetime if it was set
protected getTimestamp ( ) : string | integer
return string | integer

getUrlTrackAction() public method

Builds URL to track a new action.
See also: doTrackAction()
public getUrlTrackAction ( string $actionUrl, string $actionType ) : string
$actionUrl string URL of the download or outlink
$actionType string Type of the action: 'download' or 'link'
return string URL to piwik.php with all parameters set to track an action

getUrlTrackContentImpression() public method

Builds URL to track a content impression.
See also: doTrackContentImpression()
public getUrlTrackContentImpression ( string $contentName, string $contentPiece, string | false $contentTarget ) : string
$contentName string The name of the content. For instance 'Ad Foo Bar'
$contentPiece string The actual content. For instance the path to an image, video, audio, any text
$contentTarget string | false (optional) The target of the content. For instance the URL of a landing page.
return string URL to piwik.php with all parameters set to track the pageview

getUrlTrackContentInteraction() public method

Builds URL to track a content impression.
See also: doTrackContentInteraction()
public getUrlTrackContentInteraction ( string $interaction, string $contentName, string $contentPiece, string | false $contentTarget ) : string
$interaction string The name of the interaction with the content. For instance a 'click'
$contentName string The name of the content. For instance 'Ad Foo Bar'
$contentPiece string The actual content. For instance the path to an image, video, audio, any text
$contentTarget string | false (optional) The target the content leading to when an interaction occurs. For instance the URL of a landing page.
return string URL to piwik.php with all parameters set to track the pageview

getUrlTrackEcommerce() protected method

Calling this function will reinitializes the property ecommerceItems to empty array so items will have to be added again via addEcommerceItem()
protected getUrlTrackEcommerce ( $grandTotal, $subTotal, $tax, $shipping, $discount )

getUrlTrackEcommerceCartUpdate() public method

Returns URL used to track Ecommerce Cart updates Calling this function will reinitializes the property ecommerceItems to empty array so items will have to be added again via addEcommerceItem()
public getUrlTrackEcommerceCartUpdate ( $grandTotal )

getUrlTrackEcommerceOrder() public method

Returns URL used to track Ecommerce Orders Calling this function will reinitializes the property ecommerceItems to empty array so items will have to be added again via addEcommerceItem()
public getUrlTrackEcommerceOrder ( $orderId, $grandTotal, $subTotal, $tax, $shipping, $discount )

getUrlTrackEvent() public method

Builds URL to track a custom event.
See also: doTrackEvent()
public getUrlTrackEvent ( string $category, string $action, string | boolean $name = false, float | boolean $value = false ) : string
$category string The Event Category (Videos, Music, Games...)
$action string The Event's Action (Play, Pause, Duration, Add Playlist, Downloaded, Clicked...)
$name string | boolean (optional) The Event's object Name (a particular Movie name, or Song name, or File name...)
$value float | boolean (optional) The Event's value
return string URL to piwik.php with all parameters set to track the pageview

getUrlTrackGoal() public method

Builds URL to track a goal with idGoal and revenue.
See also: doTrackGoal()
public getUrlTrackGoal ( integer $idGoal, float $revenue ) : string
$idGoal integer Id Goal to record a conversion
$revenue float Revenue for this conversion
return string URL to piwik.php with all parameters set to track the goal conversion

getUrlTrackPageView() public method

Builds URL to track a page view.
See also: doTrackPageView()
public getUrlTrackPageView ( string $documentTitle = '' ) : string
$documentTitle string Page view name as it will appear in Piwik reports
return string URL to piwik.php with all parameters set to track the pageview

getUrlTrackSiteSearch() public method

Builds URL to track a site search.
See also: doTrackSiteSearch()
public getUrlTrackSiteSearch ( string $keyword, string $category, integer $countResults ) : string
$keyword string
$category string
$countResults integer
return string

getUserId() public method

Returns the User ID string, which may have been set via: $v->setUserId('[email protected]');
public getUserId ( ) : boolean
return boolean

getUserIdHashed() public static method

Note: matches implementation of Tracker\Request->getUserIdHashed()
public static getUserIdHashed ( $id ) : string
$id
return string

getVisitorId() public method

If you call this function from a server, where the call is triggered by a cron or script not initiated by the actual visitor being tracked, then it will return the random Visitor ID that was assigned to this visit object. This can be used if you wish to record more visits, actions or goals for this visitor ID later on.
public getVisitorId ( ) : string
return string 16 hex chars visitor ID string

loadVisitorIdCookie() protected method

Loads values from the VisitorId Cookie
protected loadVisitorIdCookie ( ) : boolean
return boolean True if cookie exists and is valid, False otherwise

sendRequest() protected method

protected sendRequest ( $url, $method = 'GET', $data = null, $force = false )

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

setBrowserHasCookies() public method

Sets if the browser supports cookies This is reported in "List of plugins" report in Piwik.
public setBrowserHasCookies ( boolean $bool )
$bool boolean

setBrowserLanguage() public method

Sets the Browser language. Used to guess visitor countries when GeoIP is not enabled
public setBrowserLanguage ( string $acceptLanguage )
$acceptLanguage string For example "fr-fr"

setCity() public method

Allowed only for Admin/Super User, must be used along with setTokenAuth().
public setCity ( string $city )
$city string

setCookie() protected method

This replicates the piwik.js tracker algorithms for consistency and better accuracy.
protected setCookie ( $cookieName, $cookieValue, $cookieTTL )
$cookieName
$cookieValue
$cookieTTL

setCountry() public method

Allowed only for Admin/Super User, must be used along with setTokenAuth().
public setCountry ( string $country )
$country string

setCustomTrackingParameter() public method

Sets a custom tracking parameter. This is useful if you need to send any tracking parameters for a 3rd party plugin that is not shipped with Piwik itself. Please note that custom parameters are cleared after each tracking request.
public setCustomTrackingParameter ( string $trackingApiParameter, string $value )
$trackingApiParameter string The name of the tracking API parameter, eg 'dimension1'
$value string Tracking parameter value that shall be sent for this tracking parameter.

setCustomVariable() public method

See http://piwik.org/docs/custom-variables/
public setCustomVariable ( integer $id, string $name, string $value, string $scope = 'visit' )
$id integer Custom variable slot ID from 1-5
$name string Custom variable name
$value string Custom variable value
$scope string Custom variable scope. Possible values: visit, page, event

setDebugStringAppend() public method

Will append a custom string at the end of the Tracking request.
public setDebugStringAppend ( string $string )
$string string

setEcommerceView() public method

This must be called before doTrackPageView() on this product/category page. It will set 3 custom variables of scope "page" with the SKU, Name and Category for this page view. Note: Custom Variables of scope "page" slots 3, 4 and 5 will be used. On a category page, you may set the parameter $category only and set the other parameters to false. Tracking Product/Category page views will allow Piwik to report on Product & Categories conversion rates (Conversion rate = Ecommerce orders containing this product or category / Visits to the product or category)
public setEcommerceView ( string $sku = '', string $name = '', string | array $category = '', float $price )
$sku string Product SKU being viewed
$name string Product Name being viewed
$category string | array Category being viewed. On a Product page, this is the product's category. You can also specify an array of up to 5 categories for a given page view.
$price float Specify the price at which the item was displayed

setFirstPartyCookies() protected method

Sets the first party cookies as would the piwik.js All cookies are supported: 'id' and 'ses' and 'ref' and 'cvar' cookies.
protected setFirstPartyCookies ( )

setForceNewVisit() public method

By default, Piwik will create a new visit if the last request by this user was more than 30 minutes ago. If you call setForceNewVisit() before calling doTrack*, then a new visit will be created for this request.
public setForceNewVisit ( )

setForceVisitDateTime() public method

By default Piwik will track requests for the "current datetime" but this function allows you to track visits in the past. All times are in UTC. Allowed only for Super User, must be used along with setTokenAuth()
See also: setTokenAuth()
public setForceVisitDateTime ( string $dateTime )
$dateTime string Date with the format 'Y-m-d H:i:s', or a UNIX timestamp

setGenerationTime() public method

Sets the time that generating the document on the server side took.
public setGenerationTime ( integer $timeMs )
$timeMs integer Generation time in ms

setIdSite() public method

Sets the current site ID.
public setIdSite ( integer $idSite )
$idSite integer

setIp() public method

Allowed only for Super User, must be used along with setTokenAuth()
See also: setTokenAuth()
public setIp ( string $ip )
$ip string IP string, eg. 130.54.2.1

setLatitude() public method

Allowed only for Admin/Super User, must be used along with setTokenAuth().
public setLatitude ( float $lat )
$lat float

setLocalTime() public method

Sets local visitor time
public setLocalTime ( string $time )
$time string HH:MM:SS format

setLongitude() public method

Allowed only for Admin/Super User, must be used along with setTokenAuth().
public setLongitude ( float $long )
$long float

setNewVisitorId() public method

Sets the current visitor ID to a random new one.
public setNewVisitorId ( )

setPageCharset() public method

It is recommended to only send UTF-8 data to Piwik. If required though, you can also specify another charset using this function.
public setPageCharset ( string $charset = '' )
$charset string

setPlugins() public method

Sets visitor browser supported plugins
public setPlugins ( boolean $flash = false, boolean $java = false, boolean $director = false, boolean $quickTime = false, boolean $realPlayer = false, boolean $pdf = false, boolean $windowsMedia = false, boolean $gears = false, boolean $silverlight = false )
$flash boolean
$java boolean
$director boolean
$quickTime boolean
$realPlayer boolean
$pdf boolean
$windowsMedia boolean
$gears boolean
$silverlight boolean

setProxy() public method

If a proxy is needed to look up the address of the Piwik site, set it with this
public setProxy ( string $proxy, integer $proxyPort = 80 )
$proxy string IP as string, for example "173.234.92.107"
$proxyPort integer

setRegion() public method

Allowed only for Admin/Super User, must be used along with setTokenAuth().
public setRegion ( string $region )
$region string

setRequestTimeout() public method

Sets the maximum number of seconds that the tracker will spend waiting for a response from Piwik.
public setRequestTimeout ( integer $timeout )
$timeout integer

setResolution() public method

Sets user resolution width and height.
public setResolution ( integer $width, integer $height )
$width integer
$height integer

setTokenAuth() public method

The following features require access: - force the visitor IP - force the date & time of the tracking requests rather than track for the current datetime
public setTokenAuth ( string $token_auth )
$token_auth string token_auth 32 chars token_auth string

setUrl() public method

Sets the current URL being tracked
public setUrl ( string $url )
$url string Raw URL (not URL encoded)

setUrlReferer() public method

Deprecation:
public setUrlReferer ( $url )

setUrlReferrer() public method

Sets the URL referrer used to track Referrers details for new visits.
public setUrlReferrer ( string $url )
$url string Raw URL (not URL encoded)

setUserAgent() public method

If this function is not called, the User Agent will default to the current user agent.
public setUserAgent ( string $userAgent )
$userAgent string

setUserId() public method

A User ID can be a username, UUID or an email address, or any number or string that uniquely identifies a user or client.
public setUserId ( string $userId )
$userId string Any user ID string (eg. email address, ID, username). Must be non empty. Set to false to de-assign a user id previously set.

setVisitorId() public method

Note: it is recommended to use ->setUserId($userId); instead. Rather than letting Piwik attribute the user with a heuristic based on IP and other user fingeprinting attributes, force the action to be recorded for a particular visitor. If you use both setVisitorId and setUserId, setUserId will take precedence. If not set, the visitor ID will be fetched from the 1st party cookie, or will be set to a random UUID.
Deprecation: We recommend to use ->setUserId($userId).
public setVisitorId ( string $visitorId )
$visitorId string 16 hexadecimal characters visitor ID, eg. "33c31e01394bdc63"

Property Details

$DEBUG_APPEND_URL public_oe property

public $DEBUG_APPEND_URL

$DEBUG_LAST_REQUESTED_URL public_oe static_oe property

Used in tests to output useful error messages.
public static $DEBUG_LAST_REQUESTED_URL

$URL public_oe static_oe property

Piwik base URL, for example http://example.org/piwik/ Must be set before using the class by calling PiwikTracker::$URL = 'http://yourwebsite.org/piwik/';
public static string $URL
return string