Docly

Google Analytics 4

Estimated reading: 3 minutes

With the provider Google Analytics 4 (GA4) it is possible to perform Client Side and Server Side calls. This is possible for all six different event types. Only with the event types After a webhook call from Findock v2 and After a successful payment a Server Side call can be performed and not Client Side.

Client Side

We recommend using the Client Side calls in GA4 if you don’t have Google Tag Manager. When you use the Client Side call, CampaignSuite executes javascript functions by means of gtag(); This requires that Google Tag is installed on the website:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){window.dataLayer.push(arguments);}
  gtag('js', newDate());
  gtag('config', 'GA_TRACKING_ID');
</script>

In the above code, replace GA_TRACKING_ID with your own tracking ID from Google Analytics.

When CampaignSuite executes a Client Side GA4 call, a javascript code will be executed in the visitor’s browser.
Read here more about the code we use for this. The calls to GA4 use events. An example of a simple page change in Gravity Forms might look like this:

Example of mapping:

Javascript example

<script type="text/javascript">
  if (window.gtag == undefined) {
    window.gtag = function() {
      window.dataLayer = window.dataLayer || [];
      dataLayer.push(arguments);
    };
  }
  gtag('event', 'page_switch', {
    'form_page': 1,
    'form_id': 4
  });
</script>

The above code uses the Javascript function gtag().

Server Side

Technically it is possible to have a Server Side call made to GA4 for all six event types. This is only available if a Measurement ID and an API secret are entered in the CampaignSuite settings. These can be found in the admin section of your Google Analytics account -> Account Settings -> Data Streams. Click on the stream and copy the Measurement ID here. The value of the API secret can be found under the heading Measurement Protocol API secrets.

GA4’s Server Side calls use the Measurement Protocol API from Google. This API also works on the basis of sending events via a POST request to an endpoint (https://www.google-analytics.com/mp/collect).

The images below show an example of a GA4 Server Side call upon a successful payment in CampaignSuite:

Example of mapping:

POST request example

{
  "client_id": "278327074.1665398324",
  "non_personalized_ads": false,
  "events": [
    {
      "name": "purchase",
      "params": {
        "items":
[
           {
             "item_id": "Ideal",
             "item_name": "One time",
             "quantity": 1,
             "item_category": "donations",
             "price": 25
           }
         ],
         "currency": "EUR",
         "transaction_id": "346",
         "value": 25
       }
     }
   ]
}
  • client_id
    This parameter is automatically populated with a Google Analytics Client ID if it is set in the website with a pixel

Event builder

Google has a handy tool with which you can build an event to test whether it is a valid call. It can be found at: https://ga- dev-tools.web.app/ga4/event-builder/