Google Analytics Event Tracking

I want to add GA event tracking to my Discourse installation. Is there any existing documentation or examples I can reference? Thanks!

Here’s some of the events that I want to track:
• Logging in
• Homepage
o Creating topic
o Starring topic
• Category page
o Creating topic
o Watching category
o Tracking category
o Regular status for category
o Muting category
o Editing category (selecting edit option)
• Topic page
o Replying
o Inviting
o Starring
o Sharing
o Flagging
• Profile page
o Adding profile photo
o Adding background photo
o Editing profile fields


You are missing a few key ones for registration/ new users like:

  • registered
  • confirmed registration
  • first login
  • first post/reply/like
1 Like

Yep, once I figure out how to GA event tracking, I can build on the list of events.

The key is to figure out how to track events :slight_smile:

Creating a generic metrics framework would be a good idea so people can track these sort of data points in a provider of their choice (google analytics, mixpanel, etc.).

An easier approach would be to use something like which already does this:

This would be a pretty deep integration point and would be difficult as a plugin I would imagine i.e. it would have to be baked into the core

1 Like

I agree. i’m not sure that this is a support issue, but should probably be an “extensibility” or plug-in topic.

I’m quite interested in this type of functionality. can anyone comment here as to whether the events iist @scotta’s original post are exposed at any point as a generic event (like a navigation event)?

Most, if not all of these seem like proper click events. When an action like (for example) Creating a Topic. is there a navigation hook event that could then be fed to a plugin that can invokes the appropirate GA call with the meta information of the action (location, user, etc.

I read through some of the plugin related threads, and it there didn’t appear to be a canonical reference to documentation describing how what capabilities the plugin framework expose from a general navigation perspective.

Is there a GO TO page/reference for how the plugin work re:navigation?


1 Like

Looking for some feedback here… Please bear with me, as I’m new to Ruby and Rails.

I’m currently working on adding this kind of event tracking, as it is pretty critical for my Discourse installation.

Presently, my idea is to add a view for each event so that they can be embedded in the correct place. By default, these will have code for Universal GA events if that is enabled, and otherwise will not have any additional code.

I think that a view for each event also opens this up to easily being extended via plugin, since the plugin could just overwrite whichever views it wants. That’s how it works, isn’t it? For example, a plugin would simply overwrite each tracking view with some JavaScript.

It think would also be helpful for the user to be able to enable/disable individual events and change the event name in the admin panel, so advice on the best way to make that happen would be appreciated. The enabled/disabled status and event name would be exposed to the view, so even plugins for other tracking/analytics providers could take advantage of the ability to customize event names in the admin panel with no additional code.

If all this sounds good, I think I have enough information and examples from the codebase to follow to go ahead and get this working.

1 Like


I’d recommend iterating on this vs doing it in one shot. For example, start with just GA and code events. Then add enable/disable. Then customization.

That way, you can ensure the technical works and get feedback from users based on their experiences with the solution.

Glad to see you taking this one.


For anyone interested, here’s the reference on how to add event tracking using analytics.js:


I have looked elsewhere on this forum and this is the only place I have seen this topic mentioned.

So I have two questions:

  1. Am I correct in understanding that there are no events that come out of the box with this GA/UA integration, that it’s just pageviews and nothing else?
  2. If we therefore want to add custom event tracking to our Discourse installation, we need to code and fire the events ourselves?

Yep, that sounds right. You can wire up your events using Ember by putting a <script> tag in Admin→Customize→CSS/HTML→</head>.


Sounds like a GA events listener wiki post would be useful for people interested in adding these and sharing them as a community resource!


Definitely - I think something about integrating GA using Google Tag Manager would also be useful (since for our website we fire Universal Analytics tags via GTM).

1 Like

This might be a stupid question (I’m not a developer, I’m an analytics guy) but could I put my Google Tag Manager container code in the /body section?


I would love to see something like that.

Tracking those on GA is quite enough, I need to compare them with new visitors. Is there any news?

1 Like

Been thinking about this lately. I can’t believe no one has done this yet as it could be incredibly valuable for us.

If we were able to tell how many times someone starts to make a topic and then gets redirected to an existing topic, we could start putting numbers on how valuable Discourse is to us.

I’ll definitely be looking into this in the coming months and will report any findings or how it goes.


That sounds good, but it would be an underestimation. A potential support request can be diverted without a customer having begun to create a new topic. It could even be argued that as your community grows, and more unique topics are created, customers will more easily find answer from the search box on the first try, rather than having to begin creating a new topic to find it.

To demonstrate the value of our Community (and other channels) we aggregate and compare the relative size of the following metrics:

All that’s to say that I think you already have the data you need to demonstrate the value of your forum.

1 Like

Very valid points, thanks for sharing. I’ll have a look at those and see how those are all affected.


I’m currently trying to track events such as Creating a Topic and Replying to an existing one.
I know how GA Events work and I know how to add custom JS code to the head via Admin→Customize→CSS/HTML→</head>.

What I still haven’t figured out is what I should listen to, in order to call the event tracking code and send the Event to GA.

I even thought about listening to a click on the button, but that doesn’t seem the right way to do it.

Any thoughts?

Edit: Nevermind, I got it. This topic helped me:

1 Like

Just wanted to check in… When I add GA tracking code to Discourse, as opposed to loading GA manually, does Discourse add any customization to the way events are fired, or is it basically just sending GA pageviews? Thanks.