I want to programmatically know the traffic channel for the current page using javascript google analytics (or reporting) API. Like organic, google search, direct, referral, etc. I can get referral with
tracker.get('refferer')
but I need to know the traffic channel.
For example channels
Can I get it? And if I can, then how?
no, usually you can not access it since channels are based upon source
and medium
combinations and these fields are processed on the server side based on referrer, document.location and previous visits information. Google Analytics provides a chart of the processing flow on the help pages
Of course, you can replicate some of the processing on the client side, by parsing utm labels from the location.href or checking the referrer but 1) this would require a ton of scripting 2) this wouldn't necessary match Google Analytics data
Some workaround can be to use classic analytics ga.js snippet alongside your usual analytics code with any dummy property ID. in this case ga.js code would process much of the source data on the client site and these data would be available from the utm* cookies