---
title: "Google Analytics"
url: "https://timeashelpcenter.productfruits.help/en/article/google-analytics"
language: "en"
last_updated: "2024-07-26T13:02:27.487Z"
---

# Google Analytics

Integrating Google Analytics with Product Fruits provides you with a wide range of valuable insights into the types of users, their behavior, and habits

### **Integration with Product Fruits**

To enable the integration, first select the *Integrations* menu option as seen in the image below*.*

![](https://cdn-assets.productfruits.com/0de44262-a74d-47c3-adab-0c0cd668a37c)

Here, select *Google Analytics* from the menu, and click *Activate* to enable the integration*.* After activation, verify that Google Analytics is receiving data by checking the Realtime reports in your Google Analytics dashboard. Alternatively, you can use [**Tag Assistant**](https://tagassistant.google.com/), to ensure that events from the Knowledge Base are successfully integrated into Google Analytics.

![](https://cdn-assets.productfruits.com/a09edc1e-f43b-4ce2-8c7b-ef746af4ff84)

### **Events and Data**

Once integrated, Google Analytics will receive events regarding user interactions with Product Fruits content. These events include actions such as opening announcements, completing or skipping tours, and other significant interactions. For the full overview, check out this [**table**](https://help.productfruits.com/en/article/analytics-platforms-integrations).

### **Installing Google Analytics Into Your Application (Required)** 

For Google Analytics to function properly, it must be installed in the application where Product Fruits is deployed. This installation enables Google Analytics to capture and analyze user data effectively.

### **Installing Google Analytics into the Product Fruits Knowledge Base**

Although it's not necessary for the basic integration, adding Google Analytics directly to the Product Fruits Knowledge Base can provide additional tracking capabilities. 

As it is a single-page application, we need to call the Google Analytics API on page change manually. The standard Google Analytics code snippet cannot be placed in the "<head>" section as required, so we must modify the snippet and handle tracking programmatically.

Navigate to *Help > Customer portal* to access the settings, then under *General* tab scroll down to the bottom of the page, and open the *Custom HTML & Scripts* toggle. Here we will work in the *Body HTML or script tags* box.

![](https://cdn-assets.productfruits.com/02bd6fe4-d3cf-4e3a-a109-02f033b0c659)

To install Google Analytics, use the following JavaScript code snippet. This snippet configures Google Analytics for a single-page application by asynchronously loading the library and initializing it with your tracking ID.

Make sure to replace "YOUR\_ID" with your actual G-tag. 

```javascript
<script async src="https://www.googletagmanager.com/gtag/js?id=
YOUR_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

function trackPageview(url) {
	gtag('config', 'YOUR_ID', {'page_path': url});
}

window.addEventListener('DOMContentLoaded', function() {
  document.querySelectorAll('a').forEach(function(anchor) {
	anchor.addEventListener('click', function(event) {
		var url = this.getAttribute('href');
		trackPageview(url);
		history.pushState(null, null, url);
	});
  });
});

</script>
```
