@capillarytech/cap-ui-utils 1.0.6 → 1.0.8

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.
package/GA/index.js CHANGED
@@ -7,9 +7,8 @@ import isEmpty from '../utils/isEmpty';
7
7
 
8
8
  import warn from '../utils/console/warn';
9
9
  import log from '../utils/console/log';
10
- import { trackException } from './utils/tracker';
11
10
 
12
- function _initialize(GAConfigs) {
11
+ const _initialize = (GAConfigs) => {
13
12
  if (!GAConfigs.accessKey) {
14
13
  warn("Cannot initialize GA without accessKey");
15
14
  return;
@@ -17,9 +16,16 @@ function _initialize(GAConfigs) {
17
16
  if(GAConfigs.accessKey) {
18
17
  ReactGA.initialize(GAConfigs.accessKey,{debug: true,}); //UA-152081629-1
19
18
  }
19
+ if(GAConfigs.trackError){
20
+ //Track Error
21
+ window.addEventListener('error', (e) =>{
22
+ tracker.trackException(`UI Error ${e.message}`);
23
+ });
24
+ }
25
+ eventsAfterInitialize();
20
26
  log("Cap GA initialized");
21
27
  }
22
- function initialize(GAConfigs) {
28
+ const initialize = (GAConfigs) =>{
23
29
  if (isEmpty(GAConfigs)) {
24
30
  warn("Cannot initialize empty object");
25
31
  return;
@@ -31,47 +37,46 @@ function initialize(GAConfigs) {
31
37
  }
32
38
  }
33
39
  _initialize(GAConfigs);
40
+
34
41
  return true;
35
42
  }
43
+ const eventsAfterInitialize = () => {
36
44
 
37
- //Track Error
38
- window.addEventListener('error', function(e) {
39
- tracker.trackException(`UI Error ${e.message}`);
40
- });
45
+ //Track windo Active and inActive time.
46
+ window.addEventListener('visibilitychange', ()=> {
47
+ const { startTracking, stopTracking } = timeTracker;
48
+ document.hidden ? stopTracking() : startTracking();
49
+ });
50
+ }
41
51
 
42
- //Track windo Active and inActive time.
43
- window.addEventListener('visibilitychange', function() {
44
- const { startTracking, stopTracking } = timeTracker;
45
- document.hidden ? stopTracking() : startTracking();
46
- });
47
52
 
48
53
  // ttiPolyfill.getFirstConsistentlyInteractive().then(tti => {
49
54
  // console.log('performance tti', tti);
50
55
  // });
51
56
 
52
- const callback = list => {
53
- list.getEntries().forEach(entry => {
54
- console.log('performance callback entry', entry);
55
- console.log(
56
- 'performance callback server latentcy',
57
- entry.responseStart - entry.requestStart,
58
- );
59
- console.log(
60
- 'performance callback download time',
61
- entry.responseEnd - entry.responseStart,
62
- );
63
- console.log(
64
- 'performance callback load time',
65
- entry.responseEnd - entry.requestStart,
66
- );
67
- });
68
- };
57
+ // const callback = list => {
58
+ // list.getEntries().forEach(entry => {
59
+ // console.log('performance callback entry', entry);
60
+ // console.log(
61
+ // 'performance callback server latentcy',
62
+ // entry.responseStart - entry.requestStart,
63
+ // );
64
+ // console.log(
65
+ // 'performance callback download time',
66
+ // entry.responseEnd - entry.responseStart,
67
+ // );
68
+ // console.log(
69
+ // 'performance callback load time',
70
+ // entry.responseEnd - entry.requestStart,
71
+ // );
72
+ // });
73
+ // };
69
74
 
70
- var observer = new PerformanceObserver(callback);
71
- observer.observe({ entryTypes: ['navigation'] });
72
- var perfData = window.performance.timing;
73
- var pageLoadTime = perfData.loadEventEnd - perfData.navigationStart;
74
- console.log('Performance metrics', perfData, pageLoadTime);
75
+ // var observer = new PerformanceObserver(callback);
76
+ // observer.observe({ entryTypes: ['navigation'] });
77
+ // var perfData = window.performance.timing;
78
+ // var pageLoadTime = perfData.loadEventEnd - perfData.navigationStart;
79
+ // console.log('Performance metrics', perfData, pageLoadTime);
75
80
 
76
81
  export default{
77
82
  initialize,
@@ -1,49 +1,48 @@
1
1
 
2
2
  // import ReactGA from 'react-ga';
3
3
  import tracker from './tracker'
4
+ import log from '../../utils/console/log'
4
5
  let trackableEvents = {};
5
6
  let trackingStoppedAt = 0;
6
7
  let windowWasInActive = false;
7
8
  const {trackEvent}= tracker;
8
9
  let addInactiveTimeToEvents = inActiveInterval => {
9
- Object.keys(trackableEvents).map(function(key) {
10
- console.log('tracker', 'adjusted timing for', key);
10
+ Object.keys(trackableEvents).forEach((key) =>{
11
11
  trackableEvents[key] += inActiveInterval;
12
12
  });
13
13
  };
14
14
 
15
- function startTimer(event) {
16
- console.log('tracker', 'Started timer for ', event);
15
+ const startTimer = (event) => {
16
+ log(`tracker Started timer for ${event}` );
17
17
  trackableEvents[event] = Date.now();
18
18
  }
19
- function stopTimer(event, options) {
19
+ const stopTimer = (event, options) =>{
20
20
  const timeTaken = Date.now() - (trackableEvents[event] || 0);
21
21
  delete trackableEvents[event];
22
- console.log('tracker', 'stopped timer for ', event, timeTaken, options);
22
+ log(`tracker stopped timer for ${event} ${timeTaken} ${options}` );
23
23
  //Track the event timing
24
+ const { category , action, label } =options;
24
25
  if (options) {
25
26
  trackEvent({
26
- category: options.category,
27
- action: options.action,
28
- label: options.label,
27
+ category: category,
28
+ action: action,
29
+ label: label,
29
30
  value: timeTaken,
30
31
  });
31
32
  }
32
33
  return timeTaken;
33
34
  }
34
35
 
35
- function stopTracking() {
36
+ const stopTracking = () =>{
36
37
  trackingStoppedAt = Date.now();
37
38
  windowWasInActive = true;
38
- console.log('tracker', 'window is inactive');
39
39
  }
40
40
 
41
- function startTracking() {
41
+ const startTracking = () =>{
42
42
  if (!windowWasInActive) {
43
43
  return false;
44
44
  }
45
45
  const inActiveInterval = Date.now() - trackingStoppedAt;
46
- console.log('tracker', 'window was inactive for ', inActiveInterval);
47
46
  trackingStoppedAt = 0;
48
47
  windowWasInActive = false;
49
48
  addInactiveTimeToEvents(inActiveInterval);
@@ -1,14 +1,14 @@
1
1
  import ReactGA from 'react-ga';
2
2
 
3
- function trackEvent(options) {
3
+ const trackEvent = (options)=> {
4
4
  ReactGA.event(options);
5
5
  }
6
6
 
7
- function trackTiming() {}
7
+ const trackTiming = () => {}
8
8
 
9
- function trackPageView() {}
9
+ const trackPageView = () => {}
10
10
 
11
- function trackException(description, fatal = true) {
11
+ const trackException = (description, fatal = true) => {
12
12
  ReactGA.exception({
13
13
  description,
14
14
  fatal,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {