Add Google Analytics support - #24
navin-mohan wants to merge 1 commit into
Conversation
ebkalderon
left a comment
There was a problem hiding this comment.
Thanks a lot for your submission! My apologies for the delayed code review; life has been pretty busy lately. 😅
| <script async src="https://www.googletagmanager.com/gtag/js?id={{ config.extra.google_analytics_id }}"></script> | ||
| <script> |
There was a problem hiding this comment.
Unfortunately, these <script> tags will won't work for users with CSP enabled without some modifications. I think we could assign a SHA-256 hash/nonce to the inline <script> tag if config.extra.content_security_policy.enable == true, and update templates/partials/content_security_policy.html accordingly to allow scripts with that same hash/nonce and scripts from the googletagmanager.com domain to run if the Google Analytics ID is enabled and set. Any thoughts?
| {%- if config.extra.fediverse_creator %} | ||
| <meta name="fediverse:creator" content="{{ config.extra.fediverse_creator }}"> | ||
| {%- endif -%} | ||
| {%- if config.extra.google_analytics_id -%} |
There was a problem hiding this comment.
If we're going to integrate first-party support for web analytics into this Zola theme, I think it would be wise to ensure the public API is decoupled from any specific service. IMO, the way Tabi approaches this is pretty ideal (documentation).
[extra.analytics]
service = "google-analytics"
id = "G-XXXXXXXXXX"There's no need to refactor the Tera templates to be Google Analytics agnostic as part of this PR, if you don't want to (that work can always be done later, if we eventually add support for a 2nd or 3rd analytics provider someday). But at least making the theme.toml API match the above format would be wonderful. ❤️
And if you can, please consider updating the theme.toml with some documentation as well. That would be most appreciated!
Adds a new extra config
google_analytics_idwhich when set will include Google Analytics tracking script.