Creates a Tracker instance

@param string $siteId
@param string $userAgent
@param string $requestIPAddress
@throws \Exception
@return Tracker
483026
public function create($siteId, $userAgent = '', $requestIPAddress = '')
    {
        if (empty($siteId)) {
            throw new \Exception('Cannot create an instance without a site id');
        }

        $cookie = new Cookie();

        $userId = $cookie->getCookie(CookieNames::USER_ID);
        $userId = ! empty($userId) ? $userId : Uuid::v4();

        $payload = new Payload(new Cookie(), $siteId, $userId);

        $requestHeaders = [];

        $browserUserAgent = !empty($userAgent) ? $userAgent : Browser::getUserAgent();
        $browserIPAddress = !empty($requestIPAddress) ? $requestIPAddress : Browser::getRequestIPAddress();

        if (! empty($browserUserAgent)) {
            $requestHeaders['X-Original-User-Agent'] = $browserUserAgent;
        }

        if (! empty($browserIPAddress)) {
            $requestHeaders['X-Original-Request-IP-Address'] = $browserIPAddress;
        }

        $client = new Client([
            'base_uri' => API::ENDPOINT,
            RequestOptions::HEADERS => $requestHeaders,
            RequestOptions::HTTP_ERRORS => false,
            RequestOptions::VERIFY => false
        ]);

        return new Tracker($cookie, $payload, $client);
    }
547845
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var static $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        // if no id, then it has not been save and can be returned
        if (empty($new->pageId)) {
            return $new;
        }

        $new->pageId = null;
        $new->name = null;
        $new->parent = null;

        return $new;
    }
385715
public function applyConclusiveMatch($userAgent)
    {
        if (WURFL_Configuration_ConfigHolder::getWURFLConfig()->isHighPerformance()) {
            //High performance mode
            $tolerance = WURFL_Handlers_Utils::firstCloseParen($userAgent);
            return $this->getDeviceIDFromRIS($userAgent, $tolerance);
        } else {
            //High accuracy mode
            return $this->getDeviceIDFromLD($userAgent, 5);
        }
    }
690442
public function execute($respTrackData = null, $userId = null)
    {
        $batch     = $this->getBatch();
        $tracker   = $this->loader->getTracker();
        $respTrack = $tracker->getRespondentTrack($respTrackData);

        $i = $batch->addToCounter('checkedRespondentTracks');

        if ($result = $respTrack->checkTrackTokens($userId)) {
            $a = $batch->addToCounter('tokenDateCauses');
            $b = $batch->addToCounter('tokenDateChanges', $result);
            $batch->setMessage('tokenDateChanges',
                    sprintf($this->_('%2$d token date changes in %1$d tracks.'), $a, $b)
                    );
        }

        $batch->setMessage('checkedRespondentTracks', sprintf($this->_('Checked %d tracks.'), $i));
    }
28022
public function getToken($token, $ip = null, $userAgent = null)
    {
        $query = $this->getTokenQuery($token, $ip, $userAgent);

        return $this->findOneWith($query);
    }
301204
public function applyConclusiveMatch($userAgent)
    {
        if (Utils::checkIfStartsWithAnyOf($userAgent, array('SEC-', 'SAMSUNG-', 'SCH'))) {
            $tolerance = Utils::firstSlash($userAgent);
        } else {
            if (Utils::checkIfStartsWithAnyOf($userAgent, array('Samsung', 'SPH', 'SGH'))) {
                $tolerance = Utils::firstSpace($userAgent);
            } else {
                $tolerance = Utils::secondSlash($userAgent);
            }
        }

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
1023917
public function copySiteById(
        $siteId,
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var \Rcm\Entity\Site $site */
        $existingSite = $this->find($siteId);

        if (empty($existingSite)) {
            throw new SiteNotFoundException("Site {$siteId} not found.");
        }

        $site = $existingSite->newInstance(
            $createdByUserId,
            $createdReason
        );

        return $site;
    }
1354156
public function client($userAgent = self::USER_AGENT, $fallbackValue = 0)
    {
        $this->sort();
        return new RequestRateClient($this->base, $userAgent, $this->requestRates, $fallbackValue);
    }
888427
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON,
        $copyPages = true
    ) {
        /** @var static $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        // if no id, then it has not been save and can be returned
        if (empty($new->siteId)) {
            return $new;
        }

        $new->siteId = null;
        $new->domain = null;

        if ($copyPages) {
            /* Get Cloned Pages */
            $pages = $new->getPages();

            $clonedPages = [];

            /** @var \Rcm\Entity\Page $page */
            foreach ($pages as $page) {
                $pageType = $page->getPageType();

                // Only clone if is supported
                if (!isset($new->supportedPageTypes[$pageType])) {
                    continue;
                }
                // Only clone if is cloneable
                if (!$new->supportedPageTypes[$pageType]['canClone']) {
                    continue;
                }

                $clonedPage = $page->newInstanceIfHasRevision(
                    $createdByUserId,
                    $createdReason
                );

                if (!$clonedPage) {
                    continue;
                }

                $clonedPage->setSite($new);

                $clonedPages[] = $clonedPage;
            }

            $new->pages = new ArrayCollection($clonedPages);
        }

        /* Get Cloned Containers */
        $containers = $this->getContainers();
        $clonedContainers = [];

        /** @var \Rcm\Entity\Container $container */
        foreach ($containers as $container) {
            $clonedContainer = $container->newInstanceIfHasRevision(
                $createdByUserId,
                $createdReason
            );

            if (!$clonedContainer) {
                continue;
            }

            $clonedContainer->setSite($new);

            $clonedContainers[] = $clonedContainer;
        }

        $new->containers = new ArrayCollection($clonedContainers);

        return $new;
    }
740186
function UpdateVisit($UserID, $ClientHour = FALSE) {
      $UserID = (int) $UserID;
      if (!$UserID) {
         throw new Exception('A valid User ID is required.');
      }
      
      $User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
      
      $Fields = array();
      
      if (Gdn_Format::ToTimestamp($User['DateLastActive']) < strtotime('5 minutes ago')) {
         // We only update the last active date once every 5 minutes to cut down on DB activity.
         $Fields['DateLastActive'] = Gdn_Format::ToDateTime();
      }
      
      // Update session level information if necessary.
      if ($UserID == Gdn::Session()->UserID) {
         $IP = Gdn::Request()->IpAddress();
         $Fields['LastIPAddress'] = $IP;
         
         if (Gdn::Session()->NewVisit()) {
            $Fields['CountVisits'] = GetValue('CountVisits', $User, 0) + 1;
         }
      }
      
      // Generate the AllIPs field.
      $AllIPs = GetValue('AllIPAddresses', $User, array());
      if (is_string($AllIPs)) {
         $AllIPs = explode(',', $AllIPs);
         SetValue('AllIPAddresses', $User, $AllIPs);
      }
      if (!is_array($AllIPs))
         $AllIPs = array();
      if ($IP = GetValue('InsertIPAddress', $User))
         $AllIPs[] = ForceIPv4($IP);
      if ($IP = GetValue('LastIPAddress', $User))
         $AllIPs[] = $IP;
      $AllIPs = array_unique($AllIPs);
      sort($AllIPs);
      $Fields['AllIPAddresses'] = $AllIPs;

      // Set the hour offset based on the client's clock.
      if (is_numeric($ClientHour) && $ClientHour >= 0 && $ClientHour < 24) {
         $HourOffset = $ClientHour - date('G', time());
         $Fields['HourOffset'] = $HourOffset;
      }
      
      // See if the fields have changed.
      $Set = array();
      foreach ($Fields as $Name => $Value) {
         if (GetValue($Name, $User) != $Value) {
            $Set[$Name] = $Value;
         }
      }
      
      if (!empty($Set)) {
         $this->EventArguments['Fields'] =& $Set;
         $this->FireEvent('UpdateVisit');
         
         $this->SetField($UserID, $Set);
      }
      
      if ($User['LastIPAddress'] != $Fields['LastIPAddress']) {
         $User = $this->GetID($UserID, DATASET_TYPE_ARRAY);
         if (!BanModel::CheckUser($User, NULL, TRUE, $Bans)) {
            $BanModel = new BanModel();
            $Ban = array_pop($Bans);
            $BanModel->SaveUser($User, TRUE, $Ban);
            $BanModel->SetCounts($Ban);
         }
      }
   }
427679
public function applyConclusiveMatch($userAgent)
    {
        $tolerance = Utils::toleranceToRisDelimeter($userAgent);
        if ($tolerance !== false) {
            return $this->getDeviceIDFromRIS($userAgent, $tolerance);
        }

        return WurflConstants::NO_MATCH;
    }
639867
public function applyConclusiveMatch($userAgent)
    {
        if (Utils::checkIfContains($userAgent, 'GoogleImageProxy')) {
            return 'google_image_proxy';
        }

        if (Utils::checkIfStartsWith($userAgent, 'Mozilla')) {
            $tolerance = Utils::firstCloseParen($userAgent);
        } else {
            $tolerance = Utils::firstSlash($userAgent);
        }

        return $this->getDeviceIDFromRIS($userAgent, $tolerance);
    }
1189022
public function getDeviceForUserAgent($userAgent)
    {
        if (!isset($userAgent)) {
            $userAgent = '';
        }
        
        $request = $this->_requestFactory->createRequestForUserAgent($userAgent);
        return $this->getDeviceForRequest($request);
    }
298321
public function isDesktop($userAgent = null, $httpHeaders = null)
    {
        return !$this->isMobile($userAgent, $httpHeaders) && !$this->isTablet($userAgent, $httpHeaders) && !$this->isRobot($userAgent);
    }
947141
public static function detect(Device $device, UserAgent $userAgent)
    {
        $device->setName($device::UNKNOWN);

        /*iphone，ipad，windowphone*/
        $flag = self::checkIpad($device, $userAgent) ||self::checkIphone($device, $userAgent) || self::checkWindowsPhone($device, $userAgent);
        if( $flag ){
        	return true;
		}
        /*android*/
		if (stripos($userAgent->getUserAgentString(), 'android') !== false) {
			$device->setName(Device::Android);
			foreach (self::$androidList as $androidName ) {
				$funcName = 'check'. $androidName;
				if ( self::$funcName( $device, $userAgent ) ) {
					return true;
				}
			}
		}

		return false;

    }
482067
private function createRateLimitData($applicationId, $userId)
	{
		// data needed to create record
		$ipAddress    = \Request::ip();
		$countShort   = 0;
		$countLong    = 0;
		$limitShort   = $this->config['short']['limit'];
		$limitLong    = $this->config['long']['limit'];
		$created      = with(new Date('now'))->toSql();
		$expiresShort = $this->getNewExpiresDateString('short');
		$expiresLong  = $this->getNewExpiresDateString('long');

		// create initial limit record
		return $this->storage->createRateLimitData(
			$applicationId,
			$userId,
			$ipAddress,
			$limitShort,
			$limitLong,
			$countShort,
			$countLong,
			$expiresShort,
			$expiresLong,
			$created
		);
	}
1010870
public function createNewSite(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON,
        $siteId = null
    ) {
        if (empty($siteId)) {
            // new site
            /** @var \Rcm\Entity\Site $newSite */
            return new \Rcm\Entity\Site(
                $createdByUserId,
                $createdReason
            );
        }

        return $this->copySiteById(
            $siteId,
            $createdByUserId,
            $createdReason
        );
    }