Dan0sz / host-analytics-locally

Automagically download analytics.js, keep it updated using WordPress' built-in Cron-schedule, generate the tracking code, add it to your site's header or footer and tons of other features!
https://daan.dev/wordpress-plugins/caos/
MIT License
11 stars 5 forks source link

allow for script attributes by adding a filter #1

Closed rlankhorst closed 4 years ago

rlankhorst commented 4 years ago

Hi Daan,

I've just created a branch here with a feature request: https://github.com/rlankhorst/host-analytics-locally/tree/allow-for-script-attributes-manipulation

I'm the developer of Complianz GDPR. I know that in your plugin a user can configure a cookiebanner cookie which in our case would be cmplz_stats = 'allow'

This would work fine, except in the US, where no consent is needed: in that case there is no cookie yet, and the plugin should already start tracking. When using Geo IP, this would cause issues for websites.

In Complianz I add a class to the script element, either class="cmplz-native" (never block, in case of anonymous configuration) or class="cmplz-stats" (block until statistics level consent is given).

Currently your plugin does not offer the option to add classes to the script element. To make it more generic I've called the filter 'caos_script_attributes'.

Would it be possible add this filter so we can dynamically add the correct class?

rlankhorst commented 4 years ago

My previous pull request was on my own fork I see. I just tried updating it, but the pull request was a bit to old, so it's now full of commits that shouldn't be there. Better to delete my pull request.

The only thing I changed was to replace in class-tracking.php: echo "<script $snippetType src='$localFileUrl' >";

with $scriptAttributes = apply_filters('caos_script_attributes', ''); echo "<script $snippetType src='$localFileUrl' $scriptAttributes>";

Dan0sz commented 4 years ago

Hi @rlankhorst!

It's been added in v3.1.2. I made some modifications of my own, so I didn't merge your pull request.

But you should be able to add additional script attributes using the appropriate filter!

rlankhorst commented 4 years ago

Great! Thanks :)

Op wo 8 jan. 2020 om 14:11 schreef Daan van den Bergh < notifications@github.com>:

Hi @rlankhorst https://github.com/rlankhorst!

It's been added in v3.1.2. I made some modifications of my own, so I didn't merge your pull request.

But you should be able to add additional script attributes using the appropriate filter!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Dan0sz/host-analytics-locally/issues/1?email_source=notifications&email_token=AGANZWXRCTN4HPOP5M6B6U3Q4XGHBA5CNFSM4JGXZ42KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIMLHWI#issuecomment-572044249, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGANZWQ4ZSBKLTWZLFCYZ2DQ4XGHBANCNFSM4JGXZ42A .

rlankhorst commented 4 years ago

@Dan0sz I noticed this filter seems to have been dropped in a recent update, which breaks our integration. Is it possible to bring a generic filter back which would enable us to conditionally allow the script to run? A generic filter which would add attributes to every used script would be great.

Alternatively, the consent API could be used, it's now moved to feature plugin (https://make.wordpress.org/core/features/), and is expected to get merged into WP core with 5.6, or (more likely) 5.7. Using the Consent API will make the plugin work with every Cookie banner plugin with wp consent api integration (currently Complianz and Cookiebot).