Better Analytics

Better Analytics 3.1.1

No permission to download
@digitalpoint: This looks very nice so far! :) Can't wait to play around with it.

2 feature requests:
  • Could you also add the option to track new created threads?
  • It also would be really cool, if it would be easy for other developer to extend the tracking of events for other content types. For example i'm trying for years to track comments and reviews from @Bob s AddOns (like AMS, RMS,...) in Google Analytics.
Thank you :)
Ya... new thread creation was already planned (and a few other things), I just haven't fully populated that settings page yet.

I needed to make the underlying tracking framework fairly modular already because there's some trickery it has to do when tracking when a user logs in.

Someone can either add normal gtag() events, but there are also times when you want to track something that happens but the action itself doesn't have a client-side page to give any JavaScript to run (for example if you do something and then it redirects the user to a page afterwards. In that case, it's setup to use the user's session. Anything can simply add an "analytics" object to the user's session, and the next page the user ends up on will log that event.

For example say you wanted to log a custom event, "new review" with no secondary parameters (the empty array at the end there is an array of parameters for the event):
PHP:
$session = $this->session();
$session->set('analytics', ['new_review', []]);
$session->save();

You could put that wherever was most appropriate (could be in an Entity that triggered only onInsert() or something.

If you have a template that is used after a new review is added, you could add the same thing with normal JavaScript like so:
Code:
<xf:js>gtag('event', 'new_review', []);</xf:js>
 
Great news! (y) You can count on me as a user/customer!

Some suggestions / wishes:
  • Tracking new threads getting created
  • Tracking UserGroup for each visitor (I have several UserGroups and it would be helpful to differentiate them in Analytics)
  • Tracking StyleID for each visitor
  • Tracking Search Keywords and Search Results
  • Tracking individual Tags on Thread Views (almost all of my threads have one or more tags) as custom value
  • Extendability for other addons like Ads Manager 2 by @Siropu - this is mostly the most important feature, beeing able to tracking clicks on hidden affiliate links in Google Analytics.
 
Great news! (y) You can count on me as a user/customer!

Some suggestions / wishes:
  • Tracking new threads getting created
Already planned (mentioned it somewhere in a post I think).
  • Tracking UserGroup for each visitor (I have several UserGroups and it would be helpful to differentiate them in Analytics)
This is something I've already been thinking about as well. Not always for every user group, but instead a configuration where you can choose which user groups to do it for. Someone could do it for all if they want, but you wouldn't have to.
  • Tracking StyleID for each visitor
That should be easy fairly easy.
  • Tracking Search Keywords and Search Results
It's already happening. Some of the Enhanced measurement things in the settings (in Google Analytics) for your property data stream work inherently if you turn them on (scrolls, outbound clicks and site search).

1651854596624.webp
Video engagement doesn't work by default because XenForo's BBCode media code for YouTube doesn't enable the JaveScript API support. However, this is something the installation of the addon automatically changes already (it makes slight change to the embed code when the addon is installed to enable it).

File downloads don't work automatically because XenForo doesn't use normal static files with specific file extensions (it uses attachments). Have already worked around this with custom code to do it.

  • Tracking individual Tags on Thread Views (almost all of my threads have one or more tags) as custom value
Once I get custom dimensions sorted out with GA4, it shouldn't be too hard. Like I said, I was already planning on it for user groups, so once that's done, extending it to other things (style ID or thread tags) shouldn't be a big stretch.

  • Extendability for other addons like Ads Manager 2 by @Siropu - this is mostly the most important feature, beeing able to tracking clicks on hidden affiliate links in Google Analytics.
Should be fairly simple for them to do. All they would need to do is add a tiny bit of JavaScript to track custom events (in fact they could do it now with the default Google Analytics setup for XenForo). They wouldn't need to use or extend anything within this addon to do it. That being said, it would be up to them. I'm not going to try and hook into 3rd party addons to make them log things. That's way too much work trying to keep up with other people's addons.
 
Oh, I forgot to mention that custom dimensions for tracking things that can have more than one value concurrently (thread tags, user groups, etc.) is tricky because Google Analytics doesn't allow you to actually give it multiple values. To show what I mean, here's a custom dimension I use to track the category of a blog post. Most have just a single category, but some have more than one category, so your reports don't really reflect properly. Like "Tech Stuff" really had 23 page views there (19 on posts with just a single category, and then another 4 on a post that has another category.

1651857201736.webp

So for something like style ID it's simple, a user can only have one style at a time. Same if you were tracking "forum". A thread can only be in a single forum (like if you wanted to see which forum section got the most page views or something).

For user groups, a viable workaround might be a list of user groups you want to track that is sorted by priority (the highest priority user group is the one it tracks). But in the end, you really would only be tracking one user group per user, rather than multiple.

I've been thinking a little about thread tags, and thinking maybe it's not worth it. The cardinality for thread tags starts to border on infinite because they are user created and normally users can assign multiple per thread. Thread prefixes is probably something better to track on with how Google Analytics is designed (having a single possible prefix per thread).

Things like thread prefix, forum that a thread is in, thread author, etc. are the types of things that would give you useful reporting. Now if Google Analytics ever let you pass in an array of values for a single dimension, that would be amazing, but they don't unfortunately.
 
Once I get custom dimensions sorted out with GA4, it shouldn't be too hard. Like I said, I was already planning on it for user groups, so once that's done, extending it to other things (style ID or thread tags) shouldn't be a big stretch.


Should be fairly simple for them to do. All they would need to do is add a tiny bit of JavaScript to track custom events (in fact they could do it now with the default Google Analytics setup for XenForo). They wouldn't need to use or extend anything within this addon to do it. That being said, it would be up to them. I'm not going to try and hook into 3rd party addons to make them log things. That's way too much work trying to keep up with other people's addons.
Thanks, that sounds great (y)
Oh, I forgot to mention that custom dimensions for tracking things that can have more than one value concurrently (thread tags, user groups, etc.) is tricky because Google Analytics doesn't allow you to actually give it multiple values.

I've been thinking a little about thread tags, and thinking maybe it's not worth it. The cardinality for thread tags starts to border on infinite because they are user created and normally users can assign multiple per thread. Thread prefixes is probably something better to track on with how Google Analytics is designed (having a single possible prefix per thread).

Things like thread prefix, forum that a thread is in, thread author, etc. are the types of things that would give you useful reporting. Now if Google Analytics ever let you pass in an array of values for a single dimension, that would be amazing, but they don't unfortunately.
I see. In my case I (as the Admin) is the only one setting thread tags, but off course there could be more than one per thread, thats true.
 
Okay, so this is where it's at (everything is functional)...

1652980093035.png

Everything can be done automatically via Google Analytics API. For example, to choose your measurement ID, it drills down through your Analytics accounts, then properties. You can also choose to make a new property with a button click (no need to go into Google Analytics account):

1652980291176.png

1652980322509.png

If you create a new property, it will automatically do everything it needs to do (like create a new data stream for that property). It will also create a few custom dimensions via the API automatically (currently there are 9 custom dimensions it created so you can report on things like thread ID, style ID, user ID, etc. in your Analytics reports).

The user group tracking setup has a drag and drop system for setting user group priorities:

1652980500377.png

The main admin area has a realtime widget showing where currently online users are at:

1652980599105.png

Admin area has reporting via API. For example, heatmaps (which can be broken down by metrics and segments):

1652980676682.png

You can generate charts in the admin area that can be broken down by various dimensions (for example this one shows visitors by operating system):

1652980777268.png

The staff bar at the top of public pages for mods/admins gets an analytics icon, that lets you see a chart for just the page you are on:

1652980967288.png

You can see client-side errors that users are getting (which don't register in the normal server error log since they are client-side). For example, I can see how many users have been unable to load the svgz logo or service workers that have been unable to register themselves:

1652981122035.png

You can host the Google Tag Manager JavaScript on your own domain which gives you control over caching (both in user's browsers as well as being able to cache it at the network edge with something like Cloudflare).

The end result is all sorts of interesting data flowing into Google Analytics (content being created, emails being sent/read, sign ups, logins, client-side errors, YouTube videos being watched, user upgrades being purchased/viewed, etc.) You can also drill down on most things if you want. Like emails sent/read allows you to see the email subject, signups and logins allow you to see how (like was it via a connected Google account, Twitter account, email, etc.), content creation events allow you to break them down by the type of content.

I have it running live on one of my sites (inmateintake.com if you didn't notice).

Right now, the holdup is that the Analytics Enhanced Measurement Settings can't be controlled via the Admin API temporarily (it was removed in December and hasn't come back yet). It's not super critical, but it's coming back soon and it's terribly annoying to be doing everything related to property configuration via the Analytics Admin API, but then we can't setup/config the Enhanced Measurement settings, you have to actually go into Analytics account to do that (for now): https://developers.google.com/analytics/devguides/config/admin/v1/changelog

Basically it's makes XenForo go from a boring default consumer style use of Google Analytics to more of an enterprise mode where you can really get detailed insights on events rather than just page views.
 
Top Bottom