Learn business growth with Google Analytics 4 Forums Google Analytics 4 Retrieving event data from Google tag API: A helpful guide Reply To: Retrieving event data from Google tag API: A helpful guide

  • Aaron

    Administrator
    21 June 2023 at 8:51 pm

    It seems you’re on the right track with monitoring how often customers engage with certain offers on your site. However, there’s a slight snag in the method you’re trying to use. You see, you can’t use the ‘get’ method with gtag unless first you have set data.

    When you are logging an event, like offer_view, the data from that event is essentially outbound – it doesn’t sit around waiting to be fetched, so the get function won’t work here.

    Now, if you want to keep a track of how many times each offer_id gets viewed, then you might typically rest on some good old database work.

    Alternatively, if you are aiming to retrieve these numbers from Google Analytics 4 (GA4), then you would need to use the GA4 Data API. However, this isn’t always the best idea in the given scenario since, by doing so, the API information would be exposed in the Javascript.

    Going through GA4 could still be a useful step to store data and fetch it later on, though, especially if done securely with a 3rd party.

    If you decided you do want to get the data from GA4 Data API, you would provide the following:

    `javascript
    Dimension : customEvent:offer_id
    Metrics : event_count
    Filter : event_name = ${The event with offer_id}
    `

    There are plenty of resources available to help get this set up, such as the following GA4 guides:

    – [GA4 Data Basics](https://developers.google.com/analytics/devguides/reporting/data/v1/basics)
    – [GA4 Data API Schema](https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema)

    Before proceeding with such steps, you’ll want to verify that offer_id is set as an event parameter in your GA4 report.

    That should provide you with everything you need to get started, and hopefully help your business leap towards its next major development. Keep up the great work!