tomdyson / wagalytics

A Google Analytics dashboard in your Wagtail admin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple site GA_ID support

jeffreyckchau opened this issue · comments

With the work that's being done in Wagtail to support multiple sites per installation, are there any plans to update this package to allow a Wagtail instance to support multiple Google Analytics IDs and View IDs? That feature would be a huge help to us.

Right now we're hacking a solution by pulling in a specific ID from the site specific settings object using a cached request, but I don't think our approach would be general enough to reflect back into the upstream repository. I would love to get some input on ways to approach multitenancy in wagalytics.

I'm approaching this via custom Wagtail settings, but also hacking a solution that I'm not sure could serve as a common denominator. So here is my long-winded +1!

Here's what my approach has been so far:

  • I have an AnalyticsSettings Wagtail settings class that defines fields like my View ID
  • I replaced settings.GA_VIEW_ID with a settings.GA_VIEW_ID_SETTING constant that contains a string identifying the setting and attribute with the View ID, e.g. GA_VIEW_ID_SETTING = 'app.AnalyticsSettings.google_analytics_view_id'
  • In wagalytics.views, I've added a get_view_id_from_settings() function that breaks the above string down to fetch the actual attribute value via get_model() and getattr()

We are multi-tenanted owing to separate schemas, but Wagtail settings are site specific so I think think the above holds true for multi-site based mutli-tenancy.

From what I've done so far, I don't see an obvious way to now get the View ID into the insert_editor_js hook that displays the page counts on editing pages, but this isn't a feature we are currently using. I wonder if this is part of the reason you arrived at using a cached request.