/** * Builds a PiwikTracker object, used to track visits, pages and Goal conversions * for a specific website, by using the Piwik Tracking API. * * @param int $idSite Id site to be tracked * @param string $apiUrl "http://example.org/piwik/" or "http://piwik.example.org/" * If set, will overwrite PiwikTracker::$URL */ function __construct($idSite, $apiUrl = false) { $this->cookieSupport = true; $this->userAgent = false; $this->localHour = false; $this->localMinute = false; $this->localSecond = false; $this->hasCookies = false; $this->plugins = false; $this->visitorCustomVar = false; $this->pageCustomVar = false; $this->customData = false; $this->forcedDatetime = false; $this->token_auth = false; $this->attributionInfo = false; $this->ecommerceLastOrderTimestamp = false; $this->ecommerceItems = array(); $this->requestCookie = ''; $this->idSite = $idSite; $this->urlReferrer = @$_SERVER['HTTP_REFERER']; $this->pageUrl = self::getCurrentUrl(); $this->ip = @$_SERVER['REMOTE_ADDR']; $this->acceptLanguage = @$_SERVER['HTTP_ACCEPT_LANGUAGE']; $this->userAgent = @$_SERVER['HTTP_USER_AGENT']; if (!empty($apiUrl)) { self::$URL = $apiUrl; } $this->visitorId = substr(md5(uniqid(rand(), true)), 0, self::LENGTH_VISITOR_ID); }
public function addEcommerceItem($sku, $name = false, $category = false, $price = false, $quantity = false) { // Alter price / qty in case an item with the same SKU is already in the cart if (!empty($sku) && isset($this->ecommerceItems[$sku])) { $old = $this->ecommerceItems[$sku]; $price = ($old[3] * $old[4] + $price * $quantity) / ($old[4] + $quantity); $quantity += $old[4]; } parent::addEcommerceItem($sku, $name, $category, $price, $quantity); }