'Get Source and Medium from ga.js

I have a newsletter page on my website which I'd like to also use to capture some additional information about the user using Google Analytics.

Using the getAll() method from ga.js I can get the referrer URL (if any), however I cannot see the medium or source data. Is this possible to retrieve using their ga.js library?



Solution 1:[1]

Retrieve specific tracker from the list of trackers you obtained. Use the following to access the fields source and medium. tracker.get('campaignSource') and tracker.get('campaignMedium')

Additional help from below links. Access data from ga object: https://developers.google.com/analytics/devguides/collection/analyticsjs/accessing-trackers

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

Solution 2:[2]

This is not possible with ga.js. However, you can use custom JavaScript to deduce the same information.

If you only want this capability, then I suggest you have a look at the library I wrote: https://github.com/ilkkapeltola/visitdata

Once the library is included, you can run visitData.get(), which returns an object with exactly the data you need.

Solution 3:[3]

If you are using google analytics core reporting api try this 'metrics': 'ga:sessions ,ga:pageviews', 'dimensions' : 'ga:source,ga:medium'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2386411
Solution 2 Damini Suthar
Solution 3 Sam