Beispiel #1
0
 /**
  * Generates a unique user ID from the current user-specific properties.
  * 
  * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#563
  * @return int
  */
 protected function generateUniqueId()
 {
     // There seems to be an error in the gaforflash code, so we take the formula
     // from http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 711
     // instead ("&" instead of "*")
     return (Util::generate32bitRandom() ^ $this->generateHash()) & 0x7fffffff;
 }
Beispiel #2
0
 public function validate()
 {
     // According to the GA documentation, there is a limit to the combined size of
     // name and value of 64 bytes after URL encoding,
     // see http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html#varTypes
     // and http://xahlee.org/js/google_analytics_tracker_2010-07-01_expanded.js line 563
     if (strlen(Util::encodeUriComponent($this->name . $this->value)) > 64) {
         Tracker::_raiseError('Custom Variable combined name and value encoded length must not be larger than 64 bytes.', __METHOD__);
     }
 }
Beispiel #3
0
 /**
  * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/core/DocumentInfo.as#52
  * @return int
  */
 protected function generateSessionId()
 {
     // TODO: Integrate AdSense support
     return Util::generate32bitRandom();
 }
Beispiel #4
0
 /**
  * @link http://code.google.com/p/gaforflash/source/browse/trunk/src/com/google/analytics/v4/Tracker.as#585
  * @return string
  */
 protected function generateDomainHash()
 {
     $hash = 1;
     if ($this->tracker->getAllowHash()) {
         $hash = Util::generateHash($this->tracker->getDomainName());
     }
     return $hash;
 }
Beispiel #5
0
 /**
  * @return string
  */
 protected function buildHttpRequest()
 {
     $parameters = $this->buildParameters();
     // This constant is supported as the 4th argument of http_build_query()
     // from PHP 5.3.6 on and will tell it to use rawurlencode() instead of urlencode()
     // internally, see http://code.google.com/p/php-ga/issues/detail?id=3
     if (defined('PHP_QUERY_RFC3986')) {
         // http_build_query() does automatically skip all array entries
         // with null values, exactly what we want here
         $queryString = http_build_query($parameters->toArray(), '', '&', PHP_QUERY_RFC3986);
     } else {
         // Manually replace "+"s with "%20" for backwards-compatibility
         $queryString = str_replace('+', '%20', http_build_query($parameters->toArray(), '', '&'));
     }
     // Mimic Javascript's encodeURIComponent() encoding for the query
     // string just to be sure we are 100% consistent with GA's Javascript client
     $queryString = Util::convertToUriComponentEncoding($queryString);
     // Recent versions of ga.js use HTTP POST requests if the query string is too long
     $usePost = strlen($queryString) > 2036;
     if (!$usePost) {
         $r = 'GET ' . $this->config->getEndpointPath() . '?' . $queryString . ' HTTP/1.0' . "\r\n";
     } else {
         // FIXME: The "/p" shouldn't be hardcoded here, instead we need a GET and a POST endpoint...
         $r = 'POST /p' . $this->config->getEndpointPath() . ' HTTP/1.0' . "\r\n";
     }
     $r .= 'Host: ' . $this->config->getEndpointHost() . "\r\n";
     if ($this->userAgent) {
         $r .= 'User-Agent: ' . str_replace(array("\n", "\r"), '', $this->userAgent) . "\r\n";
     }
     if ($this->xForwardedFor) {
         // Sadly "X-Fowarded-For" is not supported by GA so far,
         // see e.g. http://www.google.com/support/forum/p/Google+Analytics/thread?tid=017691c9e71d4b24,
         // but we include it nonetheless for the pure sake of correctness (and hope)
         $r .= 'X-Forwarded-For: ' . str_replace(array("\n", "\r"), '', $this->xForwardedFor) . "\r\n";
     }
     if ($usePost) {
         // Don't ask me why "text/plain", but ga.js says so :)
         $r .= 'Content-Type: text/plain' . "\r\n";
         $r .= 'Content-Length: ' . strlen($queryString) . "\r\n";
     }
     $r .= 'Connection: close' . "\r\n";
     $r .= "\r\n\r\n";
     if ($usePost) {
         $r .= $queryString;
     }
     return $r;
 }