aesirx-analytics 1.0.6 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +18 -9
- package/dist/analytics.js +11 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +5 -0
- package/package.json +13 -36
- package/build/analytics.js +0 -1
- package/build/lib/bundles/bundle.esm.min.js +0 -2
- package/build/lib/bundles/bundle.esm.min.js.map +0 -1
- package/build/lib/cjs/AnalyticsNext/handle.js +0 -119
- package/build/lib/cjs/AnalyticsNext/handle.js.map +0 -1
- package/build/lib/cjs/AnalyticsNext/index.js +0 -51
- package/build/lib/cjs/AnalyticsNext/index.js.map +0 -1
- package/build/lib/cjs/AnalyticsReact/handle.js +0 -77
- package/build/lib/cjs/AnalyticsReact/handle.js.map +0 -1
- package/build/lib/cjs/AnalyticsReact/index.js +0 -51
- package/build/lib/cjs/AnalyticsReact/index.js.map +0 -1
- package/build/lib/cjs/analytics.js +0 -197
- package/build/lib/cjs/analytics.js.map +0 -1
- package/build/lib/cjs/index.js +0 -35
- package/build/lib/cjs/index.js.map +0 -1
- package/build/lib/cjs/utils/AnalyticsContextProvider.js +0 -39
- package/build/lib/cjs/utils/AnalyticsContextProvider.js.map +0 -1
- package/build/lib/cjs/utils/index.js +0 -202
- package/build/lib/cjs/utils/index.js.map +0 -1
- package/build/lib/cjs/utils/services.js +0 -51
- package/build/lib/cjs/utils/services.js.map +0 -1
- package/build/lib/esm/AnalyticsNext/handle.js +0 -124
- package/build/lib/esm/AnalyticsNext/handle.js.map +0 -1
- package/build/lib/esm/AnalyticsNext/index.js +0 -56
- package/build/lib/esm/AnalyticsNext/index.js.map +0 -1
- package/build/lib/esm/AnalyticsReact/handle.js +0 -82
- package/build/lib/esm/AnalyticsReact/handle.js.map +0 -1
- package/build/lib/esm/AnalyticsReact/index.js +0 -56
- package/build/lib/esm/AnalyticsReact/index.js.map +0 -1
- package/build/lib/esm/analytics.js +0 -198
- package/build/lib/esm/analytics.js.map +0 -1
- package/build/lib/esm/index.js +0 -35
- package/build/lib/esm/index.js.map +0 -1
- package/build/lib/esm/utils/AnalyticsContextProvider.js +0 -45
- package/build/lib/esm/utils/AnalyticsContextProvider.js.map +0 -1
- package/build/lib/esm/utils/index.js +0 -206
- package/build/lib/esm/utils/index.js.map +0 -1
- package/build/lib/esm/utils/services.js +0 -54
- package/build/lib/esm/utils/services.js.map +0 -1
- package/build/lib/types/AnalyticsNext/handle.d.ts +0 -3
- package/build/lib/types/AnalyticsNext/handle.d.ts.map +0 -1
- package/build/lib/types/AnalyticsNext/index.d.ts +0 -3
- package/build/lib/types/AnalyticsNext/index.d.ts.map +0 -1
- package/build/lib/types/AnalyticsReact/handle.d.ts +0 -3
- package/build/lib/types/AnalyticsReact/handle.d.ts.map +0 -1
- package/build/lib/types/AnalyticsReact/index.d.ts +0 -3
- package/build/lib/types/AnalyticsReact/index.d.ts.map +0 -1
- package/build/lib/types/index.d.ts +0 -5
- package/build/lib/types/index.d.ts.map +0 -1
- package/build/lib/types/index.min.js +0 -1
- package/build/lib/types/utils/AnalyticsContextProvider.d.ts +0 -3
- package/build/lib/types/utils/AnalyticsContextProvider.d.ts.map +0 -1
- package/build/lib/types/utils/index.d.ts +0 -5
- package/build/lib/types/utils/index.d.ts.map +0 -1
- package/build/lib/types/utils/services.d.ts +0 -2
- package/build/lib/types/utils/services.d.ts.map +0 -1
- package/src/AnalyticsNext/handle.js +0 -58
- package/src/AnalyticsNext/index.js +0 -30
- package/src/AnalyticsReact/handle.js +0 -39
- package/src/AnalyticsReact/index.js +0 -29
- package/src/analytics.js +0 -155
- package/src/index.js +0 -4
- package/src/utils/AnalyticsContextProvider.js +0 -17
- package/src/utils/index.js +0 -126
- package/src/utils/services.js +0 -20
package/src/utils/index.js
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
import { trackerService } from './services';
|
2
|
-
import Bowser from 'bowser';
|
3
|
-
|
4
|
-
const createRequest = (endpoint, task) => {
|
5
|
-
return `${endpoint}/visitor/v1/${task}`;
|
6
|
-
};
|
7
|
-
|
8
|
-
/* FUNCTION */
|
9
|
-
const initTracker = async (endpoint, url, referrer, user_agent) => {
|
10
|
-
const { document } = window;
|
11
|
-
const { pathname, search, origin } = location;
|
12
|
-
url = `${origin}${pathname}${search}`;
|
13
|
-
referrer = document.referrer;
|
14
|
-
user_agent = window.navigator.userAgent;
|
15
|
-
const browser = Bowser.parse(window.navigator.userAgent);
|
16
|
-
const browser_name = browser?.browser?.name;
|
17
|
-
const browser_version = browser?.browser?.version;
|
18
|
-
const lang = window.navigator.userLanguage || window.navigator.language;
|
19
|
-
const device = browser?.platform?.model ?? browser?.platform?.type;
|
20
|
-
const domain = `${origin}`;
|
21
|
-
const queryString = window.location.search;
|
22
|
-
const urlParams = new URLSearchParams(queryString);
|
23
|
-
let attributes = [];
|
24
|
-
for (var key of urlParams.keys()) {
|
25
|
-
if (key.startsWith('utm_')) {
|
26
|
-
urlParams.get(key) && attributes.push({ name: key, value: urlParams.get(key) });
|
27
|
-
}
|
28
|
-
}
|
29
|
-
if (!urlParams.get('event_uuid') && !urlParams.get('visitor_uuid')) {
|
30
|
-
let ip = '';
|
31
|
-
const response = await trackerService(createRequest(endpoint, 'init'), {
|
32
|
-
url: url,
|
33
|
-
referrer: referrer,
|
34
|
-
user_agent: user_agent,
|
35
|
-
ip: ip,
|
36
|
-
domain: domain,
|
37
|
-
browser_name: browser_name,
|
38
|
-
browser_version: browser_version,
|
39
|
-
lang: lang,
|
40
|
-
device: device,
|
41
|
-
event_name: 'visit',
|
42
|
-
event_type: 'action',
|
43
|
-
attributes: attributes,
|
44
|
-
});
|
45
|
-
return response;
|
46
|
-
}
|
47
|
-
};
|
48
|
-
|
49
|
-
const startTracker = async (endpoint, event_uuid, visitor_uuid, referrer) => {
|
50
|
-
const { location, document } = window;
|
51
|
-
referrer = referrer
|
52
|
-
? location.protocol + '//' + location.host + referrer
|
53
|
-
: document.referrer.split('?')[0];
|
54
|
-
const url = location.protocol + '//' + location.host + location.pathname;
|
55
|
-
const queryString = window.location.search;
|
56
|
-
const urlParams = new URLSearchParams(queryString);
|
57
|
-
const responseStart = await trackerService(createRequest(endpoint, 'start'), {
|
58
|
-
...(urlParams.get('event_uuid') && {
|
59
|
-
event_uuid: urlParams.get('event_uuid'),
|
60
|
-
}),
|
61
|
-
...(urlParams.get('visitor_uuid') && {
|
62
|
-
visitor_uuid: urlParams.get('visitor_uuid'),
|
63
|
-
}),
|
64
|
-
...(event_uuid && {
|
65
|
-
event_uuid: event_uuid,
|
66
|
-
}),
|
67
|
-
...(visitor_uuid && {
|
68
|
-
visitor_uuid: visitor_uuid,
|
69
|
-
}),
|
70
|
-
referrer: referrer === '/' ? '' : referrer,
|
71
|
-
url: url,
|
72
|
-
});
|
73
|
-
|
74
|
-
return responseStart;
|
75
|
-
};
|
76
|
-
|
77
|
-
const endTracker = async (endpoint, event_uuid, visitor_uuid) => {
|
78
|
-
const queryString = window.location.search;
|
79
|
-
const urlParams = new URLSearchParams(queryString);
|
80
|
-
const responseEnd = await trackerService(createRequest(endpoint, 'end'), {
|
81
|
-
...(urlParams.get('event_uuid_start') && {
|
82
|
-
event_uuid: urlParams.get('event_uuid_start'),
|
83
|
-
}),
|
84
|
-
...(urlParams.get('visitor_uuid_start') && {
|
85
|
-
visitor_uuid: urlParams.get('visitor_uuid_start'),
|
86
|
-
}),
|
87
|
-
...(event_uuid && {
|
88
|
-
event_uuid: event_uuid,
|
89
|
-
}),
|
90
|
-
...(visitor_uuid && {
|
91
|
-
visitor_uuid: visitor_uuid,
|
92
|
-
}),
|
93
|
-
});
|
94
|
-
return responseEnd;
|
95
|
-
};
|
96
|
-
|
97
|
-
const trackEvent = async (endpoint, event_uuid, visitor_uuid, referrer, data) => {
|
98
|
-
const { location, document } = window;
|
99
|
-
referrer = referrer
|
100
|
-
? location.protocol + '//' + location.host + referrer
|
101
|
-
: document.referrer.split('?')[0];
|
102
|
-
const url = location.protocol + '//' + location.host + location.pathname;
|
103
|
-
const queryString = window.location.search;
|
104
|
-
const urlParams = new URLSearchParams(queryString);
|
105
|
-
const responseStart = await trackerService(createRequest(endpoint, 'start'), {
|
106
|
-
...(urlParams.get('event_uuid') && {
|
107
|
-
event_uuid: urlParams.get('event_uuid'),
|
108
|
-
}),
|
109
|
-
...(urlParams.get('visitor_uuid') && {
|
110
|
-
visitor_uuid: urlParams.get('visitor_uuid'),
|
111
|
-
}),
|
112
|
-
...(event_uuid && {
|
113
|
-
event_uuid: event_uuid,
|
114
|
-
}),
|
115
|
-
...(visitor_uuid && {
|
116
|
-
visitor_uuid: visitor_uuid,
|
117
|
-
}),
|
118
|
-
referrer: referrer === '/' ? '' : referrer,
|
119
|
-
url: url,
|
120
|
-
...data,
|
121
|
-
});
|
122
|
-
|
123
|
-
return responseStart;
|
124
|
-
};
|
125
|
-
|
126
|
-
export { initTracker, startTracker, endTracker, trackEvent };
|
package/src/utils/services.js
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
/* SERVICES */
|
2
|
-
let cache;
|
3
|
-
const assign = (a, b) => {
|
4
|
-
Object.keys(b).forEach((key) => {
|
5
|
-
if (b[key] !== undefined) a[key] = b[key];
|
6
|
-
});
|
7
|
-
return a;
|
8
|
-
};
|
9
|
-
|
10
|
-
const trackerService = async (endpoint, payload) => {
|
11
|
-
const fetchData = await fetch(endpoint, {
|
12
|
-
method: 'POST',
|
13
|
-
body: JSON.stringify(payload),
|
14
|
-
headers: assign({ 'Content-Type': 'application/json' }, { ['x-tracker-cache']: cache }),
|
15
|
-
});
|
16
|
-
const response = await fetchData.json();
|
17
|
-
return response;
|
18
|
-
};
|
19
|
-
|
20
|
-
export { trackerService };
|