Search code examples
google-analyticsgoogle-analytics-api

How to retrieve Property ID and use utm marks in Google Analytics Data API?


I want to switch from Google Analytics Reporting API to Google Analytics Data API (GA4) .

In Reporting API it was possible to retieve all view id for account (used to send requests) by special endpoint. In Analytics Data API there is no view id, but there is Property ID which is used to send requests. But I didn't find any endpoint to get Property ID through REST. Is it even possible or it's only available from https://analytics.google.com/ admin panel?

Also in Reporting API to send requests I used utm marks in dimensionFilterClauses array like this:

"dimensionFilterClauses":[
      {
         "operator":"AND",
         "filters":[
            {
               "dimensionName":"ga:campaign",
               "operator":"EXACT",
               "expressions":[
                  "some_campaign_name_2021"
               ]
            },
            {
               "dimensionName":"ga:adContent",
               "operator":"EXACT",
               "expressions":[
                  "multiformat"
               ]
            },
            {
               "dimensionName":"ga:medium",
               "operator":"EXACT",
               "expressions":[
                  "cpm"
               ]
            },
            {
               "dimensionName":"ga:source",
               "operator":"EXACT",
               "expressions":[
                  "facebook"
               ]
            },
            {
               "dimensionName":"ga:keyword",
               "operator":"EXACT",
               "expressions":[
                  "car"
               ]
            }
         ]
      }
   ]

How can I do it with Google Analytics Data API (GA4)?


Solution

  • You can use the Admin API to list all GA4 Properties that you have access to. The method is accountSummaries.list.

    The response will contain for example...

         "propertySummaries": [
            {
              "property": "properties/215...",
              "displayName": "You GA4 Property Name"
            },
          ...
    

    For the utm marks, you'll need to translate those dimension names from GA3 to GA4. This page provides the equivalent dimensions in GA4. For example, ga:source in GA3 is similar to source in GA4. Note that ga:keyword and ga:adContent are not yet available in GA4.