@ascua/metrics 0.3.8 → 0.3.10

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.
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  window.amplitude.getInstance().init(this.config.id);
@@ -1,5 +1,4 @@
1
1
  import Object from '@ember/object';
2
- import { assert } from '@ember/debug';
3
2
 
4
3
  export default class extends Object {
5
4
 
@@ -9,12 +8,12 @@ export default class extends Object {
9
8
  return `metric:${this.name}`;
10
9
  }
11
10
 
12
- clear() {}
11
+ clear() { }
13
12
 
14
- identify(/*id, data*/) {}
13
+ identify(/*id, data*/) { }
15
14
 
16
- trackPage(/*data*/) {}
15
+ trackPage(/*data*/) { }
17
16
 
18
- trackEvent(/*name, data*/) {}
17
+ trackEvent(/*name, data*/) { }
19
18
 
20
19
  }
@@ -0,0 +1,35 @@
1
+ import Metric from './base';
2
+ import script from '@ascua/metrics/utils/clarity';
3
+
4
+ const src = 'script[src*="clarity"]';
5
+
6
+ export default class extends Metric {
7
+
8
+ name = 'clarity';
9
+
10
+ init() {
11
+
12
+ super.init(...arguments);
13
+
14
+ if (!this.config.id) return;
15
+
16
+ switch (this.config.optimised) {
17
+ case true:
18
+ script.optimised(this.config);
19
+ break;
20
+ default:
21
+ script.original(this.config);
22
+ break;
23
+ }
24
+
25
+ }
26
+
27
+ willDestroy() {
28
+
29
+ document.querySelectorAll(src).forEach(e => {
30
+ e.parentElement.removeChild(e);
31
+ });
32
+
33
+ }
34
+
35
+ }
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  }
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  window.fbq('init', this.config.id);
@@ -17,15 +17,15 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
- window.gtm = function() { window.dataLayer.push(arguments); };
28
+ window.gtm = function () { window.dataLayer.push(arguments); };
29
29
 
30
30
  }
31
31
 
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  window._gs(this.config.id, false);
@@ -17,15 +17,15 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
- window.gtag = function() { window.dataLayer.push(arguments); };
28
+ window.gtag = function () { window.dataLayer.push(arguments); };
29
29
 
30
30
  gtag('js', new Date());
31
31
 
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  }
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  window.Intercom('boot', { app_id: this.config.id });
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  }
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  window.rg4js('apiKey', this.config.id);
@@ -17,12 +17,12 @@ export default class extends Metric {
17
17
  if (!this.config.id) return;
18
18
 
19
19
  switch (this.config.optimised) {
20
- case true:
21
- script.optimised(this.config);
22
- break;
23
- default:
24
- script.original(this.config);
25
- break;
20
+ case true:
21
+ script.optimised(this.config);
22
+ break;
23
+ default:
24
+ script.original(this.config);
25
+ break;
26
26
  }
27
27
 
28
28
  window.twq('config', this.config.id);
@@ -0,0 +1,42 @@
1
+ export function original(config) {
2
+
3
+ /* eslint-disable */
4
+ (function(c,l,a,r,i,t,y){
5
+ c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
6
+ t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
7
+ y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
8
+ })(window, document, "clarity", "script", config.id);
9
+ /* eslint-enable */
10
+
11
+ }
12
+
13
+ export function optimised(config) {
14
+
15
+ if (document.readyState === 'complete') {
16
+
17
+ let script = document.createElement('script');
18
+ script.src = `https://www.clarity.ms/tag/${config.id}`;
19
+ script.async = false;
20
+ script.defer = true;
21
+ document.head.appendChild(script);
22
+
23
+ } else {
24
+
25
+ document.addEventListener('readystatechange', function(event) {
26
+ if (event.target.readyState === 'complete') {
27
+ let script = document.createElement('script');
28
+ script.src = `https://www.clarity.ms/tag/${config.id}`;
29
+ script.async = false;
30
+ script.defer = true;
31
+ document.head.appendChild(script);
32
+ }
33
+ });
34
+
35
+ }
36
+
37
+ }
38
+
39
+ export default {
40
+ original,
41
+ optimised,
42
+ }
@@ -0,0 +1 @@
1
+ export { default } from '@ascua/metrics/metrics/clarity';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ascua/metrics",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
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": "bec02f4cc22f0a2b67a4f307683da15e112f357e"
28
+ "gitHead": "b1cc09bc0228d44d2118fedb6849f95cf4d86060"
29
29
  }
@@ -1,105 +0,0 @@
1
- import Metric from './base';
2
- import { assert } from '@ember/debug';
3
- import script from '@ascua/metrics/utils/google-analytics';
4
-
5
- const src = 'script[src*="google-analytics"]';
6
-
7
- export default class extends Metric {
8
-
9
- name = 'google-analytics';
10
-
11
- init() {
12
-
13
- super.init(...arguments);
14
-
15
- if (window.ga) 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.ga('create', this.config.id, 'auto');
29
-
30
- if (this.config.trace === true) {
31
- window.ga_debug = { trace: true };
32
- }
33
-
34
- if (this.config.sendHitTask === false) {
35
- window.ga('set', 'sendHitTask', null);
36
- }
37
-
38
- if (this.config.require) {
39
- [].concat(this.config.require).forEach(plugin => {
40
- window.ga('require', plugin);
41
- });
42
- }
43
-
44
- }
45
-
46
- willDestroy() {
47
-
48
- document.querySelectorAll(src).forEach(e => {
49
- e.parentElement.removeChild(e);
50
- });
51
-
52
- delete window.ga;
53
-
54
- }
55
-
56
- clear() {
57
-
58
- if (!window.ga) return;
59
-
60
- window.ga('set', 'userId', null);
61
-
62
- }
63
-
64
- identify(id) {
65
-
66
- if (!window.ga) return;
67
-
68
- assert(`You must pass an 'id' as the first argument to ${this.toString()}:identify()`, id);
69
-
70
- window.ga('set', 'userId', id);
71
-
72
- }
73
-
74
- trackPage(data) {
75
-
76
- if (!window.ga) return;
77
-
78
- let event = Object.assign({}, data, {
79
- hitType: 'pageview',
80
- });
81
-
82
- window.ga('set', 'page', location.pathname);
83
-
84
- window.ga('send', event);
85
-
86
- }
87
-
88
- trackEvent(name, data) {
89
-
90
- if (!window.ga) return;
91
-
92
- assert(`You must pass a 'name' as the first argument to ${this.toString()}:trackEvent()`, name);
93
-
94
- let defaults = { eventCategory: 'Undefined' };
95
-
96
- let event = Object.assign({}, defaults, data, {
97
- hitType: 'event',
98
- eventAction: name,
99
- });
100
-
101
- window.ga('send', event);
102
-
103
- }
104
-
105
- }
@@ -1,47 +0,0 @@
1
- export function original(config) {
2
-
3
- /* eslint-disable */
4
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
5
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
6
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
7
- })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
8
- /* eslint-enable */
9
-
10
- }
11
-
12
- export function optimised(config) {
13
-
14
- /* eslint-disable */
15
- (function(i,r){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
16
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();
17
- })(window,'ga');
18
- /* eslint-enable */
19
-
20
- if (document.readyState === 'complete') {
21
-
22
- let script = document.createElement('script');
23
- script.src = 'https://www.google-analytics.com/analytics.js';
24
- script.async = false;
25
- script.defer = true;
26
- document.head.appendChild(script);
27
-
28
- } else {
29
-
30
- document.addEventListener('readystatechange', function(event) {
31
- if (event.target.readyState === 'complete') {
32
- let script = document.createElement('script');
33
- script.src = 'https://www.google-analytics.com/analytics.js';
34
- script.async = false;
35
- script.defer = true;
36
- document.head.appendChild(script);
37
- }
38
- });
39
-
40
- }
41
-
42
- }
43
-
44
- export default {
45
- original,
46
- optimised,
47
- }
@@ -1 +0,0 @@
1
- export { default } from '@ascua/metrics/metrics/google-analytics';