backdrop-contrib / matomo

Adds the tracking code for Matomo Analytics to your Backdrop CMS site.
https://backdropcms.org/project/matomo
GNU General Public License v2.0
3 stars 5 forks source link

Add option to install no script tracker #21

Closed Wylbur closed 2 years ago

Wylbur commented 2 years ago

Matomo provides an option for installing a no script image tracker.
https://matomo.org/faq/how-to/faq_176/

This is a feature request to add this as a feature to the Matomo module.

indigoxela commented 2 years ago

That seems feasible, we just need a setting in the admin form and then add a noscript tag to the tracking code like that:

<img src="https://matomo.example.org/matomo.php?idsite={$IDSITE}&amp;rec=1" style="border:0" alt="" />
indigoxela commented 2 years ago

A PR is available for testing. Caution, it's a "quick shot", don't use on production yet. Note: update.php needs to be run.

Wylbur commented 2 years ago

Confirming that the js script checkbox appears, and does generate noscript snippet.

Thanks for adding this so quickly!

indigoxela commented 2 years ago

Thanks for adding this so quickly!

We're not completely done yet.

When creating the PR, I wondered, why the port uses hook_preprocess_layout() instead of hook_preprocess_page(). The D version uses hook_page_alter(), which doesn't exist in B. However, the B equivalent would be hook_preprocess_page (not layout).

@hosef Do you happen to remember, why you chose the layout preprocessor instead of the page preprocessor?

It didn't matter until now, as the hook only adds js (backdrop_add_js can be done in many places). The noscript tag needs real markup in the page, though, and outside the layout (in page_bottom). So now the module has to implement two hooks, which seems inefficient. I'd like to combine all in hook_preprocess_page(), which is a bigger change. So I'd like to know the reason for the previous hook choice.

indigoxela commented 2 years ago

FTR: I got answer from @hosef in the chat - he doesn't remember why and hook_preprocess_page is also OK.