Implement twig template for tracking code customization

Created on 10 July 2019, over 5 years ago
Updated 6 July 2023, over 1 year ago

Based on Matomo issue: #2948060: Implement twig template for tracking code customization β†’ - thanks to the author @pfrenssen!

Problem/Motivation

We would like to be able to customize the Javascript code that is generated by the module. There can be many use cases for wanting to override the JS, but we want to achieve the following:

  • We are hosting a large number of websites in an internal "Drupal SaaS platform" which all share the same code base. For these sites we are serving the JS from a CDN that accepts many of the GA parameters but in a different format. For example if we enable link tracking in a site we need this to be rendered as a URL parameter that is appended to the CDN URL (eg. &enableLinkTracking), instead of '(i[r].q=i[r].q||[]).push(['enableLinkTracking]).

Proposed resolution

Currently the generation of the JS is performed in hardcoded PHP code in google_analytics_page_attachments(). Refactor this to use a twig template instead, so we can use preprocessors to alter existing parameters, as well as override the template in case more drastic changes are needed. We can move much of the logic to a preprocess function, and put the if/else switches in the Twig template itself.

Remaining tasks

Discuss if this is would be useful and wanted in the Google Analytics project.

User interface changes

None.

API changes

None. The output for existing users would remain exactly the same, but it will be overridable if needed.

Data model changes

None.

✨ Feature request
Status

Closed: outdated

Version

3.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO

    With the sunset of legacy google analytics, the 8.x-3.x module is now unsupported. If this is still an issue with the 4.x version, please file a new issue in the queue.

Production build 0.71.5 2024