1

Is it possible to implement User ID tracking with the php-ga API library? I'd like to tie it in with our client-side tracking.

php-ga library - https://github.com/thomasbachem/php-ga

User ID - Web Tracking (via analytics.js) - https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id

Thanks

4
  • As far as I know only Universal Analytics supports this. I dont know wether the the PHP-GA is up-to-date for universal analytics, or if there is a separate PHP-library for this. Just to point you in a direction Commented Sep 22, 2014 at 11:15
  • considering that it states php-ga is no longer maintained and user_id is something that was added recently I would have to guess no. Commented Sep 22, 2014 at 11:50
  • Ah, that's a shame - is there an alternative PHP library you guys can recommend that supports this feature? Commented Sep 22, 2014 at 12:05
  • The beauty of the measurement protocol - the basis of universal analytics - is that you do not need a library to send calls to the google server. It's just a url with a few parameters now, you can send it serverside via CURL. As already stated UserId does not work with classic analytics, so you'd need to upgrade in any case. Commented Sep 22, 2014 at 13:12

1 Answer 1

1

You can push events without any library. Just use measurment protocol: https://developers.google.com/analytics/devguides/collection/protocol/v1/ Here is how I do it form server side:

<?php 
$data = array(
    'v=' . 1,
    't=' . 'approved', //Page
    'tid=' . 'UA-XXXXXXXX-X', //GA account code
    'cid=' . $ga_user_id, // 1267034788.1479821336 needs to be extracted from $_COOKIE['_ga']
    'ec=' . 'credit', // for event only - event category
    'ea=' . 'denied',   // for event only - event action
    'el=' . '12345', // for event only - event label
  );

  $ch = curl_init('www.google-analytics.com/collect');

  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $data));

  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  curl_exec($ch);
  curl_close($ch);

Here is builder tool that I've been using for url building: https://ga-dev-tools.appspot.com/hit-builder/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.