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

[Bug]: Scripts with data-category are running before cookies are accepted #699

Closed
eduardsv opened this issue Jun 21, 2024 · 4 comments
Closed
Labels
invalid This doesn't seem right

Comments

@eduardsv
Copy link

eduardsv commented Jun 21, 2024

Expected Behavior

Scripts that have data-category argument provided should be blocked until user accepts cookie consent message.

Current Behavior

Scripts are running on page load, before user accepts cookie consent message.

Steps to reproduce

I have recreated this issue on StackBlitz

Additional info

When I've tried recreating this issue on CodePen, everything works as expected

Version

3.0.1

On which browser do you see the issue?

Firefox, Chrome, Safari

@eduardsv eduardsv added the bug Something isn't working label Jun 21, 2024
@github-actions github-actions bot added the triage yet to be reviewed label Jun 21, 2024
@orestbida
Copy link
Owner

The data-category attribute is merely used to assign a category to the script; it does not block the script tag. The only way to block a script tag is by changing the 'type' attribute to a non valid javascript mime type, such as type="text/plain".

Your script tags should look like this instead:

<script type="text/plain" data-category="ads">
    document.getElementById("console-log").innerHTML+= "--- Running ads script ---<br>"
</script>
<script type="text/plain" data-category="analytics">
    document.getElementById("console-log").innerHTML+= "--- Running analytics script ---<br>"
</script>

On Codepen it looks like it's working but it's actually not. Here is the console log of codepen:

Uncaught TypeError: Cannot read properties of null (reading 'innerHTML') 
 at https://cdpn.io/cpe/boomboom/index.html?editors=1011&key=index.html-a0bc11d5-7e23-4633-fa28-055e547dd9ad:32
Uncaught TypeError: Cannot read properties of null (reading 'innerHTML') 
 at https://cdpn.io/cpe/boomboom/index.html?editors=1011&key=index.html-a0bc11d5-7e23-4633-fa28-055e547dd9ad:35

@orestbida orestbida added invalid This doesn't seem right and removed bug Something isn't working triage yet to be reviewed labels Jun 21, 2024
@eduardsv
Copy link
Author

I see... It should've been obvious, but I haven't thought about that at all.

Thanks a lot for your help and for a great product!

@shibusahu30
Copy link

how do you unblock these scripts once user gives consent?

@orestbida
Copy link
Owner

@shibusahu30 they are enabled by the plugin through this function:

const loadScriptsHelper = (scripts, index) => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants