Skip to content

data-cookiecategory on script only works the firs time? #497

Answered by orestbida
aldevit asked this question in Q&A
Discussion options

You must be logged in to vote

You cannot change the behavior of the <script> elements. There is no easy way to achieve the end result you'd like to get to, you'd need to adapt each script so that it can be used inside the onAccept and onChange callbacks.

E.g. the following snippet:

<script type="text/plain" data-cookiecategory="analytics">
    // example code
    window.analyticsEnabled = true;
</script>

can be adapted to:

const cc = initCookieConsent();

cc.run({
    // your config ...

    onAccept: () => {
        if(cc.allowedCategory('analytics')) {
            enableAnalytics()
        }
    },
    
    onChange: (cookie, changedCategories) => {
        if(changedCategories.includes('analytics')) {
            if(

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@aldevit
Comment options

@orestbida
Comment options

Answer selected by aldevit
@aldevit
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants