Google Analytics for Sitecore Content Hub
How to implement Google Analytics for Sitecore Content Hub?

In this blog, we will learn how to implement Google Analytics for Sitecore Content Hub.
Nowadays, there is often a basic need for data whenever a user interacts with a site, portal, platform, or anything else. This data provides insights into where users go and which buttons they click, among other things.
Now, putting aside my talk on "why analytics is important," let's see how we can implement it in Sitecore.
Let's break it down into two parts:
Part 1: Google Analytics and Google Tag Manager
Log in to Google Tag Manager and create a container.

Now click on "New Tag" -> Tag Configuration -> Google Analytics -> Google Analytics: GA4 Event
you will see something like this below

For the measurement ID, log in to Google Analytics.
Go to Admin, then Property Settings → Data Collection and Modification → Data Streams.
Now, we all have one question: why do this? The answer is to receive analytics; without it, you won't get any data.

Add Stream → web

After creating the data stream, click on it, and you will see a page like the one below.
Copy that measurement ID.

Go to Tag Manager and add a new tag.
Enter the measurement ID there. If you see a message like "No Google tag found in this container", you need to create a tag by clicking "Create Tag." Just create the tag. You can also change the triggering on all pages or Initialization - All Pages.

Now you have everything you need for analytics.

The code below is for sending an event if needed.
<!-----------custom event --------------->
<script>
window.dataLayer.push({
event: "<event_name>",
custome_event_parameter: "<your_value>",
});
</script>
*Add code as needed.
Part 2: Sitecore Content Hub Integration
Log in to Sitecore Content Hub.
Go to Manage → Settings → Portal Configuration → Google Tag Manager.
Add the Container Key there.
If you want to send an event, add the script code above to the HTML code of any Content Hub page.
Now you can access all your Google Analytics data in Google Analytics.

References:



