Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics Query Custom Channel Grouping

I am trying to pull a Custom Channel Grouping for Transaction IDs from Google Analytics. The marketing group has defined a couple of custom Channel Groupings in GA and they want me to pull these fields. I can not find any documentation anywhere which discusses this. It's not a custom dimension and it's not a custom variable. Has anyone else had to do this? Is it possible or do I have to re-implement the rules outside of GA?

like image 729
Matthew Crews Avatar asked May 27 '26 13:05

Matthew Crews


2 Answers

Short answer: this is not currently possible (as of June 2015) in the Google Analytics API.

The best workaround I have found is to rebuild the channel grouping in the logic of the API query. For example, if you have a channel group that is defined in your custom grouping as "campaign contains shopping AND source == google," you can write that into the filters line of the optArgs call to the API.

This doesn't strike me as a sustainable, maintainable practice, however -- if the custom grouping is changed, you need to go back and change your code separately -- but it's the best solution available at the moment.

like image 72
Mihir Tendulkar Avatar answered May 31 '26 12:05

Mihir Tendulkar


Example code is Javascript:

The filter doesn't seem to work for ga:channelGrouping, so 'filters':'ga:channelGrouping=Direct', fails with the error:

{
    "error": {
        "errors": [{
            "domain": "global",
            "reason": "invalidParameter",
            "message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
        }],
        "code": 400,
        "message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
    }
}

But you can get the ga:channelGrouping back as a dimension:

gapi.client.analytics.data.ga.get({
    'ids': 'ga:' + profileId,
    'start-date': 'yesterday',
    'end-date': 'today',
    'dimensions':'ga:channelGrouping,ga:date, ga:landingPagePath, ga:pagePath',
    'metrics': 'ga:entrances',
    'sort': '-ga:date',
  })

so you get it in the data:

[
      /*Channel grouping*/
      "(Other)",
      "20150730",
      "blah",
      "vlah",
      "7"
    ]

At the moment I'm planning on filtering the channel grouping in my own code once I get the result back rather than trying to get Google to do this for me. Basically because Google doesn't seem to support this right now...

like image 22
Liam Avatar answered May 31 '26 11:05

Liam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!