andreas-straub / gatsby-plugin-gdpr-tracking

GDPR conform analytics tracking for Gatsby website
Apache License 2.0
15 stars 5 forks source link

Simple window.trackGoogleAnalytics question #7

Closed klintan closed 3 years ago

klintan commented 3 years ago

Hey! Thanks for a great plugin, makes life much easier 👍

However I have some issues (which is probably wholly dependent on me not really understanding how Gatsby works under the hood)

I was of course thinking that the best way would be that onAccept, just start the hotjar and GAnalytics to begin tracking if accepted, else just keep them off. However, this does not work, window / trackGoogleAnalytics is undefined. Tried using browser-monads but not really sure how that would help to be honest, since that would just make the undefined as well. How would one use the browser globals to do these calls? Do you have an example implementation?

<CookieConsent
        location="bottom"
        onAccept={() => {
          window.trackHotjar();
          window.trackGoogleAnalytics();
        }}
        enableDeclineButton
        buttonText="Yes I accept"
        cookieName="gdpr-analytics-enabled"
        style={{ background: "#2B373B" }}
        buttonStyle={{ color: "#4e503b", fontSize: "13px" }}
        expires={150}
      >
        {intl.formatMessage({ id: "cookie" })}
      </CookieConsent>

Many thanks!

klintan commented 3 years ago

Found the issue, running gatsby develop it won't work, but after you've built it, it seems to work :)

Will close this one.