Basj
Basj

Reputation: 46371

How to send medium and source with ga('send', 'pageview', ...)?

On some referral links (I cannot modify them), I didn't use the standard:

example.com/?utm_source=hey&utm_medium=mymedium&utm_campaign=campaign17

but I used the non-standard:

example.com/?src=foo

Thus, it is not tracked correctly in Google-Analytics. It is displayed as:

medium  source
(none)  (direct)

So I tried to pass the relevant parameters via a custom Javascript code:

ga('send', 'pageview', '/?utm_source=foo&utm_medium=test&utm_campaign=test');

instead of ga('send', 'pageview'); at the end of the standard analytics <script>...</script> snippet.

Still, it doesn't work: it is displayed as (none) (direct) (for example in Analytics' Realtime > Traffic sources).

Question: how to pass a source / medium / campaign name via ga('send', 'pageview', ...);?

Upvotes: 2

Views: 2058

Answers (2)

Olly P
Olly P

Reputation: 1

use profile filters to push in the parameter into the source medium fields with no code required.

Upvotes: 0

Dmitry Sulman
Dmitry Sulman

Reputation: 126

You have to use ga('set', ...) command before ga('send', 'pageview'):

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'campaignSource', 'foo');
ga('set', 'campaignMedium', 'yourmedium');
ga('set', 'campaignName', 'test');
ga('send', 'pageview');

Or you can use more simple syntax:

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview', {'campaignSource': 'foo', 'campaignMedium': 'yourmedium', 'campaignName': 'test'});

Field reference: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#trafficsources

Upvotes: 4

Related Questions