{"id":60506,"date":"2024-02-29T10:51:04","date_gmt":"2024-02-29T05:21:04","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=60506"},"modified":"2024-03-01T10:55:31","modified_gmt":"2024-03-01T05:25:31","slug":"integrating-google-analytics-4-with-unomi-using-measurement-protocol","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/integrating-google-analytics-4-with-unomi-using-measurement-protocol\/","title":{"rendered":"Integrating Google Analytics 4 with Unomi Using Measurement Protocol"},"content":{"rendered":"<h2><b>Introduction<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Analytics plays a crucial role in understanding user behavior and optimizing digital experiences. In this guide, we&#8217;ll walk through the process of integrating Google Analytics 4 (GA 4) with Unomi using the Measurement Protocol. This powerful combination allows for advanced user segmentation and provides more targeted insights. Follow these step-by-step instructions to send events from Unomi to GA 4 seamlessly.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-60498 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/img1.png\" alt=\"\" width=\"997\" height=\"588\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/img1.png 997w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/img1-300x177.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/img1-768x453.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/img1-624x368.png 624w\" sizes=\"(max-width: 997px) 100vw, 997px\" \/><\/p>\n<h2><b>Setting Up Google Analytics 4<\/b><\/h2>\n<p><b>1.1 Create a Google Analytics Account<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u00a0Navigate to <\/span><a href=\"https:\/\/analytics.google.com\/\"><span style=\"font-weight: 400;\">Google Analytics<\/span><\/a><span style=\"font-weight: 400;\"> and create a new account.<\/span><\/li>\n<\/ul>\n<p><b>1.2 Create a Google Analytics 4 Property<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Go to Admin \u2192 Account Access Management \u2192 Create a property.<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-60503\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image5.png\" alt=\"\" width=\"1920\" height=\"697\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image5.png 1920w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image5-300x109.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image5-1024x372.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image5-768x279.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image5-1536x558.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image5-624x227.png 624w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p><b>1.3 Add a Data Stream<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">In Admin, Go to Account Access Management \u2192 Data Streams \u2192 Add Stream.<\/span><\/span><\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-60501\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image3.png\" alt=\"\" width=\"1920\" height=\"715\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image3.png 1920w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image3-300x112.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image3-1024x381.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image3-768x286.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image3-1536x572.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image3-624x232.png 624w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p><b>1.4 Obtain Measurement ID<\/b><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">In Admin, go to Account Access Management \u2192 Data Streams \u2192 Add Stream \u2192 Stream Details.<\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-60504\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image6.png\" alt=\"\" width=\"1564\" height=\"581\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image6.png 1564w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image6-300x111.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image6-1024x380.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image6-768x285.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image6-1536x571.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image6-624x232.png 624w\" sizes=\"(max-width: 1564px) 100vw, 1564px\" \/><\/p>\n<p><b>1.5 Get Measurement Protocol API Secret Key<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">In Admin, go to Account Access Management \u2192 Data Streams \u2192 Add Stream \u2192 Stream Details \u2192 Measurement Protocol API secrets \u2192 Create.<\/span><\/li>\n<\/ul>\n<p><b>1.6 Create Custom Definitions<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If needed, create custom definitions for parameters to be sent to GA 4.<\/span><\/li>\n<\/ul>\n<h2><b>Linking GA 4 to Google Tag Manager<\/b><\/h2>\n<p><b>2.1 Create a Google Tag Manager Account<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Visit <\/span><a href=\"https:\/\/tagmanager.google.com\/\"><span style=\"font-weight: 400;\">Google Tag Manager<\/span><\/a><span style=\"font-weight: 400;\"> and create an account.<\/span><\/li>\n<\/ul>\n<p><b>2.2 Create a Container<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">In Admin, go to Account \u2192 Container \u2192 Create Container.<\/span><\/span><\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-60502\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image4.png\" alt=\"\" width=\"1828\" height=\"766\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image4.png 1828w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image4-300x126.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image4-1024x429.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image4-768x322.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image4-1536x644.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image4-624x261.png 624w\" sizes=\"(max-width: 1828px) 100vw, 1828px\" \/><\/p>\n<p><b>2.3 Create a Tag in Google Tag Manager<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Navigate to tags \u2192 new \u2192 tag configuration \u2192 Google Tag \u2192 set Tag ID as a constant variable (Measurement ID of GA 4) \u2192 Select Triggering \u2192 All pages<\/span><\/span><\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-60500\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image1.png\" alt=\"\" width=\"1524\" height=\"594\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/image1.png 1524w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image1-300x117.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image1-1024x399.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image1-768x299.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/image1-624x243.png 624w\" sizes=\"(max-width: 1524px) 100vw, 1524px\" \/><\/p>\n<h2><b>Code Base Setup<\/b><\/h2>\n<p><b>3.1 Clone the UNOMI Official Repo<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Clone the code from <\/span><a href=\"https:\/\/github.com\/apache\/unomi.git\"><span style=\"font-weight: 400;\">Unomi&#8217;s official<\/span><\/a><span style=\"font-weight: 400;\"> repository.\u00a0<\/span><\/li>\n<\/ul>\n<p><b>3.2 Create a Custom Extensions Project<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Follow the structure of Unomi&#8217;s custom extensions in this repository.<\/span><\/li>\n<\/ul>\n<p><b>3.3 Implement ActionExecutor Class<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Under the action module, create a custom class implementing ActionExecutor and override the execute method.<\/span><\/li>\n<\/ul>\n<p><b>3.4 Make HTTP Post Request to GA 4<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Send an HTTP Post request to<\/span><a href=\"https:\/\/www.google-analytics.com\/mp\/collect\"><span style=\"font-weight: 400;\"> https:\/\/www.google-analytics.com\/mp\/collect<\/span><\/a><span style=\"font-weight: 400;\"> with query parameters <\/span><b>measurement_id <\/b><span style=\"font-weight: 400;\">and <\/span><b>api_secret<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">E.g. &#8211;<\/span><\/p>\n<p><a href=\"https:\/\/www.google-analytics.com\/mp\/collect?measurement_id=G-DZN5PKGCC8&amp;api_secret=mX9O03uiSiCV-zI5KZMQEQ\"><span style=\"font-weight: 400;\">https:\/\/www.google-analytics.com\/mp\/collect?measurement_id=your_measurmentId&amp;api_secret=your_api_key<\/span><\/a><\/p>\n<p><b>3.5 Include Client ID and Event in the Request Body<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The POST request body should include client_id (a mandatory unique ID) and event.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Request body example :<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-60505\" src=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/req_body.png\" alt=\"\" width=\"779\" height=\"328\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2024\/02\/req_body.png 779w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/req_body-300x126.png 300w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/req_body-768x323.png 768w, \/blog\/wp-ttn-blog\/uploads\/2024\/02\/req_body-624x263.png 624w\" sizes=\"(max-width: 779px) 100vw, 779px\" \/><\/p>\n<h2><b>Conclusion<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">By following these steps, you&#8217;ve successfully integrated Google Analytics 4 with Unomi using the Measurement Protocol. This integration empowers you to gather more granular insights into user behavior and enhance your data-driven decision-making process.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Feel free to customize and enhance this integration based on your specific use cases and business requirements. Happy tracking!<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Introduction Analytics plays a crucial role in understanding user behavior and optimizing digital experiences. In this guide, we&#8217;ll walk through the process of integrating Google Analytics 4 (GA 4) with Unomi using the Measurement Protocol. This powerful combination allows for advanced user segmentation and provides more targeted insights. Follow these step-by-step instructions to send events [&hellip;]<\/p>\n","protected":false},"author":1730,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":41},"categories":[4685,4831,2251,446,1994],"tags":[5569],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60506"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1730"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=60506"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60506\/revisions"}],"predecessor-version":[{"id":60561,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/60506\/revisions\/60561"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=60506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=60506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=60506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}