Google Analytics API - retrieve Custom Segment Id by its name

前端 未结 2 1301
灰色年华
灰色年华 2020-12-18 11:42

Using Google Analytics API to retrieve 20+ Profiles\' data so i can combine all of them into one set of data for analysis. (separate profiles are for different domains that

相关标签:
2条回答
  • 2020-12-18 12:28

    I found an easy way to get custom segments details from api.

    First, you need to have user management access, probably an administrator can easily do that.

    Manage Segments#Set Segment availability

    • Visit this link and go to 'Set Segment availability' section in there.
    • Apply 'Collaborate permission' option as shown in the link.

    After applying permission, just from your service account and api run the same code as you mention in you question or follow the below link of code to list all segments details.

    Listing a User's Segments

    This time you will be able to get custom segment ids. I was trying to get the custom segment details since last 3-4 days. Hope it helps.

    0 讨论(0)
  • 2020-12-18 12:33

    The answer is that the Analytics Core Reporting API doesn't have access to the custom segments. They can only be accessed by the Analytics Management API as referenced here:

    Retrieve a user's Custom Segments to apply them to Core Reporting API queries. https://developers.google.com/analytics/devguides/config/mgmt/v3/

    So looks like I will have to make call to Analytics Management API first to get list of custom segments that I want, and then use that list in Analytics Core Reporting API call to get data for just those segments.

    https://developers.google.com/analytics/devguides/reporting/core/v3/reference#segment

    Alternatively, I can forget about using the custom segments and instead retrieve Session Hostname and Source in Analytics Core Reporting API call data, so that I can do same filter in the query or in report as my custom segment. Drawback is that the referral spam is about 80% + of Google Analytics data so I would be retrieving more data than i need on regular basis.

    0 讨论(0)
提交回复
热议问题