@ascua/metrics 0.0.236 → 0.0.238

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import Metric from './base';
2
2
  import { assert } from '@ember/debug';
3
3
  import script from '@ascua/metrics/utils/facebook-pixel';
4
4
 
5
- const src = 'script[src*="fbevents.js"]';
5
+ const src = 'script[src*="facebook"]';
6
6
 
7
7
  export default class extends Metric {
8
8
 
@@ -2,7 +2,7 @@ import Metric from './base';
2
2
  import { assert } from '@ember/debug';
3
3
  import script from '@ascua/metrics/utils/google-tag-manager';
4
4
 
5
- const src = 'script[src*="googletagmanager"]';
5
+ const src = 'script[src*="gtm"]';
6
6
 
7
7
  export default class extends Metric {
8
8
 
@@ -12,7 +12,7 @@ export default class extends Metric {
12
12
 
13
13
  super.init(...arguments);
14
14
 
15
- if (window.gt) return;
15
+ if (window.gtm) return;
16
16
 
17
17
  if (!this.config.id) return;
18
18
 
@@ -25,7 +25,7 @@ export default class extends Metric {
25
25
  break;
26
26
  }
27
27
 
28
- window.gt = function(data) { window.dataLayer.push(data); };
28
+ window.gtm = function() { window.dataLayer.push(arguments); };
29
29
 
30
30
  }
31
31
 
@@ -35,33 +35,31 @@ export default class extends Metric {
35
35
  e.parentElement.removeChild(e);
36
36
  });
37
37
 
38
- delete window.dataLayer;
39
-
40
- delete window.gt;
38
+ delete window.gtm;
41
39
 
42
40
  }
43
41
 
44
42
  clear() {
45
43
 
46
- if (!window.gt) return;
44
+ if (!window.gtm) return;
47
45
 
48
- window.gt({ 'event': 'clear' });
46
+ window.gtm({ 'event': 'clear' });
49
47
 
50
48
  }
51
49
 
52
50
  identify(id) {
53
51
 
54
- if (!window.gt) return;
52
+ if (!window.gtm) return;
55
53
 
56
54
  assert(`You must pass an 'id' as the first argument to ${this.toString()}:identify()`, id);
57
55
 
58
- window.gt({ 'event': 'identify', 'userId': id });
56
+ window.gtm({ 'event': 'identify', 'userId': id });
59
57
 
60
58
  }
61
59
 
62
60
  trackEvent(name, data) {
63
61
 
64
- if (!window.gt) return;
62
+ if (!window.gtm) return;
65
63
 
66
64
  assert(`You must pass a 'name' as the first argument to ${this.toString()}:trackEvent()`, name);
67
65
 
@@ -69,7 +67,7 @@ export default class extends Metric {
69
67
  event: name,
70
68
  });
71
69
 
72
- window.gt(event);
70
+ window.gtm(event);
73
71
 
74
72
  }
75
73
 
@@ -0,0 +1,74 @@
1
+ import Metric from './base';
2
+ import { assert } from '@ember/debug';
3
+ import script from '@ascua/metrics/utils/gtag';
4
+
5
+ const src = 'script[src*="gtag"]';
6
+
7
+ export default class extends Metric {
8
+
9
+ name = 'gtag';
10
+
11
+ init() {
12
+
13
+ super.init(...arguments);
14
+
15
+ if (window.gtag) return;
16
+
17
+ if (!this.config.id) return;
18
+
19
+ switch (this.config.optimised) {
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
+ }
27
+
28
+ window.gtag = function() { window.dataLayer.push(arguments); };
29
+
30
+ gtag('js', new Date());
31
+
32
+ gtag('config', 'G-J1NWM32T1V');
33
+
34
+ }
35
+
36
+ willDestroy() {
37
+
38
+ document.querySelectorAll(src).forEach(e => {
39
+ e.parentElement.removeChild(e);
40
+ });
41
+
42
+ delete window.gtag;
43
+
44
+ }
45
+
46
+ clear() {
47
+
48
+ if (!window.gtag) return;
49
+
50
+ window.gtag({ 'event': 'clear' });
51
+
52
+ }
53
+
54
+ identify(id) {
55
+
56
+ if (!window.gtag) return;
57
+
58
+ assert(`You must pass an 'id' as the first argument to ${this.toString()}:identify()`, id);
59
+
60
+ window.gtag({ 'event': 'identify', 'userId': id });
61
+
62
+ }
63
+
64
+ trackEvent(name, data) {
65
+
66
+ if (!window.gtag) return;
67
+
68
+ assert(`You must pass a 'name' as the first argument to ${this.toString()}:trackEvent()`, name);
69
+
70
+ window.gtag(name, data);
71
+
72
+ }
73
+
74
+ }
@@ -0,0 +1,79 @@
1
+ import Metric from './base';
2
+ import { assert } from '@ember/debug';
3
+ import script from '@ascua/metrics/utils/twitter-pixel';
4
+
5
+ const src = 'script[src*="twitter"]';
6
+
7
+ export default class extends Metric {
8
+
9
+ name = 'twitter-pixel';
10
+
11
+ init() {
12
+
13
+ super.init(...arguments);
14
+
15
+ if (window.twq) return;
16
+
17
+ if (!this.config.id) return;
18
+
19
+ switch (this.config.optimised) {
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
+ }
27
+
28
+ window.twq('config', this.config.id);
29
+
30
+ }
31
+
32
+ willDestroy() {
33
+
34
+ document.querySelectorAll(src).forEach(e => {
35
+ e.parentElement.removeChild(e);
36
+ });
37
+
38
+ delete window.twq;
39
+ delete window._twq;
40
+
41
+ }
42
+
43
+ clear() {
44
+
45
+ if (!window.twq) return;
46
+
47
+ window.twq('config', this.config.id);
48
+
49
+ }
50
+
51
+ identify(id, data) {
52
+
53
+ if (!window.twq) return;
54
+
55
+ assert(`You must pass an 'id' as the first argument to ${this.toString()}:identify()`, id);
56
+
57
+ window.twq('config', this.config.id, { external_id: id, ...data });
58
+
59
+ }
60
+
61
+ trackPage(data) {
62
+
63
+ if (!window.twq) return;
64
+
65
+ window.twq('event', 'PageView', data);
66
+
67
+ }
68
+
69
+ trackEvent(name, data) {
70
+
71
+ if (!window.twq) return;
72
+
73
+ assert(`You must pass a 'name' as the first argument to ${this.toString()}:trackEvent()`, name);
74
+
75
+ window.twq('event', name, data);
76
+
77
+ }
78
+
79
+ }
@@ -0,0 +1,45 @@
1
+ export function original(config) {
2
+
3
+ /* eslint-disable */
4
+ (function(w,d,s,l,i){w[l]=w[l]||[];var f=d.getElementsByTagName(s)[0],
5
+ j=d.createElement(s);j.async=true;j.src=
6
+ 'https://www.googletagmanager.com/gtag/js?id='+i;f.parentNode.insertBefore(j,f);
7
+ })(window,document,'script','dataLayer',config.id);
8
+ /* eslint-enable */
9
+
10
+ }
11
+
12
+ export function optimised(config) {
13
+
14
+ /* eslint-disable */
15
+ window.dataLayer = window.dataLayer || [];
16
+ /* eslint-enable */
17
+
18
+ if (document.readyState === 'complete') {
19
+
20
+ let script = document.createElement('script');
21
+ script.src = `https://www.googletagmanager.com/gtag/js?id=${config.id}`;
22
+ script.async = false;
23
+ script.defer = true;
24
+ document.head.appendChild(script);
25
+
26
+ } else {
27
+
28
+ document.addEventListener('readystatechange', function(event) {
29
+ if (event.target.readyState === 'complete') {
30
+ let script = document.createElement('script');
31
+ script.src = `https://www.googletagmanager.com/gtag/js?id=${config.id}`;
32
+ script.async = false;
33
+ script.defer = true;
34
+ document.head.appendChild(script);
35
+ }
36
+ });
37
+
38
+ }
39
+
40
+ }
41
+
42
+ export default {
43
+ original,
44
+ optimised,
45
+ }
@@ -0,0 +1,45 @@
1
+ export function original(config) {
2
+
3
+ /* eslint-disable */
4
+ !function(e,t,n,s,u,a){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
5
+ },s.version='1.1',s.queue=[],u=t.createElement(n),u.async=!0,u.src='https://static.ads-twitter.com/uwt.js',
6
+ a=t.getElementsByTagName(n)[0],a.parentNode.insertBefore(u,a))}(window,document,'script');
7
+ /* eslint-enable */
8
+
9
+ }
10
+
11
+ export function optimised(config) {
12
+
13
+ /* eslint-disable */
14
+ !function(e,s){e.twq||(s=e.twq=function(){s.exe?s.exe.apply(s,arguments):s.queue.push(arguments);
15
+ },s.version='1.1',s.queue=[])}(window);
16
+ /* eslint-enable */
17
+
18
+ if (document.readyState === 'complete') {
19
+
20
+ let script = document.createElement('script');
21
+ script.src = 'https://static.ads-twitter.com/uwt.js';
22
+ script.async = false;
23
+ script.defer = true;
24
+ document.head.appendChild(script);
25
+
26
+ } else {
27
+
28
+ document.addEventListener('readystatechange', function(event) {
29
+ if (event.target.readyState === 'complete') {
30
+ let script = document.createElement('script');
31
+ script.src = 'https://static.ads-twitter.com/uwt.js';
32
+ script.async = false;
33
+ script.defer = true;
34
+ document.head.appendChild(script);
35
+ }
36
+ });
37
+
38
+ }
39
+
40
+ }
41
+
42
+ export default {
43
+ original,
44
+ optimised,
45
+ }
@@ -0,0 +1 @@
1
+ export { default } from '@ascua/metrics/metrics/gtag';
@@ -0,0 +1 @@
1
+ export { default } from '@ascua/metrics/metrics/twitter-pixel';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ascua/metrics",
3
- "version": "0.0.236",
3
+ "version": "0.0.238",
4
4
  "description": "Small description for @ascua/metrics goes here",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "32a6fad3bdce42d5a7819adcbb5312a22d4316c2"
28
+ "gitHead": "c69b7174d17ae756556f9a48371b61859d18c237"
29
29
  }