Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'Traffic Source' in universal analytics

How to get Traffic source data in universal analytics?

I'm trying the following code in firebug console:-

ga(function(tracker) {
  var src = tracker.get('campaignSource');
  console.log(src);
});

But it always logs 'undefined'.

The field 'campaignMedium' also returns 'undefined'.

But I get correct values for some fields like 'clientId' or 'screenResolution' or 'language'.

Is there some other process to get these infromation?

P.S: I'm using https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#trafficsources for reference of field names.

like image 894
Kaushik Avatar asked Oct 03 '22 12:10

Kaushik


2 Answers

I don't believe you can because campaign info is all stored server-side. The reason you're able to get the value of the fields for 'clientId', 'screenResolution' and 'language' is that they are stored client-side.

If you wanted to get the campaign source, etc., you'd have to create your own cookie and store the campaign values there.

like image 96
Blexy Avatar answered Oct 05 '22 11:10

Blexy


As Blexy suggested, with UA it's better to rely on your own cookie for tracking traffic sources. Try this project: https://github.com/dm-guy/utm-alternative

like image 38
dm-guy Avatar answered Oct 05 '22 13:10

dm-guy