Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to add an analytics tracking code to Signalen frontend #173

Open
bartjkdp opened this issue Oct 14, 2022 · 3 comments
Open

Ability to add an analytics tracking code to Signalen frontend #173

bartjkdp opened this issue Oct 14, 2022 · 3 comments
Labels
discuss Things we want to discuss with the whole team

Comments

@bartjkdp
Copy link

bartjkdp commented Oct 14, 2022

We would like municipalities to be able to add a tracking code for their analytics solution, so they are able to track pageviews on Signalen.

Possible solution design

Add the ability to mount an additional file in the container (e.g. /extend_body.html). This contents of this file is added to the HTML body in index.html during runtime via start.sh.

The contents of this HTML can then be controlled via a value in the Helm chart:

htmlBodyExtend: |
    <script async src="https://siteimproveanalytics.com/js/siteanalyze_000000.js"></script>

The content of the value can be added to a ConfigMap and mounted on /extend_body.html in the container.

Considerations

  • We could also consider using the existing configuration JSON, but formatting HTML in a JSON value can be challenging.
  • We can consider moving to YAML for the app configuration, then adding HTML as a value can become easier as well.
@bartjkdp bartjkdp added the discuss Things we want to discuss with the whole team label Oct 14, 2022
@boris-arkenaar
Copy link

Sounds good Bart, thanks!

Having all configurations together would be preferable I'd say. HTML in JSON doesn't even have to be that bad, right? Only escape the double quotes. Do you need only one script tag, or is that just an example? Would only the URL be sufficient?

@bartjkdp
Copy link
Author

bartjkdp commented Oct 15, 2022

@boris-arkenaar thanks for the feedback. I think the script tag is just an example, different analytics solutions have different ways of embedding. For example the Matomo code looks like this:

<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$MATOMO_URL}/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>

I agree, it could work to use a JSON value. The Signalen frontend Helm chart allows the values to be configured in YAML and Helm takes care of converting this to JSON. So we won't bother the users of the Helm chart with fiddling the code into JSON.

@OscarBakker
Copy link

@boris-arkenaar thanks for the feedback. I think the script tag is just an example, different analytics solutions have different ways of embedding. For example the Matomo code looks like this:

<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$MATOMO_URL}/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>

I agree, it could work to use a JSON value. The Signalen frontend Helm chart allows the values to be configured in YAML and Helm takes care of converting this to JSON. So we won't bother the users of the Helm chart with fiddling the code into JSON.

Especially these last lines sound convincing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Things we want to discuss with the whole team
Projects
None yet
Development

No branches or pull requests

3 participants