Skip to content

Commit

Permalink
fix(FeatureGoogleAnalytics): Fixed boolean logic and window.$
Browse files Browse the repository at this point in the history
  • Loading branch information
Juhan Soone committed Nov 20, 2019
1 parent 068900b commit 26a8e5a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions Components/FeatureGoogleAnalytics/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FeatureGoogleAnalytics extends window.HTMLDivElement {
}

init () {
this.$ = window.$(this)
this.$ = $(this)
this.props = this.getInitialProps()
this.resolveElements()
this.bindFunctions()
Expand Down Expand Up @@ -56,12 +56,12 @@ class FeatureGoogleAnalytics extends window.HTMLDivElement {
}

isOptedOut () {
return !!Cookies.get(this.disableStr)
return Cookies.get(this.disableStr) === true
}

setStatus (status) {
window[this.disableStr] = status
Cookies.set(this.disableStr, status)
window[this.disableStr] = !status
Cookies.set(this.disableStr, !status)
this.defineGlobalGAFunction()
}

Expand All @@ -70,18 +70,10 @@ class FeatureGoogleAnalytics extends window.HTMLDivElement {
this.setStatus(status)
}

loagGAScript () {
if (!this.scriptLoaded) {
this.scriptLoaded = true
const scriptUrl = `https://www.googletagmanager.com/gtag/js?id=${this.gaId}`
$.getScript(scriptUrl)
}
}

defineGlobalGAFunction () {
let gtag
if (this.isOptedOut()) {
gtag = function () {}
gtag = function () { }
} else if (this.gaId === 'debug') {
gtag = function () {
console.log('GoogleAnalytics', [].slice.call(arguments))
Expand Down

0 comments on commit 26a8e5a

Please sign in to comment.