3

I'm using Google Measurement Protocol to trigger views in GA. I'm wondering how to trigger pageviews from mobile web (not mobile apps).

I've checked documentation and there's no mention of differentiating desktop, mobile or tablet. I assumed it would do this via the user-agent, but the below user-agent is for a Samsung Galaxy S6 Edge, but tracks as desktop.

Is there a device switch I'm missing? Thank you.

$ch = curl_init();

$params =
    ['t' => 'pageview',
    'tid' => 'UA-XXXXXXXX-1',
    'v' => '1',
    'cid' => "9618da12-7db9-0128-8117-2cac0d35e05f",
    'ds' => 'web',
    'dl' => ‘http://www.example.com’,
    'ua' => ‘Mozilla/5.0 (Linux; Android 5.1.1; SM-G928X Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36’,
    'geoid' => ‘US’,
    'dr' => ‘http://www.referingsite.com’,
    'ul' => 'en-us',
    'de' => 'UTF-8',
    'sd' => '24-bit',
    'je' => '0'];

curl_setopt_array($ch, array(
    CURLOPT_URL => 'https://www.google-analytics.com/collect',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => http_build_query($params)
));

curl_exec($ch);
curl_close($ch);
Jon
  • 452
  • 4
  • 23
  • My advice is to build up your request first as a http get so you can test it in a browser window. then send it to the debug endpoint https://www.google-analytics.com/debug/collect?tid=fake&v=1 just to be sure it works. Second make sure its a web google analytics account if you send pageviews to a web account you wont be able to see them. If there is an error in your debug post it and I will have a look. – Linda Lawton - DaImTo Aug 23 '16 at 09:59
  • Hi. Thanks, the hit is received but the problem is it registers as a desktop visit, not mobile – Jon Aug 23 '16 at 10:30
  • I "think" that's set via the useragent. https://developer.chrome.com/multidevice/user-agent but I suspect Google has the power to over write it if it can detect that you are sending it from desktop and you send it from a browser I bet they are going to take the browser. I have never managed to hack that field. – Linda Lawton - DaImTo Aug 23 '16 at 10:36
  • Interesting. The idea of the Measurement Protocol is that they "take your word for it" though, rather than try to infer values. – Jon Aug 23 '16 at 10:44
  • Play with it its what I did see if you can force it to change. I have done that a few times. I could send off an email to find out if its even possible. No guarantee I will get a response from that team though. – Linda Lawton - DaImTo Aug 23 '16 at 10:58
  • Email sent: BTW I just checked an old account which is only getting inserts from the spam bots. It seams all the hits are desktop so I think even they cant figure out how to get it to change – Linda Lawton - DaImTo Aug 23 '16 at 11:05
  • 2
    Google points out that _"Google has libraries to identify real user agents. Hand crafting your own agent could break at any time"_, so even if they try to take your word for it it seems even small errors could throw them off (on the other hand you probably copied that verbatim from a real agent. I really curious how this turns out). – Eike Pierstorff Aug 23 '16 at 11:16
  • Thanks for your reply. Yes it was a copy paste, and I've tried multiple. There could be something wrong in the encoding I suppose but I'm pretty sure there's not. – Jon Aug 23 '16 at 12:51
  • The example in the field reference is url encoded. I really don't see why this would be necessary in a POST request body, but you might still want to try it just the be on the safe side. – Eike Pierstorff Aug 23 '16 at 15:28
  • Hi. I tried encoded and not. No change. I'm at a loss. @DalmTo Did you get a reply? – Jon Aug 25 '16 at 16:53
  • I tagged incorrectly... Hi. I tried encoded and not. No change. I'm at a loss. @DaImTo Did you get a reply? – Jon Aug 26 '16 at 16:58
  • Not a word sorry they don't always get back to me. While Eike is correct about that statement in the UserAgent. I have talked to Google about that and they say its safe enough to use. I am tempted to rip appart the android sdk to see how they send it. – Linda Lawton - DaImTo Aug 29 '16 at 06:07
  • Thanks for trying. And yes if you do, let me know! – Jon Aug 29 '16 at 12:58
  • Just for anyone new arriving, it's 7 months later and no solution. – Jon Mar 06 '17 at 02:37

0 Answers0