Class PiwikTracker

Description
Variable Summary
 static string $URL
Method Summary
 PiwikTracker __construct (int $idSite, [string $apiUrl = false])
 void addEcommerceItem (string $sku, [string $name = false], [string|array $category = false], [float|int $price = false], [int $quantity = false])
 string doTrackAction (string $actionUrl, string $actionType)
 void doTrackEcommerceCartUpdate (float $grandTotal)
 void doTrackEcommerceOrder (string|int $orderId, float $grandTotal, [float $subTotal = false], [float $tax = false], [float $shipping = false], [float $discount = false])
 string doTrackGoal (int $idGoal, [int $revenue = false])
 string doTrackPageView (string $documentTitle)
 string getAttributionInfo ()
 array|false getCustomVariable (int $id, [string $scope = 'visit'])
 string|int getTimestamp ()
 string getUrlTrackAction (string $actionUrl, string $actionType)
 string getUrlTrackGoal (int $idGoal, [int $revenue = false])
 string getUrlTrackPageView ([string $documentTitle = false])
 string getVisitorId ()
 void setAttributionInfo (string $jsonEncoded)
 void setBrowserHasCookies (bool $bool)
 void setBrowserLanguage (string $acceptLanguage)
 void setCustomVariable (int $id, string $name, string $value, [string $scope = 'visit'])
 void setDebugStringAppend (string $string)
 void setEcommerceView ([string $sku = false], [string $name = false], [string|array $category = false], [float $price = false])
 void setForceVisitDateTime (string $dateTime)
 void setIp (string $ip)
 void setLocalTime (string $time)
 void setPlugins ([bool $flash = false], [bool $java = false], [bool $director = false], [bool $quickTime = false], [bool $realPlayer = false], [bool $pdf = false], [bool $windowsMedia = false], [bool $gears = false], [bool $silverlight = false])
 void setResolution (int $width, int $height)
 void setTokenAuth (string $token_auth)
 void setUrl (string $url)
 void setUrlReferrer (string $url)
 void setUserAgent (string $userAgent)
 void setVisitorId (string $visitorId)
Variables
static string $URL = '' (line 33)

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

  • access: public
Methods
Constructor __construct (line 63)

Builds a PiwikTracker object, used to track visits, pages and Goal conversions for a specific website, by using the Piwik Tracking API.

PiwikTracker __construct (int $idSite, [string $apiUrl = false])
  • int $idSite: Id site to be tracked
  • string $apiUrl: "http://example.org/piwik/" or "http://piwik.example.org/" If set, will overwrite PiwikTracker::$URL
addEcommerceItem (line 298)

Adds an item in the Ecommerce order.

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.

  • access: public
void addEcommerceItem (string $sku, [string $name = false], [string|array $category = false], [float|int $price = false], [int $quantity = false])
  • string $sku: (required) SKU, Product identifier
  • string $name: (optional) Product name
  • string|array $category: (optional) Product category, or array of product categories (up to 5 categories can be specified for a given product)
  • float|int $price: (optional) Individual product price (supports integer and decimal prices)
  • int $quantity: (optional) Product quantity. If not specified, will default to 1 in the Reports
disableCookieSupport (line 702)

By default, PiwikTracker will read third party cookies from the response and sets them in the next request.

This can be disabled by calling this function.

  • access: public
void disableCookieSupport ()
doTrackAction (line 277)

Tracks a download or outlink

  • return: Response
  • access: public
string doTrackAction (string $actionUrl, string $actionType)
  • string $actionUrl: URL of the download or outlink
  • string $actionType: Type of the action: 'download' or 'link'
doTrackEcommerceCartUpdate (line 316)

Tracks a Cart Update (add item, remove item, update item).

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).

  • access: public
void doTrackEcommerceCartUpdate (float $grandTotal)
  • float $grandTotal: Cart grandTotal (typically the sum of all items' prices)
doTrackEcommerceOrder (line 338)

Tracks an Ecommerce order.

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.

  • access: public
void doTrackEcommerceOrder (string|int $orderId, float $grandTotal, [float $subTotal = false], [float $tax = false], [float $shipping = false], [float $discount = false])
  • string|int $orderId: (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.
  • float $grandTotal: (required) Grand Total revenue of the transaction (including tax, shipping, etc.)
  • float $subTotal: (optional) Sub total amount, typically the sum of items prices for all items in this order (before Tax and Shipping costs are applied)
  • float $tax: (optional) Tax amount for this order
  • float $shipping: (optional) Shipping amount for this order
  • float $discount: (optional) Discounted amount in this order
doTrackGoal (line 264)

Records a Goal conversion

  • return: Response
  • access: public
string doTrackGoal (int $idGoal, [int $revenue = false])
  • int $idGoal: Id Goal to record a conversion
  • int $revenue: Revenue for this conversion
doTrackPageView (line 251)

Tracks a page view

  • return: Response
  • access: public
string doTrackPageView (string $documentTitle)
  • string $documentTitle: Page title as it will appear in the Actions > Page titles report
getAttributionInfo (line 600)

Returns the currently assigned Attribution Information stored in a first party cookie.

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.

  • return: JSON Encoded string containing the Referer information for Goal conversion attribution. Will return false if the cookie could not be found
  • see: Piwik.js getAttributionInfo()
  • access: public
string getAttributionInfo ()
getCustomVariable (line 185)

Returns the currently assigned Custom Variable stored in a first party cookie.

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.

  • return: An array with this format: array( 0 => CustomVariableName, 1 => CustomVariableValue )
  • see: Piwik.js getCustomVariable()
  • access: public
array|false getCustomVariable (int $id, [string $scope = 'visit'])
  • int $id: Custom Variable integer index to fetch from cookie. Should be a value from 1 to 5
  • string $scope: Custom variable scope. Possible values: visit, page
getTimestamp (line 783)

Returns current timestamp, or forced timestamp/datetime if it was set

  • access: protected
string|int getTimestamp ()
getUrlTrackAction (line 506)
string getUrlTrackAction (string $actionUrl, string $actionType)
  • string $actionUrl: URL of the download or outlink
  • string $actionType: Type of the action: 'download' or 'link'
getUrlTrackGoal (line 490)
string getUrlTrackGoal (int $idGoal, [int $revenue = false])
  • int $idGoal: Id Goal to record a conversion
  • int $revenue: Revenue for this conversion
getUrlTrackPageView (line 475)
string getUrlTrackPageView ([string $documentTitle = false])
  • string $documentTitle: Page view name as it will appear in Piwik reports
getVisitorId (line 570)

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).

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.

  • return: 16 hex chars visitor ID string
  • access: public
string getVisitorId ()
setAttributionInfo (line 134)

Sets the attribution information to the visit, so that subsequent Goal conversions are properly attributed to the right Referrer URL, timestamp, Campaign Name & Keyword.

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()

void setAttributionInfo (string $jsonEncoded)
  • string $jsonEncoded: JSON encoded array containing Attribution info
setBrowserHasCookies (line 653)

Sets if the browser supports cookies This is reported in "List of plugins" report in Piwik.

  • access: public
void setBrowserHasCookies (bool $bool)
  • bool $bool
setBrowserLanguage (line 228)

Sets the Browser language. Used to guess visitor countries when GeoIP is not enabled

  • access: public
void setBrowserLanguage (string $acceptLanguage)
  • string $acceptLanguage: For example "fr-fr"
setCustomVariable (line 153)

Sets Visit Custom Variable.

See http://piwik.org/docs/custom-variables/

  • access: public
void setCustomVariable (int $id, string $name, string $value, [string $scope = 'visit'])
  • int $id: Custom variable slot ID from 1-5
  • string $name: Custom variable name
  • string $value: Custom variable value
  • string $scope: Custom variable scope. Possible values: visit, page
setDebugStringAppend (line 662)

Will append a custom string at the end of the Tracking request.

  • access: public
void setDebugStringAppend (string $string)
  • string $string
setEcommerceView (line 362)

Sets the current page view as an item (product) page view, or an Ecommerce Category page view.

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)

  • access: public
void setEcommerceView ([string $sku = false], [string $name = false], [string|array $category = false], [float $price = false])
  • string $sku: Product SKU being viewed
  • string $name: Product Name being viewed
  • string|array $category: 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.
  • float $price: Specify the price at which the item was displayed
setForceVisitDateTime (line 522)

Overrides server date and time for the tracking requests.

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()

void setForceVisitDateTime (string $dateTime)
  • string $dateTime: Date with the format 'Y-m-d H:i:s', or a UNIX timestamp
setIp (line 534)

Overrides IP address

Allowed only for Super User, must be used along with setTokenAuth()

void setIp (string $ip)
  • string $ip: IP string, eg. 130.54.2.1
setLocalTime (line 627)

Sets local visitor time

  • access: public
void setLocalTime (string $time)
  • string $time: HH:MM:SS format
setPlugins (line 680)

Sets visitor browser supported plugins

  • access: public
void setPlugins ([bool $flash = false], [bool $java = false], [bool $director = false], [bool $quickTime = false], [bool $realPlayer = false], [bool $pdf = false], [bool $windowsMedia = false], [bool $gears = false], [bool $silverlight = false])
  • bool $flash
  • bool $java
  • bool $director
  • bool $quickTime
  • bool $realPlayer
  • bool $pdf
  • bool $windowsMedia
  • bool $gears
  • bool $silverlight
setResolution (line 641)

Sets user resolution width and height.

  • access: public
void setResolution (int $width, int $height)
  • int $width
  • int $height
setTokenAuth (line 617)

Some Tracking API functionnality requires express authentication, using either the Super User token_auth, or a user with 'admin' access to the website.

The following features require access:

  • force the visitor IP
  • force the date & time of the tracking requests rather than track for the current datetime
  • force Piwik to track the requests to a specific VisitorId rather than use the standard visitor matching heuristic

  • access: public
void setTokenAuth (string $token_auth)
  • string $token_auth: token_auth 32 chars token_auth string
setUrl (line 100)

Sets the current URL being tracked

  • access: public
void setUrl (string $url)
  • string $url: Raw URL (not URL encoded)
setUrlReferrer (line 110)

Sets the URL referrer used to track Referrers details for new visits.

  • access: public
void setUrlReferrer (string $url)
  • string $url: Raw URL (not URL encoded)
setUserAgent (line 239)

Sets the user agent, used to detect OS and browser.

If this function is not called, the User Agent will default to the current user agent.

  • access: public
void setUserAgent (string $userAgent)
  • string $userAgent
setVisitorId (line 549)

Forces the requests to be recorded for the specified Visitor ID rather than using the heuristics based on IP and other attributes.

This is typically used with the Javascript getVisitorId() function.

Allowed only for Super User, must be used along with setTokenAuth().

void setVisitorId (string $visitorId)
  • string $visitorId: 16 hexadecimal characters visitor ID, eg. "33c31e01394bdc63"

Documentation generated on Tue, 15 May 2012 17:24:07 -0400 by phpDocumentor 1.4.3