@capillarytech/cap-ui-utils 1.0.2 → 1.0.3

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 ADDED
@@ -0,0 +1,44 @@
1
+ import ReactGA from 'react-ga';
2
+ import ttiPolyfill from 'tti-polyfill';
3
+ import { startTracking, stopTracking } from './utils/timeTracker';
4
+ import { trackException } from './utils/tracker';
5
+
6
+ ReactGA.initialize('UA-152081629-1');
7
+
8
+ //Track Error
9
+ window.addEventListener('error', function(e) {
10
+ trackException(`UI Error ${e.message}`);
11
+ });
12
+
13
+ //Track windo Active and inActive time.
14
+ window.addEventListener('visibilitychange', function() {
15
+ document.hidden ? stopTracking() : startTracking();
16
+ });
17
+
18
+ ttiPolyfill.getFirstConsistentlyInteractive().then(tti => {
19
+ console.log('performance tti', tti);
20
+ });
21
+
22
+ const callback = list => {
23
+ list.getEntries().forEach(entry => {
24
+ console.log('performance callback entry', entry);
25
+ console.log(
26
+ 'performance callback server latentcy',
27
+ entry.responseStart - entry.requestStart,
28
+ );
29
+ console.log(
30
+ 'performance callback download time',
31
+ entry.responseEnd - entry.responseStart,
32
+ );
33
+ console.log(
34
+ 'performance callback load time',
35
+ entry.responseEnd - entry.requestStart,
36
+ );
37
+ });
38
+ };
39
+
40
+ var observer = new PerformanceObserver(callback);
41
+ observer.observe({ entryTypes: ['navigation'] });
42
+ var perfData = window.performance.timing;
43
+ var pageLoadTime = perfData.loadEventEnd - perfData.navigationStart;
44
+ console.log('Performance metrics', perfData, pageLoadTime);
@@ -0,0 +1,39 @@
1
+ import React, { useEffect } from 'react';
2
+ import ReactGA from 'react-ga';
3
+ // import path from '../config/path';
4
+
5
+ // const rootPath = path.publicPath;
6
+
7
+ // const getPageUrl = (component, pageUrl) => {
8
+ // switch (component) {
9
+ // case 'createCampaign':
10
+ // return `${rootPath}/${pageUrl.split('/')[3]}`;
11
+ // case 'messageSummary':
12
+ // return `${rootPath}/campaign/message/view`;
13
+ // case 'campaignMessage':
14
+ // return `${rootPath}/campaign/message/${pageUrl.split('/')[6]}`;
15
+ // case 'campaignReports':
16
+ // return `${rootPath}/campaign/reports`;
17
+ // case 'CampaignDetails':
18
+ // return `${rootPath}/campaign`;
19
+ // default:
20
+ // return pageUrl;
21
+ // }
22
+ // };
23
+ // const withTracker = (WrappedComponent, options = {}, getPageUrl) => {
24
+ const trackPage = pageUrl => {
25
+ const { component } = options;
26
+ const pageView = component ? getPageUrl(component, pageUrl) : pageUrl;
27
+ ReactGA.pageview(pageView);
28
+ };
29
+
30
+ const HOC = props => {
31
+ useEffect(() => trackPage(props.location.pathname), [
32
+ props.location.pathname,
33
+ ]);
34
+ return <WrappedComponent {...props} />;
35
+ };
36
+ return HOC;
37
+ };
38
+
39
+ export default withTracker;
@@ -0,0 +1,50 @@
1
+ import { trackEvent } from './reactGa';
2
+
3
+ let trackableEvents = {};
4
+ let trackingStoppedAt = 0;
5
+ let windowWasInActive = false;
6
+
7
+ let addInactiveTimeToEvents = inActiveInterval => {
8
+ Object.keys(trackableEvents).map(function(key) {
9
+ console.log('tracker', 'adjusted timing for', key);
10
+ trackableEvents[key] += inActiveInterval;
11
+ });
12
+ };
13
+
14
+ export function startTimer(event) {
15
+ console.log('tracker', 'Started timer for ', event);
16
+ trackableEvents[event] = Date.now();
17
+ }
18
+
19
+ export function stopTimer(event, options) {
20
+ const timeTaken = Date.now() - (trackableEvents[event] || 0);
21
+ delete trackableEvents[event];
22
+ console.log('tracker', 'stopped timer for ', event, timeTaken, options);
23
+ //Track the event timing
24
+ if (options) {
25
+ trackEvent({
26
+ category: options.category,
27
+ action: options.action,
28
+ label: options.label,
29
+ value: timeTaken,
30
+ });
31
+ }
32
+ return timeTaken;
33
+ }
34
+
35
+ export function stopTracking() {
36
+ trackingStoppedAt = Date.now();
37
+ windowWasInActive = true;
38
+ console.log('tracker', 'window is inactive');
39
+ }
40
+
41
+ export function startTracking() {
42
+ if (!windowWasInActive) {
43
+ return false;
44
+ }
45
+ const inActiveInterval = Date.now() - trackingStoppedAt;
46
+ console.log('tracker', 'window was inactive for ', inActiveInterval);
47
+ trackingStoppedAt = 0;
48
+ windowWasInActive = false;
49
+ addInactiveTimeToEvents(inActiveInterval);
50
+ }
@@ -0,0 +1,14 @@
1
+ import ReactGA from 'react-ga';
2
+
3
+ export function trackEvent() {}
4
+
5
+ export function trackTiming() {}
6
+
7
+ export function trackPageView() {}
8
+
9
+ export function trackException(description, fatal = true) {
10
+ ReactGA.exception({
11
+ description,
12
+ fatal,
13
+ });
14
+ }
@@ -2,7 +2,7 @@ import React from 'react';
2
2
 
3
3
  const AccessForbidden = props => {
4
4
  return (
5
- <div>AccessForbidden AccessForbidden</div>
5
+ <div>AccessForbidden</div>
6
6
  );
7
7
  };
8
8
 
package/auth/index.js CHANGED
@@ -40,7 +40,6 @@ function _initialize(authConfigs) {
40
40
  * @param authOptions
41
41
  */
42
42
  function initialize(authConfigs, authOptions) {
43
- log("Before initialize 1")
44
43
  if (isEmpty(authConfigs)) {
45
44
  warn("Cannot initialize empty object");
46
45
  return;
@@ -55,7 +54,6 @@ function initialize(authConfigs, authOptions) {
55
54
  return;
56
55
  }
57
56
  }
58
- log("Before initialize")
59
57
  _initialize(authConfigs);
60
58
  return true;
61
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,6 +8,8 @@
8
8
  },
9
9
  "author": "Rajshekar",
10
10
  "dependencies": {
11
- "react": "^16.13.0"
11
+ "react": "^16.13.0",
12
+ "react-ga": "^2.7.0",
13
+ "tti-polyfill": "^0.2.2"
12
14
  }
13
15
  }