Total Complexity | 7 |
Complexity/F | 2.33 |
Lines of Code | 40 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | /* global dataFlyntFeatureGoogleAnalytics, Cookies */ |
||
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 = dataFlyntFeatureGoogleAnalytics |
||
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 | let confirmOptout = false |
||
|
|||
18 | |||
19 | if (data.confirm) { |
||
20 | confirmOptout = window.confirm(data.confirm) |
||
21 | } else { |
||
22 | confirmOptout = true |
||
23 | } |
||
24 | |||
25 | if (confirmOptout) { |
||
26 | window['ga-disable-' + data.gaId] = true |
||
27 | if (data.success) { |
||
28 | window.alert(data.success) |
||
29 | } |
||
30 | setOptoutCookie() |
||
31 | } |
||
32 | }) |
||
33 | } |
||
34 | |||
35 | function setOptoutCookie () { |
||
36 | Cookies.set('disableGa', true) |
||
37 | $gaOptoutLinks.remove() |
||
38 | } |
||
39 | |||
40 | function getOptoutCookie () { |
||
41 | return Cookies.get('disableGa') |
||
42 | } |
||
43 |