Piwik\Tracker\Request::getIdSite PHP Method

getIdSite() public method

public getIdSite ( )
    public function getIdSite()
    {
        if (isset($this->idSiteCache)) {
            return $this->idSiteCache;
        }
        $idSite = Common::getRequestVar('idsite', 0, 'int', $this->params);
        /**
         * Triggered when obtaining the ID of the site we are tracking a visit for.
         *
         * This event can be used to change the site ID so data is tracked for a different
         * website.
         *
         * @param int &$idSite Initialized to the value of the **idsite** query parameter. If a
         *                     subscriber sets this variable, the value it uses must be greater
         *                     than 0.
         * @param array $params The entire array of request parameters in the current tracking
         *                      request.
         */
        Piwik::postEvent('Tracker.Request.getIdSite', array(&$idSite, $this->params));
        if ($idSite <= 0) {
            throw new UnexpectedWebsiteFoundException('Invalid idSite: \'' . $idSite . '\'');
        }
        $this->idSiteCache = $idSite;
        return $idSite;
    }

Usage Example

Example #1
0
 /**
  * Records in the DB the association between the visit and this action.
  *
  * @param int $idReferrerActionUrl is the ID of the last action done by the current visit.
  * @param $idReferrerActionName
  * @param Visitor $visitor
  */
 public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName)
 {
     $this->loadIdsFromLogActionTable();
     $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName);
     /** @var ActionDimension[] $dimensions */
     $dimensions = ActionDimension::getAllDimensions();
     foreach ($dimensions as $dimension) {
         $value = $dimension->onNewAction($this->request, $visitor, $this);
         if ($value !== false) {
             if (is_float($value)) {
                 $value = Common::forceDotAsSeparatorForDecimalPoint($value);
             }
             $visitAction[$dimension->getColumnName()] = $value;
         }
     }
     // idaction_name is NULLable. we only set it when applicable
     if ($this->isActionHasActionName()) {
         $visitAction['idaction_name'] = (int) $this->getIdActionName();
     }
     foreach ($this->actionIdsCached as $field => $idAction) {
         $visitAction[$field] = $idAction === false ? 0 : $idAction;
     }
     $customValue = $this->getCustomFloatValue();
     if (!empty($customValue)) {
         $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue);
     }
     $visitAction = array_merge($visitAction, $this->customFields);
     $this->idLinkVisitAction = $this->getModel()->createAction($visitAction);
     $visitAction['idlink_va'] = $this->idLinkVisitAction;
     Common::printDebug("Inserted new action:");
     $visitActionDebug = $visitAction;
     $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']);
     Common::printDebug($visitActionDebug);
 }
All Usage Examples Of Piwik\Tracker\Request::getIdSite