TheIconic\Tracking\GoogleAnalytics\Analytics::sendHit PHP Method

sendHit() private method

Sends a hit to GA. The hit will contain in the payload all the parameters added before.
private sendHit ( $methodName ) : AnalyticsResponse
$methodName
return AnalyticsResponse
    private function sendHit($methodName)
    {
        $hitType = strtoupper(substr($methodName, 4));
        $hitConstant = $this->getParameterClassConstant('TheIconic\\Tracking\\GoogleAnalytics\\Parameters\\Hit\\HitType::HIT_TYPE_' . $hitType, 'Hit type ' . $hitType . ' is not defined, check spelling');
        $this->setHitType($hitConstant);
        if (!$this->hasMinimumRequiredParameters()) {
            throw new InvalidPayloadDataException();
        }
        return $this->getHttpClient()->post($this->getUrl(), $this->isAsyncRequest);
    }

Usage Example

 /**
  * Override sendHit() so that we can prevent Analytics data from being sent
  *
  * @param $methodName
  * @return AnalyticsResponse
  */
 private function sendHit($methodName)
 {
     if ($this->shouldSendAnalytics) {
         return parent::sendHit($methodName);
     } else {
         return null;
     }
 }