Completed
Push — Feature-GoogleAnalyticsOptout ( 12176c )
by
unknown
02:06
created

Features/GoogleAnalytics/script.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 33
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 2
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 5
mnd 2
bc 6
fnc 3
bpm 2
cpm 1.6666
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A script.js ➔ setOptoutCookie 0 4 1
A $gaOptoutLinks.click 0 11 2
A script.js ➔ getOptoutCookie 0 3 1
1
/* global wpData, Cookies */
2
3
import $ from 'jquery'
4
import 'file-loader?name=vendor/js-cookie.js!js-cookie/src/js.cookie'
5
6
const $gaOptoutLinks = $('.globalAction-optoutGa')
7
const data = wpData
8
9
const alreadyOptedOut = getOptoutCookie()
10
11
if (alreadyOptedOut) {
12
  $gaOptoutLinks.remove()
13
  window['ga-disable-' + data.gaId] = true
14
} else {
15
  $gaOptoutLinks.on('click', function (e) {
16
    e.preventDefault()
17
18
    const confirmOptout = window.confirm(data.confirm)
19
20
    if (confirmOptout) {
21
      window['ga-disable-' + data.gaId] = true
22
      window.alert(data.success)
23
      setOptoutCookie()
24
    }
25
  })
26
}
27
28
function setOptoutCookie () {
29
  Cookies.set('disableGa', true)
30
  $gaOptoutLinks.remove()
31
}
32
33
function getOptoutCookie () {
34
  return Cookies.get('disableGa')
35
}
36