hashStringToInt() public static method

Hashes a string into an integer which should be very low collision risks
public static hashStringToInt ( string $string ) : integer
$string string String to hash
return integer Resulting int hash
Ejemplo n.º 1
0
 /**
  * Records an Ecommerce conversion in the DB. Deals with Items found in the request.
  * Will deal with 2 types of conversions: Ecommerce Order and Ecommerce Cart update (Add to cart, Update Cart etc).
  *
  * @param array $conversion
  * @param array $visitInformation
  */
 protected function recordEcommerceGoal($conversion, $visitInformation)
 {
     if ($this->isThereExistingCartInVisit) {
         Common::printDebug("There is an existing cart for this visit");
     }
     if ($this->isGoalAnOrder) {
         $conversion['idgoal'] = self::IDGOAL_ORDER;
         $conversion['idorder'] = $this->orderId;
         $conversion['buster'] = Common::hashStringToInt($this->orderId);
         $conversion['revenue_subtotal'] = $this->getRevenue($this->request->getParam('ec_st'));
         $conversion['revenue_tax'] = $this->getRevenue($this->request->getParam('ec_tx'));
         $conversion['revenue_shipping'] = $this->getRevenue($this->request->getParam('ec_sh'));
         $conversion['revenue_discount'] = $this->getRevenue($this->request->getParam('ec_dt'));
         $debugMessage = 'The conversion is an Ecommerce order';
     } else {
         $conversion['buster'] = 0;
         $conversion['idgoal'] = self::IDGOAL_CART;
         $debugMessage = 'The conversion is an Ecommerce Cart Update';
     }
     $conversion['revenue'] = $this->getRevenue($this->request->getGoalRevenue($defaultRevenue = 0));
     Common::printDebug($debugMessage . ':' . var_export($conversion, true));
     // INSERT or Sync items in the Cart / Order for this visit & order
     $items = $this->getEcommerceItemsFromRequest();
     if ($items === false) {
         return;
     }
     $itemsCount = 0;
     foreach ($items as $item) {
         $itemsCount += $item[self::INTERNAL_ITEM_QUANTITY];
     }
     $conversion['items'] = $itemsCount;
     if ($this->isThereExistingCartInVisit) {
         $updateWhere = array('idvisit' => $visitInformation['idvisit'], 'idgoal' => self::IDGOAL_CART, 'buster' => 0);
         $recorded = $this->updateExistingConversion($conversion, $updateWhere);
     } else {
         $recorded = $this->insertNewConversion($conversion, $visitInformation);
     }
     if ($recorded) {
         $this->recordEcommerceItems($conversion, $items, $visitInformation);
     }
     /**
      * Triggered after successfully persisting an ecommerce conversion.
      * 
      * _Note: Subscribers should be wary of doing any expensive computation here as it may slow
      * the tracker down._
      * 
      * @param array $conversion The conversion entity that was just persisted. See what information
      *                          it contains [here](/guides/persistence-and-the-mysql-backend#conversions).
      * @param array $visitInformation The visit entity that we are tracking a conversion for. See what
      *                                information it contains [here](/guides/persistence-and-the-mysql-backend#visits).
      */
     Piwik::postEvent('Tracker.recordEcommerceGoal', array($conversion, $visitInformation));
 }
Ejemplo n.º 2
0
 /**
  * Records an Ecommerce conversion in the DB. Deals with Items found in the request.
  * Will deal with 2 types of conversions: Ecommerce Order and Ecommerce Cart update (Add to cart, Update Cart etc).
  *
  * @param array $conversion
  * @param Visitor $visitor
  * @param Action $action
  * @param array $visitInformation
  */
 protected function recordEcommerceGoal($conversion, Visitor $visitor, $action, $visitInformation)
 {
     if ($this->isThereExistingCartInVisit) {
         Common::printDebug("There is an existing cart for this visit");
     }
     if ($this->isGoalAnOrder) {
         $debugMessage = 'The conversion is an Ecommerce order';
         $conversion['idorder'] = $this->orderId;
         $conversion['idgoal'] = self::IDGOAL_ORDER;
         $conversion['buster'] = Common::hashStringToInt($this->orderId);
         $conversionDimensions = ConversionDimension::getAllDimensions();
         $conversion = $this->triggerHookOnDimensions($conversionDimensions, 'onEcommerceOrderConversion', $visitor, $action, $conversion);
     } else {
         $debugMessage = 'The conversion is an Ecommerce Cart Update';
         $conversion['buster'] = 0;
         $conversion['idgoal'] = self::IDGOAL_CART;
         $conversionDimensions = ConversionDimension::getAllDimensions();
         $conversion = $this->triggerHookOnDimensions($conversionDimensions, 'onEcommerceCartUpdateConversion', $visitor, $action, $conversion);
     }
     Common::printDebug($debugMessage . ':' . var_export($conversion, true));
     // INSERT or Sync items in the Cart / Order for this visit & order
     $items = $this->getEcommerceItemsFromRequest();
     if (false === $items) {
         return;
     }
     $itemsCount = 0;
     foreach ($items as $item) {
         $itemsCount += $item[GoalManager::INTERNAL_ITEM_QUANTITY];
     }
     $conversion['items'] = $itemsCount;
     if ($this->isThereExistingCartInVisit) {
         $recorded = $this->getModel()->updateConversion($visitInformation['idvisit'], self::IDGOAL_CART, $conversion);
     } else {
         $recorded = $this->insertNewConversion($conversion, $visitInformation);
     }
     if ($recorded) {
         $this->recordEcommerceItems($conversion, $items, $visitInformation);
     }
     /**
      * Triggered after successfully persisting an ecommerce conversion.
      *
      * _Note: Subscribers should be wary of doing any expensive computation here as it may slow
      * the tracker down._
      *
      * @param array $conversion The conversion entity that was just persisted. See what information
      *                          it contains [here](/guides/persistence-and-the-mysql-backend#conversions).
      * @param array $visitInformation The visit entity that we are tracking a conversion for. See what
      *                                information it contains [here](/guides/persistence-and-the-mysql-backend#visits).
      */
     Piwik::postEvent('Tracker.recordEcommerceGoal', array($conversion, $visitInformation));
 }
Ejemplo n.º 3
0
 /**
  * Records an Ecommerce conversion in the DB. Deals with Items found in the request.
  * Will deal with 2 types of conversions: Ecommerce Order and Ecommerce Cart update (Add to cart, Update Cart etc).
  *
  * @param array $conversion
  * @param Visitor $visitor
  * @param Action $action
  * @param array $visitInformation
  */
 protected function recordEcommerceGoal(VisitProperties $visitProperties, Request $request, $conversion, $action)
 {
     $isThereExistingCartInVisit = $request->getMetadata('Goals', 'isThereExistingCartInVisit');
     if ($isThereExistingCartInVisit) {
         Common::printDebug("There is an existing cart for this visit");
     }
     $visitor = Visitor::makeFromVisitProperties($visitProperties, $request);
     $isGoalAnOrder = $request->getMetadata('Ecommerce', 'isGoalAnOrder');
     if ($isGoalAnOrder) {
         $debugMessage = 'The conversion is an Ecommerce order';
         $orderId = $request->getParam('ec_id');
         $conversion['idorder'] = $orderId;
         $conversion['idgoal'] = self::IDGOAL_ORDER;
         $conversion['buster'] = Common::hashStringToInt($orderId);
         $conversionDimensions = ConversionDimension::getAllDimensions();
         $conversion = $this->triggerHookOnDimensions($request, $conversionDimensions, 'onEcommerceOrderConversion', $visitor, $action, $conversion);
     } else {
         $debugMessage = 'The conversion is an Ecommerce Cart Update';
         $conversion['buster'] = 0;
         $conversion['idgoal'] = self::IDGOAL_CART;
         $conversionDimensions = ConversionDimension::getAllDimensions();
         $conversion = $this->triggerHookOnDimensions($request, $conversionDimensions, 'onEcommerceCartUpdateConversion', $visitor, $action, $conversion);
     }
     Common::printDebug($debugMessage . ':' . var_export($conversion, true));
     // INSERT or Sync items in the Cart / Order for this visit & order
     $items = $this->getEcommerceItemsFromRequest($request);
     if (false === $items) {
         return;
     }
     $itemsCount = 0;
     foreach ($items as $item) {
         $itemsCount += $item[GoalManager::INTERNAL_ITEM_QUANTITY];
     }
     $conversion['items'] = $itemsCount;
     if ($isThereExistingCartInVisit) {
         $recorded = $this->getModel()->updateConversion($visitProperties->getProperty('idvisit'), self::IDGOAL_CART, $conversion);
     } else {
         $recorded = $this->insertNewConversion($conversion, $visitProperties->getProperties(), $request);
     }
     if ($recorded) {
         $this->recordEcommerceItems($conversion, $items);
     }
 }