i've replaced an earlier package that writes for the "ga.js" library with `g_analytics_writer` - a unified way to generate *simple* tracking analytics for "Google Analytics" in Pyramid apps.
It offers a unified API for 'telling the package what to track', then will generate optimized analytics tracking code for any of 3 available versions (ga.js, analytics.js, gtag.js)
for pyramid, you just configure environment.ini with:
g_analytics_writer.account_id = UA-123123123-1
include the package:
config.include('g_analytics_writer')
which will add a `g_analytics_writer` object to the pyramid request.
and update template with (mako):
${request.g_analytics_writer.render()|n}
It supports custom variables, ecommerce transactions, simple events, sending to multiple trackers and some other things. it's fully tested and works on Python 2 & 3.
This has been a bit of a pain to write, as I had to do a lot of testing to figure out how to minimize the amount of external API calls on each platform.
This was written to handle our concerns/needs on an upgrade/migration from `ga.js`, but I'd be happy to extend the capabilities if I have time (or take PRs)