Add Google Analytics to your knowledge base
Last Update: Sep 2024 • Est. Read Time: 2 MINOften times you'll want to track the performance of your knowledge base. Google Analytics is a free service that will allow you to collect valuable insights into its usage. You'll be able to see how many people visit your knowledge base, which articles get the most amount of views, and how long they stay on the page. This can help you determine what content is and isn't working. You'll also be able to see how users navigate from page to page to understand what information they consume if they don't find their answer. Finally, Google Analytics can help you track user data related to location, browsers, and devices.
Please note that EU regulators have issued decisions requiring website operators to remove Google Analytics from their websites due to concerns about data transfers to the United States. As such, we suggest that you monitor these developments, as the use of Google Analytics in the Europe Union and United Kingdom may not be deemed permitted by relevant regulators.
Who can access this feature? | |
User types | Content Administrators or Admins can access Knowledge base themes. |
In this article
Prerequisites
You must have an Analytics account before you can set this up in your Kustomer knowledge base theme.
Adding Google Analytics to your knowledge base
Once you have an account, you can add Google Analytics to your theme so you can start tracking insights.
- Go to Settingsand select Knowledge Base > Themes.
- Select the theme your knowledge base is using. If using the visual editor, go to More Optionsand select Go to Code Editor.
- Select Create New Draft and open the GA.js file found in the Global section in the right panel. If your theme does not already have this file, select Add to create the file using the following options:
- Theme Target: Global
- File Name: GA
- File Type: JS
- Enter the following code in the editor:
window.addEventListener('load', (event) => { const script = document.createElement('script'); script.async = true; script.src = "https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"; document.getElementsByTagName('head')[0].appendChild(script); window.dataLayer = window.dataLayer || []; function gtag(){window.dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'GA_MEASUREMENT_ID'); });
- Enter your Google Analytics 4 property in the two lines that ask for GA_MEASUREMENT_ID.
Note: If you set up your analytics before October 2020 and have a Universal Analytics property, you can use this ID instead.
- Select Save and Publish.