Accessing ga4 metrics (Avg. session duration, event/sessions, engaged sessions)

209 views
Skip to first unread message

Adwords Scripting

unread,
Jun 19, 2023, 4:06:50 AM6/19/23
to Google Ads Scripts Forum
How. So how do you access these metrics?

Below how I get Average Session duration from UA (GA3), with the name "AverageTimeOnSite", what is the name for GA4?

      var Value = AdsApp.report(
    "SELECT AdGroupStatus, AverageTimeOnSite " +
    "FROM ADGROUP_PERFORMANCE_REPORT " +
    "WHERE AdGroupStatus = ENABLED " +
    "DURING 20230601,20230618");


Google Ads Scripts Forum Advisor

unread,
Jun 21, 2023, 4:44:52 AM6/21/23
to adwords...@googlegroups.com

Hi,

 

Thank you for reaching out to the Google Ads Scripts Support Channel.

 

Would you be so kind as to confirm if the information you're aiming to retrieve from GA3 is visible in your Google Ads account in the UI? If yes, may we ask that you provide a complete and uncropped screenshot from the Google Ads UI so that we may be able to guide you accordingly?

 

You may send these privately via the Reply to author option. Note that you may need to join the Google Group for you to use this option. If this option is not available on your end still, you may send it through our email (googleadsscr...@google.com) instead.

 

This message is in relation to case "ref:_00D1U1174p._5004Q2mV9VW:ref"

Thanks,
 
Google Logo Google Ads Scripts Team


Google Ads Scripter

unread,
Jun 21, 2023, 7:28:38 AM6/21/23
to Google Ads Scripts Forum
Hello and thanks for getting back!

Sorry for my unclear question. I want to fetch the "AverageTimeOnSite" from GA4. It works from UA (GA3) using "AverageTimeOnSite" but since UA (GA3) will be closed down in a couple of days I need to fetch it from GA4 now, how to do that?

Also see image.
 
FYI: The GA4 data for the accounts looks fine when entering by Browser.
Screenshot-2023-06-21-at-13.20.53.jpg

Sigurd Fabrin

unread,
Jun 21, 2023, 9:18:33 AM6/21/23
to Google Ads Scripts Forum

Google Ads Scripter

unread,
Jun 21, 2023, 10:41:51 AM6/21/23
to Google Ads Scripts Forum
Thanks.

I've read that thread about using a separate google sheets (or bigQuery). Any method seems quite time consuming to setup for every client and if using a spreadsheet it would be thousands of rows with session duration for 1 000 Ad Groups * 100 different time periods which then should be used within the rest of the script.

So...

Are you going to let one access the GA4 session duration direct from the Google Ads script as you have done with UA (GA3)?

Any other efficient solutions I can use or that will come?

Hoang Nhu Hoa

unread,
Jun 28, 2023, 9:47:05 AM6/28/23
to Adwords Scripting via Google Ads Scripts Forum
thanks

Vào Th 2, 19 thg 6, 2023 vào lúc 18:07 Adwords Scripting via Google Ads Scripts Forum <adwords...@googlegroups.com> đã viết:
--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/bce3c3a2-ea0f-45bf-a2c3-aa57a8d07226n%40googlegroups.com.

Adwords Scripting

unread,
Jul 4, 2023, 1:43:58 AM7/4/23
to Google Ads Scripts Forum
Thanks, any thoughts about my last questions? 

Are you going to let one access the GA4 session duration direct from the Google Ads script as you have done with UA (GA3), and if so what time can one expect it to be finnished?

Google Ads Scripts Forum Advisor

unread,
Jul 4, 2023, 7:46:47 AM7/4/23
to adwords...@googlegroups.com

Hi,

From the Google Ads Script's perspective, you can refer to our Advanced APIs, specifically the documentation for Google Analytics -https://developers.google.com/google-ads/scripts/docs/examples/google-analytics. The advanced APIs in Google Ads scripts let experienced developers connect to certain public Google APIs with less setup than using their HTTP interfaces. You use these APIs much like scripts' built-in services, and they offer the same conveniences like auto-completion and automatic authorization.

If you have any questions on how to access the GA4 session duration, you can instead raise your concern with the Google Analytics product team here: https://support.google.com/analytics/gethelp

Let me know if you have any question or if I misunderstood your concern, kindly elaborate.
 

Sigurd Fabrin

unread,
Jul 4, 2023, 8:21:05 AM7/4/23
to Google Ads Scripts Forum
In order to be able to fetch data from GA4 in Google Ads script, we need Google to enable access to the Google Analytics Data API  in the Advanced API drop-down menu

The current analytics API below is (the depreciated) Universal Analytics.
Screenshot 2023-07-04 at 14.06.54.png


The Google Analytics Data API is available for Apps script in Google sheets, but so far not for Google Ads script
Screenshot 2023-07-04 at 14.14.46.png


Sigurd

Adwords Scripting

unread,
Jul 4, 2023, 10:30:07 AM7/4/23
to Google Ads Scripts Forum
Okej, thanks for the info. I'll hope the API from Google Ads Script get's updated for GA4 too!
Reply all
Reply to author
Forward
0 new messages