krizon / php-ga-measurement-protocol

PHP client for the Google Analytics Measurement Protocol API
MIT License
109 stars 23 forks source link

Event tracking with custom dimension and metric #25

Closed LubosRemplik closed 1 year ago

LubosRemplik commented 9 years ago

In javascript you can do something like this

ga('send', 'event', 'category', 'action', {
  'metric19': 24.99
});

I have try two ways how to approach this via PHP GA, Test 1:

$client->event(array(
  'cid' => 'customer id',
  'tid' => 'tracking id',
  'ec' => 'Event Category',
  'ea' => 'Event Action',
  'el' => array(
    'metric19' => '24.99'
  )
));

Test 2:

$client->event(array(
  'cid' => 'customer id',
  'tid' => 'tracking id',
  'ec' => 'Event Category',
  'ea' => 'Event Action',
  'el' => json_encode(array(
    'metric19' => '24.99'
  ))
));

it seems neither ones work.

Any ideas?

gradosevic commented 8 years ago

Custom dimensions and metrics should be sent in the same level as other parameters. Naming convention is cmX and cdX, e.g. cm1, cm2, cm3... and cd1, cd2, cd3...

For some reason, I am unable to receive custom data in my Analytics account, any example how to actually set up this would be much appreciated.