I´d like to disable a local JS. I´ve tried some variations, but only one works. Does anybody have an idea please?

I use: Opt-in with categories.

Machine readable name of category is: analyse_marketing

Path to JS:
sites/default/files/google_tag/google_tagmanager/google_tag.script.js

Do not work:
analyse_marketing:public://google_tag/google_tagmanager/google_tag.script.js
analyse_marketing:sites/default/files/google_tag/google_tagmanager/google_tag.script.js
analyse_marketing:/sites/default/files/google_tag/google_tagmanager/google_tag.script.js
analyse_marketing:https://www.mydomain.com/sites/default/files/google_tag/google_tagmanage...

Work:
http://www.mydomain.com/sites/default/files/google_tag/google_tagmanager...

Comments

beg76 created an issue. See original summary.

beg76’s picture

It also do not prevent loading other external scripts like Smartlook or Google TagManager.

If i put

in Disable Javascript field, it still loads the JS without giving consent.

svenryen’s picture

@beg76, which modules provide the scripts that you link to in your last comment?

svenryen’s picture

I take it this is the module https://www.drupal.org/project/smartlook_tracking. I'll see if I can install it and help you out.

johnzzon’s picture

We're using the GoogleTagManager module (https://www.drupal.org/project/google_tag) and it looks like @beg76 uses the same (at least the path to the script is the same)

This module uses hook_page_attachments() to add the script in the head, so the script is not available in hook_js_alter() from what I can tell.

Added related issue of that module.

svenryen’s picture

FWIW, I checked, and I was able to exclude and load the script using:

analyse_marketing:/sites/default/files/google_tag/google_tagmanager/google_tag.script.js

There's a bug though, which causes scripts to be appended and load even though the category hasn't been accepted. (Edit: The bug was caused by having a category with machine name 0).

svenryen’s picture

And I just realised this bug was reported in 7.x and not 8.x. I'll have a look and see what can be done to improve this feature in 7.x.

svenryen’s picture

Status: Active » Closed (works as designed)

I was able to exclude the script in D7 as well.

The setting to use is:

analyse_marketing:https://www.mydomain.com/sites/default/files/google_tag/google_tagmanager/google_tag.script.js If that doesn't work, try http:// instead of https://.

Smartlook uses inline css, so you'll have to use hook_page_alter() to exclude that script, and then a javascript function to load the script on the jQuery event eu_cookie_compliance.changeStatus. If you have issues setting that up, the company I work for offers paid support for handling that scenario. Shouldn't take too many hours.

johnzzon’s picture

Yeah, I can confirm that it did work. I didn't notice any cookies from Google Analytics, but I think that was due to being on a different domain than the GTM was configured for. I can see the script being loaded properly when clicking accept on a category.