US English (US)
BS Bosnian

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Book a Demo
  • Product Updates
  • Contact Us
English (US)
US English (US)
BS Bosnian
  • Home
  • Customization
  • Customization Guides
  • Advanced Customization

Tracking Analytics with Google Analytics 4 (GA4)

Learn how to implement custom GA4 events in your Helpjuice knowledge base to measure article engagement, search behavior and more

Written by Guilherme Arantes

Updated at June 24th, 2025, by Amanda Helpjuice

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Getting Started
    Users Accessibility New to Helpjuice? Start Here Content Management Multiple Languages/Translations & Localization Multilingual Knowledge Bases Analytics Video Tutorials
  • Customization
    Customization Guides
  • API V2
  • API V3 and Webhooks
  • Article Editor
  • Billing / Subscription
  • Authentication
  • Pricing
  • Swifty AI Chatbot
  • Swifty AI Helpbar
  • What's New
+ More

Table of Contents

1. Tracking Page Views 2. Tracking Search Terms and Result Counts

This guide will walk you through setting up Google Analytics 4 (GA4) custom events in Helpjuice, so you can track article page views, search interactions, and user identification all from within your Helpjuice site.

If you need to track other events, you can follow a similar approach from these examples.

1. Tracking Page Views

To record each page view within your Helpjuice instance, add the following event after your article content is rendered, or within a DOMContentLoaded event:

gtag("event", "hj_page_view", {
  page_title: document.title,
  page_path: window.location.pathname
});

This enables you to build reports in GA4 based on specific page viewed, helping you measure knowledge base engagement.

2. Tracking Search Terms and Result Counts

To understand what your users are searching for and how effective your articles are at answering their queries, track each search term along with the number of results returned:

document.addEventListener("DOMContentLoaded", function() {
  const searchInput = document.querySelector('#search');
  if (searchInput) {
    searchInput.addEventListener("change", function() {
      const term = searchInput.value;
      const interval = setInterval(() => {
        const results = document.querySelectorAll(".search-result").length;
        const noResults = document.querySelector(".no-results");
        if (results > 0 || noResults) {
          clearInterval(interval);
          gtag("event", "hj_search", {
            search_term: term,
            result_count: results
          });
        }
      }, 300);
    });
  }
});

This snippet captures both the search term and the number of results returned (including zero results), giving you insight into what users are looking for and whether their needs are being met.

helpjuice events ga4 setup

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • How to track Article Analytics through API (views and readings)
  • Analytics API

Copyright © 2025 - Helpjuice

Helpjuice, Inc. is a registered US Corporation, EIN # 45-2275731

Download W9
  • Help
  • Features
  • Pricing
  • About
  • Careers
  • Customers
  • Blog
  • Case Studies
  • Resources
  • Knowledge Base Examples
  • Privacy Policy
  • Terms of Service

Why is the knowledge base important?

With a knowledge base, you can allow your customers to self-help themselves, thus reducing your customer support by up to 60%. Furthermore, you can also have your team get instant answers to the questions they need without having to email themselves all using knowledge base software.

What is the purpose of a knowledge base?

The purpose of knowledge base software is to allow you to host your knowledge base/corporate wiki in one centralized 'hub'. Both your customers, and employees can now access information within seconds!

Made with from Miami, Bosnia, Morocco & Brasil

+1 (833) 387 3877 support@helpjuice.com
Expand