I'm working on the Mxit platform & would like to create and capture some custom variables to store in Google Analytics.
With Mxit portals, it's not the usual communication between browser & web server. It's phone app, mxit server, web server. Mxit sits in the middle, which means we can’t directly capture user specific info.
Mxit does however set custom headers with additional user info, which can be captured for Analytics via custom variables.
We can't make use of javascript, so I’ve installed the Analytics for mobile php script, which creates and appends data to the gif image.
I've set the custom variables on a normal website via javascript and using GA debug I copied the utme parameter and added it to the GA for mobile php code to append to manually append to the gif query string.
Here's a quick, over simplified example:
The custom values I'd like to set.
$id = $headers['mxitID'];
$country = $headers['country'];
$gender = $headers['gender'];
$age = $headers['age'];
and here I'm appending to the gif query string
&utme=8(MxitID*Country*Gender*Age)9($id*$country*$gender*$age)11(1*1*1*1)
The way I understand it, 8() represents the custom variable names, 9() represents the custom variable values and 11() represents the scope.
It's been 2 days now, and there is still no custom variable information in Google Analytics.
I'm checking Visitors > Custom Variables
Any help would be appreciated.
Google has a server-side solution just for this issue. You can find the code here: https://developers.google.com/analytics/devguides/collection/other/mobileWebsites
Here's an implementation of that library
<?php
class GoogleAnalytics {
const ACCOUNT = "ACCOUNT ID GOES HERE";
const PIXEL = "/ga.php";
public static function getImageUrl() {
$url .= self::PIXEL . '?';
$url .= 'utmac=' . self::ACCOUNT;
$url .= '&utmn=' . rand(0, 0x7fffffff);
$referer = !empty($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : '-';
$url .= '&utmr=' . urlencode($referer);
if (!empty($_SERVER["REQUEST_URI"])) {
$url .= "&utmp=" . urlencode($_SERVER["REQUEST_URI"]);
}
$url .= '&guid=ON';
return str_replace('&', '&', $url);
}
}
?>
And then in your view you do:
<img src="<?php echo GoogleAnalytics::getImageUrl() ?>" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With