Getting a link to a specific Google Analytics view

后端 未结 3 1228
-上瘾入骨i
-上瘾入骨i 2021-01-06 16:10

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

3条回答
  •  有刺的猬
    2021-01-06 16:53

    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 + '/'
    

提交回复
热议问题