bernard
BuSo Pro
- Joined
- Dec 31, 2016
- Messages
- 2,587
- Likes
- 2,298
- Degree
- 6
If you have a php file that returns an empty tracking pixel, how would you best get this into Google Analytics as an event connected to the relevant user session?
I asked GPT and using the Measurement Protocol, but then the event got tracked as Direct traffic instead of being an Event connected to an actual User session.
I then asked GPT again and was told to grab the clientID and pass it to the tracking script and then pass it to GA, which should do the trick?
and
Is this approach feasible?
I asked GPT and using the Measurement Protocol, but then the event got tracked as Direct traffic instead of being an Event connected to an actual User session.
I then asked GPT again and was told to grab the clientID and pass it to the tracking script and then pass it to GA, which should do the trick?
JavaScript:
ga(function(tracker) {
var clientId = tracker.get('clientId');
var imageUrl = 'https://example.com/tracker.php?clientId=' + clientId;
// then use imageUrl as the source of the tracking pixel });
});
and
PHP:
<?php
// Load Universal Analytics parameters
$data = array(
'v' => 1,
'tid' => 'UA-XXXX-Y', // replace with your Tracking ID
'cid' => $_GET['clientId'],
't' => 'event',
'ec' => 'affiliate',
'ea' => 'click',
);
// rest of the script...