{"id":7973,"date":"2022-10-19T14:02:40","date_gmt":"2022-10-19T14:02:40","guid":{"rendered":"https:\/\/docs.campaignsuite.nl\/docs\/gravity-forms\/measurement\/google-analytics-4\/"},"modified":"2022-10-19T14:04:35","modified_gmt":"2022-10-19T14:04:35","slug":"google-analytics-4","status":"publish","type":"docs","link":"https:\/\/docs.campaignsuite.nl\/en\/docs\/gravity-forms\/measurement\/google-analytics-4\/","title":{"rendered":"Google Analytics 4"},"content":{"rendered":"\n<p><img decoding=\"async\" src=\"https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/google_analyitcs_4_logo.png\" style=\"width: 210px;\" align=\"right\">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 <strong>After a webhook call from Findock v2<\/strong> and <strong>After a successful payment<\/strong> a Server Side call can be performed and not Client Side.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Client Side<\/h3>\n\n\n\n<p>We recommend using the Client Side calls in GA4 if you don&#8217;t have Google Tag Manager. When you use the Client Side call, CampaignSuite executes javascript functions by means of gtag(); This requires that <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/gtagjs\" target=\"_blank\" rel=\"noreferrer noopener\">Google Tag<\/a> is installed on the website:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- Google tag (gtag.js) --&gt;\n&lt;script async src=\"https:\/\/www.googletagmanager.com\/gtag\/js?id=GA_TRACKING_ID\"&gt;&lt;\/script&gt;\n&lt;script&gt;\n  window.dataLayer = window.dataLayer || &#91;];\n  function gtag(){window.dataLayer.push(arguments);}\n  gtag('js', newDate());\n  gtag('config', 'GA_TRACKING_ID');\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>In the above code, replace GA_TRACKING_ID with your own tracking ID from Google Analytics.<\/p>\n\n\n\n<p>When CampaignSuite executes a Client Side GA4 call, a javascript code will be executed in the visitor&#8217;s browser. <br>Read <a rel=\"noreferrer noopener\" href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/gtagjs\/sending-data\" target=\"_blank\">here<\/a> 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:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example of mapping:<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"424\" src=\"https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_client.png\" alt=\"\" class=\"wp-image-7941\" srcset=\"https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_client.png 907w, https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_client-300x140.png 300w, https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_client-768x359.png 768w\" sizes=\"auto, (max-width: 907px) 100vw, 907px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Javascript example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script type=\"text\/javascript\"&gt;\n  if (window.gtag == undefined) {\n    window.gtag = function() {\n      window.dataLayer = window.dataLayer || &#91;];\n      dataLayer.push(arguments);\n    };\n  }\n  gtag('event', 'page_switch', {\n    'form_page': 1,\n    'form_id': 4\n  });\n&lt;\/script&gt;\n<\/code><\/pre>\n\n\n\n<p>The above code uses the Javascript function gtag().<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Server Side<\/h3>\n\n\n\n<p>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 -&gt; Account Settings -&gt; Data Streams. Click on the stream and copy the Measurement ID here. The value of the API secret can be found under the heading <strong>Measurement Protocol API secrets.<\/strong><\/p>\n\n\n\n<p> GA4&#8217;s Server Side calls use the <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/protocol\/ga4\" target=\" _blank\">Measurement Protocol API<\/a><\/strong> 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).<\/p>\n\n\n\n<p>The images below show an example of a GA4 Server Side call upon a successful payment in CampaignSuite:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example of mapping:<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"875\" height=\"644\" src=\"https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_server-1.png\" alt=\"\" class=\"wp-image-7970\" srcset=\"https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_server-1.png 875w, https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_server-1-300x221.png 300w, https:\/\/docs.campaignsuite.nl\/wp-content\/uploads\/2022\/10\/measurement_ga4_server-1-768x565.png 768w\" sizes=\"auto, (max-width: 875px) 100vw, 875px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">POST request example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"client_id\": \"278327074.1665398324\",\n  \"non_personalized_ads\": false,\n  \"events\": &#91;\n    {\n      \"name\": \"purchase\",\n      \"params\": {\n        \"items\":\n&#91;\n           {\n             \"item_id\": \"Ideal\",\n             \"item_name\": \"One time\",\n             \"quantity\": 1,\n             \"item_category\": \"donations\",\n             \"price\": 25\n           }\n         ],\n         \"currency\": \"EUR\",\n         \"transaction_id\": \"346\",\n         \"value\": 25\n       }\n     }\n   ]\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><span style=\"text-decoration: underline;\">client_id<\/span><\/strong><br>This parameter is automatically populated with a Google Analytics Client ID if it is set in the website with a pixel<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Event builder<\/h3>\n\n\n\n<p>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: <a href=\"https:\/\/ga-dev-tools.web.app\/ga4\/event-builder\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/ga- dev-tools.web.app\/ga4\/event-builder\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":7768,"menu_order":5,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-7973","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/comments?post=7973"}],"version-history":[{"count":3,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7973\/revisions"}],"predecessor-version":[{"id":7977,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7973\/revisions\/7977"}],"up":[{"embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7768"}],"wp:attachment":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/media?parent=7973"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/doc_tag?post=7973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}