Does Discourse allow for customization of tracking codes with Google Analytics

Hi all! Within our Discourse community, we host both questions and answers and blog posts. To differentiate between these two types of content for our members, we use tags like /tag/blog/ and /tag/question/. Our business requires us to compare the number of blogs vs. questions created month by month.

This task is challenging because Discourse’s default reporting structures focus on topics or posts, and the /tag/blog filter is implemented within the platform rather than directly in the URL structure. Google Analytics 4 doesn’t support direct filtering by tags, so I’m exploring alternative methods.

To achieve similar insights, we can apparently utilize custom dimensions or events in GA 4. I’m wondering if Discourse allows for customizing tracking codes for Google Analytics.

From what I gather, this involves

  1. Modify Tracking Code to send the custom event data to Google Analytics. This typically involves using JavaScript.
  2. Send Event Data: Use the gtag() function (Google’s global site tag) to send the event data. The syntax for sending event data with gtag() is as follows:

javascript gtag(‘event’, ‘action’, { ‘event_category’: ‘category’, ‘event_label’: ‘label’, ‘value’: value });

  • Replace 'action' with the action you want to track. For example, you could use 'page_view' for tracking page views.
  • Replace 'category' with the category of the event. This could be ' Blog ' or something similar to identify blog-related events.
  • Replace 'label' with a descriptive label for the event. This could be the title of the blog post.
  • You can include additional parameters like 'value' if applicable.

Place the modified tracking code on your website (Discourse) where you want the event to be tracked. Typically, this would be within the HTML of your webpage, preferably in the <head> section.

Additionally, our admin team has disabled the Explorer plugin tool.

If anyone can confirm that it’s feasible to obtain data comparing the number of questions tagged as /tag/question/ versus blogs tagged as /tag/blog/ created on a month-by-month basis, I can revisit the matter with the server administrators.

Many TIA!