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

Does not work #3

Open
donaldboulton opened this issue Mar 21, 2019 · 4 comments
Open

Does not work #3

donaldboulton opened this issue Mar 21, 2019 · 4 comments

Comments

@donaldboulton
Copy link

No cookiehub scripts added, you do not even use cookieshub in your own website, nor any other cookie compliance scripts.
All the starters that say they use this do not and why not.
Working example of your work is needed, but no one does that anymore and that really a problem with the whole internet programming community.
Show me!

@oliviergenevest
Copy link

Same issue, can't make it work, can you provide a working example ? thanks

@jordiup
Copy link

jordiup commented Sep 26, 2019

Correct, the plugin seems to suck.

For anyone trying to use Cookiehub see the gatsby docs for adding the script inline:

https://www.gatsbyjs.org/docs/custom-html/#adding-custom-javascript

Finally got it working.

@VirtualFox0
Copy link

VirtualFox0 commented Jan 5, 2020

The plugin didn't work for me too and I don't want to integrate cookiehub usinghtml.js, because of the limitations.

Now, I integrated cookiehub with my own react component:

import React from "react"
import Helmet from 'react-helmet';

const CookieBannerCookieHub = ({ googleTrackingId, cookieHubId }) => {
    const googleUrl = "https://www.googletagmanager.com/gtag/js?id=" + googleTrackingId
    const cookieHubUrl = "https://cookiehub.net/cc/" + cookieHubId + ".js"
    return (
        <Helmet 
            script={[
                { 
                    type: "text/javascript", 
                    src: googleUrl 
                },
                { 
                    type: "text/javascript", 
                    innerHTML: 
                        `var gtagId = '`+googleTrackingId+`';
                        window['ga-disable-' + gtagId] = true;
                        window.dataLayer = window.dataLayer || [];
                        function gtag(){dataLayer.push(arguments)}
                        gtag('js', new Date());`
                },
                { 
                    type: "text/javascript", 
                    src: cookieHubUrl 
                },
                { 
                    type: "text/javascript", 
                    innerHTML: 
                        `window.addEventListener("load", function() {
                            window.cookieconsent.initialise({
                            onInitialise: function(status) {
                                if (this.hasConsented('required')) {
                                }
                                if (this.hasConsented('analytics')) {
                                    window['ga-disable-`+googleTrackingId+`'] = false;
                                    gtag('config', gtagId);
                                }
                                if (this.hasConsented('marketing')) {
                                }
                            },
                            onAllow: function(category) {
                                if (category == 'required') {
                                }
                                if (category == 'analytics') {
                                    window['ga-disable-`+googleTrackingId+`'] = false;
                                    gtag('config', gtagId);
                                }
                                if (category == 'marketing') {
                                }
                            },
                            onRevoke: function(category) {
                                if (category == 'required') {
                                }
                                if (category == 'analytics') {
                                    window['ga-disable-`+googleTrackingId+`'] = true;
                                }
                                if (category == 'marketing') {
                                }
                            }
                        })
                    });`
                }
            ]}
        />
    )
}

export default CookieBannerCookieHub

Within layout.js or another place you can use the component easily:

<CookieBannerCookieHub googleTrackingId="<YOUR TRACKING ID>" cookieHubId="<YOUR COOKIEHUB ID>"/>

I published this small component: https://github.com/VirtualFox0/react-cookiehub-banner

@mikejw
Copy link

mikejw commented Sep 13, 2021

It didn't work for me either!

I decided to inject the JavaScript into the <head>, using react-helmet and also the static directory feature of Gatsby.

<Helmet>
  <script src="/cookies.js" type="text/javascript" />
</Helmet>

(According to this SO answer.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants