Getting a link to a specific Google Analytics view

纵饮孤独 提交于 2019-11-30 18:48:33

问题


I have a GA account, with defined properties and views. Now, I gave viewing rights for a few users to a specific view. How can I construct/get programmatically a direct URL that will bring those users right to that view/report?

Thanks a lot!


回答1:


First lets take a look at an typical report url for a specific view:

https://analytics.google.com/analytics/web/#report/visitors-actives/a40777649w70913173p73156703/

Notice the pattern:

BASE_URL = 'https://analytics.google.com/analytics/web/#report/'
REPORT_TYPE = 'visitors-actives/'
ACOUNT_ID = '40777649'
WEBPROPERTY_ID = '70913173'
PROFILE_ID = '73156703' # Also called the view Id.

You can retrieve this information programmatically by calling the Account Summaries: list API method which returns a list of Account Summaries:

{
  "id": string,
  "kind": "analytics#accountSummary",
  "name": string,
  "starred": boolean,
  "webProperties": [
    {
      "kind": "analytics#webPropertySummary",
      "id": string,
      "name": string,
      "internalWebPropertyId": string,
      "level": string,
      "websiteUrl": string,
      "starred": boolean,
      "profiles": [
        {
          "kind": "analytics#profileSummary",
          "id": string,
          "name": string,
          "type": string,
          "starred": boolean
        }
      ]
    }
  ]
}
  • The ACCOUNT_ID is the top level acountSumaries.id.
  • The WEBPROPERTY_ID is the accountsumaries.webproperties[X].internalWebPropertyId.
  • The PROFILE_ID is the accountsumaries.webproperties[X].profiles[X].id

Now with this information you can recustruct the URL link to the report of interest for a particular view.

FULL_URL = BASE_URL + REPORT_TYPE + 'a' + ACCOUNT_ID + 'w' + WEBPROPERTY_ID + 'p' + PROFILE_ID + '/'



回答2:


Further to Matt's brilliant answer, you can use the "Try this API" section in their documentation here to get this information without writing a line of code:

https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountSummaries/list

There is also some code snippets to do this programmatically.

Don't forget you will need to be logged in with an account with GA access for this to work.




回答3:


I have a few points to add to Matt and Adam's answers:

  • I chose to build a generic URL for the main view instead of a report. That way a user can navigate to a report of their choosing. The URL structure is https://analytics.google.com/analytics/web/#/report-home/a[account id]w[internal web property id]p[view id] Important: a user has to have at least READ_AND_ANALYZE permissions for the web property in order to access its default view.
  • internalWebPropertyId is a resource in the web properties collection and can be obtained through various GA Management API calls. For example, I extracted this value from the response object after creating a new web property using insert call.


来源:https://stackoverflow.com/questions/42340736/getting-a-link-to-a-specific-google-analytics-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!