コード例 #1
0
 /**
  * @param TrackingEvent $trackingEvent
  * @param array         $decodedData
  *
  * @return TrackingVisit
  */
 protected function getTrackingVisit(TrackingEvent $trackingEvent, $decodedData)
 {
     $visitorUid = $decodedData['_id'];
     $userIdentifier = $trackingEvent->getUserIdentifier();
     $hash = md5($visitorUid . $userIdentifier);
     // try to find existing visit
     if (!empty($this->collectedVisits) && array_key_exists($hash, $this->collectedVisits)) {
         $visit = $this->collectedVisits[$hash];
     } else {
         $visit = $this->doctrine->getRepository(self::TRACKING_VISIT_ENTITY)->findOneBy(['visitorUid' => $visitorUid, 'userIdentifier' => $trackingEvent->getUserIdentifier(), 'trackingWebsite' => $trackingEvent->getWebsite()]);
     }
     if (!$visit) {
         $visit = new TrackingVisit();
         $visit->setParsedUID(0);
         $visit->setParsingCount(0);
         $visit->setUserIdentifier($trackingEvent->getUserIdentifier());
         $visit->setVisitorUid($visitorUid);
         $visit->setFirstActionTime($trackingEvent->getCreatedAt());
         $visit->setLastActionTime($trackingEvent->getCreatedAt());
         $visit->setTrackingWebsite($trackingEvent->getWebsite());
         $visit->setIdentifierDetected(false);
         if (!empty($decodedData['cip'])) {
             $visit->setIp($decodedData['cip']);
         }
         if (!empty($decodedData['ua'])) {
             $this->processUserAgentString($visit, $decodedData['ua']);
         }
         $this->identifyTrackingVisit($visit);
         $this->collectedVisits[$hash] = $visit;
     } else {
         if ($visit->getFirstActionTime() > $trackingEvent->getCreatedAt()) {
             $visit->setFirstActionTime($trackingEvent->getCreatedAt());
         }
         if ($visit->getLastActionTime() < $trackingEvent->getCreatedAt()) {
             $visit->setLastActionTime($trackingEvent->getCreatedAt());
         }
     }
     return $visit;
 }
コード例 #2
0
 public function testIdentify()
 {
     $visit = new TrackingVisit();
     $visit->setUserIdentifier('id=118; email=test@test.com; visitor-id=89');
     $channel = new Channel();
     $website = new TestTrackingWebsite();
     $website->setChannel($channel);
     $visit->setTrackingWebsite($website);
     $result = new \stdClass();
     $repo = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->once())->method('getRepository')->willReturn($repo);
     $repo->expects($this->once())->method('findOneBy')->with(['originId' => 118, 'dataChannel' => $channel])->willReturn($result);
     $this->assertEquals(['parsedUID' => 118, 'targetObject' => $result], $this->provider->identify($visit));
 }