Mobile app version of vmapp.org
Login or Join
Kevin317

: Google Analytics stopped registering hits 10 minutes after implementing measurement protocol I'm trying to implement google analytics on server-side. In order to (loosely) identify visitors, I'm generating

@Kevin317

Posted in: #GoogleAnalytics #HttpHeaders #Tracking

I'm trying to implement google analytics on server-side. In order to (loosely) identify visitors, I'm generating an md5 based on IP and user-agent and send the result to Google for tracking the pageview. This is the code I'm using:

function send_google_hits() {
$uri = $_SERVER['REQUEST_URI'];
$parts = explode('/', $uri);
$slug = implode('/', array_slice($parts, 0, 3)) . '/';
$ref = $_SERVER['HTTP_REFERER'];
$usr = $_SERVER['REMOTE_ADDR'] . ' ' . $_SERVER['HTTP_USER_AGENT'];
$usr = md5($usr);
$title = "Hit from server";
$data = array(
'v' => 1,
'tid' => '[UA-XXXXXXXX-X]',
'cid' => $usr,
't' => 'pageview',
'dh' => '[example.com]',
'dp' => $slug,
'dt' => $title,
);
wp_remote_post(
'https://ssl.google-analytics.com/collect',
array( 'body' => $data )
);
}


The set-up worked fine for about 10 minutes, but after that Google Analytics stopped displaying hits in the real-time view. There are two reasons I can think of - either there's some tight rate limiting policy on hits that I can send this way or there's some policy issue that I may be in breach of.

I don't have user-id enabled in my property, as I'm not sure if it applies to what I'm doing (I'm not trying to track users across devices). But if this were the case, I'd expect it didn't work in the first place.

Any idea on how to get this working?

10% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin317

0 Comments

Sorted by latest first Latest Oldest Best

Back to top | Use Dark Theme