@proveanything/smartlinks 1.7.10 → 1.8.0
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/README.md +3 -0
- package/dist/api/analytics.d.ts +57 -0
- package/dist/api/analytics.js +542 -0
- package/dist/api/auth.d.ts +23 -35
- package/dist/api/auth.js +104 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/docs/API_SUMMARY.md +575 -40
- package/dist/docs/analytics-metadata-conventions.md +80 -0
- package/dist/docs/analytics.md +690 -0
- package/dist/docs/interactions.md +2 -0
- package/dist/docs/overview.md +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/openapi.yaml +856 -128
- package/dist/types/analytics.d.ts +307 -0
- package/dist/types/analytics.js +7 -1
- package/dist/types/auth.d.ts +67 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/docs/API_SUMMARY.md +575 -40
- package/docs/analytics-metadata-conventions.md +80 -0
- package/docs/analytics.md +690 -0
- package/docs/interactions.md +2 -0
- package/docs/overview.md +2 -1
- package/openapi.yaml +856 -128
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ If you're new to the SDK, this is the easiest path:
|
|
|
21
21
|
### Pick a guide
|
|
22
22
|
|
|
23
23
|
- [docs/ai.md](docs/ai.md) — AI responses, chat, RAG, voice, streaming, and product assistants
|
|
24
|
+
- [docs/analytics.md](docs/analytics.md) — fire-and-forget web analytics, tag scan telemetry, and dashboard queries
|
|
24
25
|
- [docs/widgets.md](docs/widgets.md) — embeddable React components
|
|
25
26
|
- [docs/realtime.md](docs/realtime.md) — subscriptions and live updates
|
|
26
27
|
- [docs/iframe-responder.md](docs/iframe-responder.md) — iframe integration and parent/child messaging
|
|
@@ -29,6 +30,7 @@ If you're new to the SDK, this is the easiest path:
|
|
|
29
30
|
### Most common use cases
|
|
30
31
|
|
|
31
32
|
- **Build an AI assistant** → start with [docs/ai.md](docs/ai.md)
|
|
33
|
+
- **Track page views, clicks, or tag scans** → start with [docs/analytics.md](docs/analytics.md)
|
|
32
34
|
- **Fetch collections/products** → see [Quick start](README.md#quick-start)
|
|
33
35
|
- **Authenticate admins or end users** → see [Authentication](README.md#authentication)
|
|
34
36
|
- **Upload and manage files** → see [Assets](README.md#assets)
|
|
@@ -39,6 +41,7 @@ For the full list of functions and types, see the API summary:
|
|
|
39
41
|
|
|
40
42
|
**Documentation:**
|
|
41
43
|
- [AI & Chat Completions](docs/ai.md) - Chat completions, RAG, voice integration
|
|
44
|
+
- [Analytics](docs/analytics.md) - Fire-and-forget analytics tracking, tag scans, and dashboard queries
|
|
42
45
|
- [Widgets](docs/widgets.md) - Embeddable React components
|
|
43
46
|
- [Realtime](docs/realtime.md) - Realtime data updates
|
|
44
47
|
- [iframe Responder](docs/iframe-responder.md) - iframe integration
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { AnalyticsTrackOptions, AnalyticsTrackResult, AnalyticsBrowserConfig, AnalyticsGeolocationCaptureOptions, AnalyticsLinkClickInput, AnalyticsLinkBindingOptions, AnalyticsPageViewBindingOptions, AnalyticsClassicReportRequest, AnalyticsVisitorIdOptions, CollectionAnalyticsEvent, TagAnalyticsEvent, AnalyticsSummaryRequest, AnalyticsSummaryResponse, AnalyticsTimeseriesRequest, AnalyticsTimeseriesResponse, AnalyticsBreakdownRequest, AnalyticsBreakdownResponse, AnalyticsEventsRequest, AnalyticsEventsResponse, LegacyAnalyticsRequest, AnalyticsDashboardResponse, AnalyticsProductsResponse, AnalyticsQrCodesResponse, AnalyticsTagsResponse, AnalyticsWeeklyRequest, AnalyticsCountryRequest } from "../types/analytics";
|
|
2
|
+
export type { AnalyticsTrackOptions, AnalyticsTrackResult, AnalyticsBrowserConfig, AnalyticsGeolocationCaptureOptions, AnalyticsLinkClickInput, AnalyticsLinkBindingOptions, AnalyticsPageViewBindingOptions, AnalyticsClassicReportRequest, AnalyticsVisitorIdOptions, CollectionAnalyticsEvent, TagAnalyticsEvent, AnalyticsSummaryRequest, AnalyticsSummaryResponse, AnalyticsTimeseriesRequest, AnalyticsTimeseriesResponse, AnalyticsBreakdownRequest, AnalyticsBreakdownResponse, AnalyticsEventsRequest, AnalyticsEventsResponse, LegacyAnalyticsRequest, AnalyticsDashboardResponse, AnalyticsProductsResponse, AnalyticsQrCodesResponse, AnalyticsTagsResponse, AnalyticsWeeklyRequest, AnalyticsCountryRequest, };
|
|
3
|
+
export declare namespace analytics {
|
|
4
|
+
namespace collection {
|
|
5
|
+
/**
|
|
6
|
+
* Fire-and-forget collection analytics event.
|
|
7
|
+
* Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
|
|
8
|
+
*/
|
|
9
|
+
function track(event: CollectionAnalyticsEvent, options?: AnalyticsTrackOptions): AnalyticsTrackResult;
|
|
10
|
+
}
|
|
11
|
+
namespace tag {
|
|
12
|
+
/**
|
|
13
|
+
* Fire-and-forget tag analytics event.
|
|
14
|
+
* Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
|
|
15
|
+
*/
|
|
16
|
+
function track(event: TagAnalyticsEvent, options?: AnalyticsTrackOptions): AnalyticsTrackResult;
|
|
17
|
+
}
|
|
18
|
+
namespace browser {
|
|
19
|
+
function configure(config: AnalyticsBrowserConfig): void;
|
|
20
|
+
function getSessionId(): string | undefined;
|
|
21
|
+
function getVisitorId(): string | undefined;
|
|
22
|
+
function setVisitorId(visitorId: string, options?: AnalyticsVisitorIdOptions): string;
|
|
23
|
+
function clearVisitorId(options?: Pick<AnalyticsVisitorIdOptions, 'storage' | 'storageKey'>): void;
|
|
24
|
+
function captureCampaignParams(search?: string): Partial<CollectionAnalyticsEvent>;
|
|
25
|
+
function setLocation(location: TagAnalyticsEvent['location'] | null): void;
|
|
26
|
+
function clearLocation(): void;
|
|
27
|
+
function getLocation(): TagAnalyticsEvent['location'] | undefined;
|
|
28
|
+
function detectDevice(): CollectionAnalyticsEvent['deviceType'];
|
|
29
|
+
function captureLocation(options?: AnalyticsGeolocationCaptureOptions): Promise<TagAnalyticsEvent['location'] | null>;
|
|
30
|
+
function trackCollection(event: Partial<CollectionAnalyticsEvent>, options?: AnalyticsTrackOptions): AnalyticsTrackResult;
|
|
31
|
+
function trackTag(event: Partial<TagAnalyticsEvent>, options?: AnalyticsTrackOptions): AnalyticsTrackResult;
|
|
32
|
+
function trackPageView(event: Partial<CollectionAnalyticsEvent>, options?: AnalyticsTrackOptions): AnalyticsTrackResult;
|
|
33
|
+
function trackLinkClick(event: AnalyticsLinkClickInput, options?: AnalyticsTrackOptions): AnalyticsTrackResult;
|
|
34
|
+
function trackTagScan(event: Partial<TagAnalyticsEvent>, options?: AnalyticsTrackOptions): AnalyticsTrackResult;
|
|
35
|
+
function bindPageViews(binding?: AnalyticsPageViewBindingOptions): () => void;
|
|
36
|
+
function bindLinkTracking(binding?: AnalyticsLinkBindingOptions): () => void;
|
|
37
|
+
}
|
|
38
|
+
namespace admin {
|
|
39
|
+
function summary(collectionId: string, body: AnalyticsSummaryRequest): Promise<AnalyticsSummaryResponse>;
|
|
40
|
+
function timeseries(collectionId: string, body: AnalyticsTimeseriesRequest): Promise<AnalyticsTimeseriesResponse>;
|
|
41
|
+
function breakdown(collectionId: string, body: AnalyticsBreakdownRequest): Promise<AnalyticsBreakdownResponse>;
|
|
42
|
+
function events(collectionId: string, body: AnalyticsEventsRequest): Promise<AnalyticsEventsResponse>;
|
|
43
|
+
function web(collectionId: string, body?: LegacyAnalyticsRequest): Promise<AnalyticsDashboardResponse>;
|
|
44
|
+
function clicks(collectionId: string, body?: LegacyAnalyticsRequest): Promise<AnalyticsDashboardResponse>;
|
|
45
|
+
function tagScans(collectionId: string, body?: LegacyAnalyticsRequest): Promise<AnalyticsDashboardResponse>;
|
|
46
|
+
function products(collectionId: string, body?: LegacyAnalyticsRequest): Promise<AnalyticsProductsResponse>;
|
|
47
|
+
function qrCodes(collectionId: string, body?: LegacyAnalyticsRequest): Promise<AnalyticsQrCodesResponse>;
|
|
48
|
+
function tags(collectionId: string, body?: LegacyAnalyticsRequest): Promise<AnalyticsTagsResponse>;
|
|
49
|
+
function weekly(collectionId: string, body?: AnalyticsWeeklyRequest): Promise<AnalyticsTimeseriesResponse>;
|
|
50
|
+
function country(collectionId: string, body?: AnalyticsCountryRequest): Promise<AnalyticsBreakdownResponse>;
|
|
51
|
+
function topPages(collectionId: string, body?: AnalyticsClassicReportRequest): Promise<AnalyticsBreakdownResponse>;
|
|
52
|
+
function topReferrers(collectionId: string, body?: AnalyticsClassicReportRequest): Promise<AnalyticsBreakdownResponse>;
|
|
53
|
+
function topCampaigns(collectionId: string, body?: AnalyticsClassicReportRequest): Promise<AnalyticsBreakdownResponse>;
|
|
54
|
+
function topSources(collectionId: string, body?: AnalyticsClassicReportRequest): Promise<AnalyticsBreakdownResponse>;
|
|
55
|
+
function topDestinations(collectionId: string, body?: AnalyticsClassicReportRequest): Promise<AnalyticsBreakdownResponse>;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { post, getBaseURL, getApiHeaders } from "../http";
|
|
13
|
+
const analyticsBrowserState = {
|
|
14
|
+
config: {
|
|
15
|
+
sessionStorageKey: 'smartlinks.analytics.sessionId',
|
|
16
|
+
visitorStorage: 'local',
|
|
17
|
+
visitorStorageKey: 'smartlinks.analytics.visitorId',
|
|
18
|
+
autoCaptureCampaignParams: true,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
const defaultCampaignParamMap = {
|
|
22
|
+
utmSource: ['utm_source', 'utmSource'],
|
|
23
|
+
utmMedium: ['utm_medium', 'utmMedium'],
|
|
24
|
+
utmCampaign: ['utm_campaign', 'utmCampaign'],
|
|
25
|
+
utmContent: ['utm_content', 'utmContent'],
|
|
26
|
+
utmTerm: ['utm_term', 'utmTerm'],
|
|
27
|
+
entryType: ['entryType', 'entry'],
|
|
28
|
+
group: 'group',
|
|
29
|
+
tag: 'tag',
|
|
30
|
+
campaign: 'campaign',
|
|
31
|
+
placement: 'placement',
|
|
32
|
+
linkGroup: ['linkGroup', 'link_group'],
|
|
33
|
+
linkPlacement: ['linkPlacement', 'link_placement'],
|
|
34
|
+
linkPosition: ['linkPosition', 'link_position'],
|
|
35
|
+
linkTitle: ['linkTitle', 'link_title'],
|
|
36
|
+
destinationDomain: ['destinationDomain', 'destination_domain'],
|
|
37
|
+
pagePath: ['pagePath', 'page_path'],
|
|
38
|
+
pageId: 'pageId',
|
|
39
|
+
qrCodeId: 'qrCodeId',
|
|
40
|
+
scanMethod: ['scanMethod', 'scan_method'],
|
|
41
|
+
};
|
|
42
|
+
function createSessionId() {
|
|
43
|
+
return `${Date.now()}_${Math.floor(Math.random() * 1000000)}`;
|
|
44
|
+
}
|
|
45
|
+
function createVisitorId() {
|
|
46
|
+
return `visitor_${Date.now()}_${Math.floor(Math.random() * 1000000)}`;
|
|
47
|
+
}
|
|
48
|
+
function getStorage(mode) {
|
|
49
|
+
try {
|
|
50
|
+
if (mode === 'local' && typeof localStorage !== 'undefined')
|
|
51
|
+
return localStorage;
|
|
52
|
+
if (mode === 'session' && typeof sessionStorage !== 'undefined')
|
|
53
|
+
return sessionStorage;
|
|
54
|
+
}
|
|
55
|
+
catch (_a) {
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
function getOrCreateSessionId() {
|
|
60
|
+
var _a, _b, _c, _d;
|
|
61
|
+
if (analyticsBrowserState.sessionId)
|
|
62
|
+
return analyticsBrowserState.sessionId;
|
|
63
|
+
const key = (_a = analyticsBrowserState.config.sessionStorageKey) !== null && _a !== void 0 ? _a : 'smartlinks.analytics.sessionId';
|
|
64
|
+
const storage = getStorage('session');
|
|
65
|
+
const existing = key ? storage === null || storage === void 0 ? void 0 : storage.getItem(key) : undefined;
|
|
66
|
+
if (existing) {
|
|
67
|
+
analyticsBrowserState.sessionId = existing;
|
|
68
|
+
return existing;
|
|
69
|
+
}
|
|
70
|
+
const generated = (_d = (_c = (_b = analyticsBrowserState.config).sessionIdFactory) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : createSessionId();
|
|
71
|
+
analyticsBrowserState.sessionId = generated;
|
|
72
|
+
if (key) {
|
|
73
|
+
try {
|
|
74
|
+
storage === null || storage === void 0 ? void 0 : storage.setItem(key, generated);
|
|
75
|
+
}
|
|
76
|
+
catch (_e) {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return generated;
|
|
80
|
+
}
|
|
81
|
+
function getOrCreateVisitorId() {
|
|
82
|
+
var _a, _b, _c, _d, _e;
|
|
83
|
+
if (analyticsBrowserState.config.visitorStorage === false)
|
|
84
|
+
return undefined;
|
|
85
|
+
if (analyticsBrowserState.visitorId)
|
|
86
|
+
return analyticsBrowserState.visitorId;
|
|
87
|
+
const storageMode = (_a = analyticsBrowserState.config.visitorStorage) !== null && _a !== void 0 ? _a : 'local';
|
|
88
|
+
const key = (_b = analyticsBrowserState.config.visitorStorageKey) !== null && _b !== void 0 ? _b : 'smartlinks.analytics.visitorId';
|
|
89
|
+
const storage = getStorage(storageMode);
|
|
90
|
+
const existing = key ? storage === null || storage === void 0 ? void 0 : storage.getItem(key) : undefined;
|
|
91
|
+
if (existing) {
|
|
92
|
+
analyticsBrowserState.visitorId = existing;
|
|
93
|
+
return existing;
|
|
94
|
+
}
|
|
95
|
+
const generated = (_e = (_d = (_c = analyticsBrowserState.config).visitorIdFactory) === null || _d === void 0 ? void 0 : _d.call(_c)) !== null && _e !== void 0 ? _e : createVisitorId();
|
|
96
|
+
analyticsBrowserState.visitorId = generated;
|
|
97
|
+
if (key) {
|
|
98
|
+
try {
|
|
99
|
+
storage === null || storage === void 0 ? void 0 : storage.setItem(key, generated);
|
|
100
|
+
}
|
|
101
|
+
catch (_f) {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return generated;
|
|
105
|
+
}
|
|
106
|
+
function persistVisitorId(visitorId, options = {}) {
|
|
107
|
+
var _a, _b, _c, _d;
|
|
108
|
+
analyticsBrowserState.visitorId = visitorId;
|
|
109
|
+
const storageMode = (_b = (_a = options.storage) !== null && _a !== void 0 ? _a : analyticsBrowserState.config.visitorStorage) !== null && _b !== void 0 ? _b : 'local';
|
|
110
|
+
const storageKey = (_d = (_c = options.storageKey) !== null && _c !== void 0 ? _c : analyticsBrowserState.config.visitorStorageKey) !== null && _d !== void 0 ? _d : 'smartlinks.analytics.visitorId';
|
|
111
|
+
const shouldPersist = options.persist !== false && storageMode !== false;
|
|
112
|
+
const storage = shouldPersist ? getStorage(storageMode) : undefined;
|
|
113
|
+
if (!storageKey || !storage)
|
|
114
|
+
return visitorId;
|
|
115
|
+
try {
|
|
116
|
+
if (visitorId) {
|
|
117
|
+
storage.setItem(storageKey, visitorId);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
storage.removeItem(storageKey);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (_e) {
|
|
124
|
+
}
|
|
125
|
+
return visitorId;
|
|
126
|
+
}
|
|
127
|
+
function detectDeviceType() {
|
|
128
|
+
var _a;
|
|
129
|
+
if (typeof navigator === 'undefined' || typeof screen === 'undefined')
|
|
130
|
+
return 'unknown';
|
|
131
|
+
const ua = (_a = navigator.userAgent) !== null && _a !== void 0 ? _a : '';
|
|
132
|
+
if (/Mobi|Android/i.test(ua)) {
|
|
133
|
+
if (Math.min(screen.width, screen.height) >= 768)
|
|
134
|
+
return 'tablet';
|
|
135
|
+
return 'mobile';
|
|
136
|
+
}
|
|
137
|
+
if (/iPad|Tablet/i.test(ua))
|
|
138
|
+
return 'tablet';
|
|
139
|
+
return 'desktop';
|
|
140
|
+
}
|
|
141
|
+
function getCurrentPath() {
|
|
142
|
+
if (typeof window === 'undefined')
|
|
143
|
+
return undefined;
|
|
144
|
+
return `${window.location.pathname}${window.location.search}`;
|
|
145
|
+
}
|
|
146
|
+
function getCurrentReferrerFields() {
|
|
147
|
+
if (typeof document === 'undefined' || !document.referrer)
|
|
148
|
+
return {};
|
|
149
|
+
try {
|
|
150
|
+
const referrerUrl = new URL(document.referrer);
|
|
151
|
+
return {
|
|
152
|
+
referrer: document.referrer,
|
|
153
|
+
referrerHost: referrerUrl.hostname,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
catch (_a) {
|
|
157
|
+
return {
|
|
158
|
+
referrer: document.referrer,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function getCampaignFields(search) {
|
|
163
|
+
var _a;
|
|
164
|
+
const query = search !== null && search !== void 0 ? search : (typeof window !== 'undefined' ? window.location.search : '');
|
|
165
|
+
if (!query)
|
|
166
|
+
return {};
|
|
167
|
+
const params = new URLSearchParams(query);
|
|
168
|
+
const fields = {};
|
|
169
|
+
const paramMap = Object.assign(Object.assign({}, defaultCampaignParamMap), ((_a = analyticsBrowserState.config.campaignParamMap) !== null && _a !== void 0 ? _a : {}));
|
|
170
|
+
for (const [field, aliases] of Object.entries(paramMap)) {
|
|
171
|
+
const names = Array.isArray(aliases) ? aliases : [aliases];
|
|
172
|
+
for (const name of names) {
|
|
173
|
+
const value = params.get(name);
|
|
174
|
+
if (value) {
|
|
175
|
+
;
|
|
176
|
+
fields[field] = value;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return fields;
|
|
182
|
+
}
|
|
183
|
+
function getDestinationDomain(href) {
|
|
184
|
+
if (!href)
|
|
185
|
+
return undefined;
|
|
186
|
+
try {
|
|
187
|
+
const base = typeof window !== 'undefined' ? window.location.href : undefined;
|
|
188
|
+
return new URL(href, base).hostname;
|
|
189
|
+
}
|
|
190
|
+
catch (_a) {
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function getResolvedLocation() {
|
|
195
|
+
var _a, _b, _c;
|
|
196
|
+
if (analyticsBrowserState.location !== undefined)
|
|
197
|
+
return (_a = analyticsBrowserState.location) !== null && _a !== void 0 ? _a : undefined;
|
|
198
|
+
const configured = (_c = (_b = analyticsBrowserState.config).getLocation) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
199
|
+
if (configured !== undefined)
|
|
200
|
+
return configured !== null && configured !== void 0 ? configured : undefined;
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
function mergeCollectionEventDefaults(event) {
|
|
204
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
205
|
+
const configuredDefaults = (_a = analyticsBrowserState.config.defaultCollectionEvent) !== null && _a !== void 0 ? _a : {};
|
|
206
|
+
const dynamicDefaults = (_d = (_c = (_b = analyticsBrowserState.config).getCollectionDefaults) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : {};
|
|
207
|
+
const campaignFields = analyticsBrowserState.config.autoCaptureCampaignParams === false ? {} : getCampaignFields();
|
|
208
|
+
const path = (_e = event.path) !== null && _e !== void 0 ? _e : getCurrentPath();
|
|
209
|
+
const visitorId = (_f = event.visitorId) !== null && _f !== void 0 ? _f : getOrCreateVisitorId();
|
|
210
|
+
const href = (_h = (_g = event.href) !== null && _g !== void 0 ? _g : dynamicDefaults.href) !== null && _h !== void 0 ? _h : configuredDefaults.href;
|
|
211
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, configuredDefaults), dynamicDefaults), campaignFields), getCurrentReferrerFields()), { visitorId, sessionId: getOrCreateSessionId(), deviceType: detectDeviceType(), path, pagePath: (_k = (_j = event.pagePath) !== null && _j !== void 0 ? _j : campaignFields.pagePath) !== null && _k !== void 0 ? _k : path, destinationDomain: (_l = event.destinationDomain) !== null && _l !== void 0 ? _l : getDestinationDomain(href), location: getResolvedLocation(), eventType: 'page_view' }), event), { metadata: Object.assign(Object.assign(Object.assign(Object.assign({}, ((_m = configuredDefaults.metadata) !== null && _m !== void 0 ? _m : {})), ((_o = dynamicDefaults.metadata) !== null && _o !== void 0 ? _o : {})), (visitorId ? { visitorId } : {})), ((_p = event.metadata) !== null && _p !== void 0 ? _p : {})) });
|
|
212
|
+
}
|
|
213
|
+
function mergeTagEventDefaults(event) {
|
|
214
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
215
|
+
const configuredDefaults = (_a = analyticsBrowserState.config.defaultTagEvent) !== null && _a !== void 0 ? _a : {};
|
|
216
|
+
const dynamicDefaults = (_d = (_c = (_b = analyticsBrowserState.config).getTagDefaults) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : {};
|
|
217
|
+
const visitorId = (_e = event.visitorId) !== null && _e !== void 0 ? _e : getOrCreateVisitorId();
|
|
218
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, configuredDefaults), dynamicDefaults), { visitorId, sessionId: getOrCreateSessionId(), deviceType: detectDeviceType(), location: getResolvedLocation(), eventType: 'scan_tag' }), event), { metadata: Object.assign(Object.assign(Object.assign(Object.assign({}, ((_f = configuredDefaults.metadata) !== null && _f !== void 0 ? _f : {})), ((_g = dynamicDefaults.metadata) !== null && _g !== void 0 ? _g : {})), (visitorId ? { visitorId } : {})), ((_h = event.metadata) !== null && _h !== void 0 ? _h : {})) });
|
|
219
|
+
}
|
|
220
|
+
function isExternalHref(href) {
|
|
221
|
+
if (typeof window === 'undefined')
|
|
222
|
+
return undefined;
|
|
223
|
+
try {
|
|
224
|
+
const url = new URL(href, window.location.href);
|
|
225
|
+
return url.hostname !== window.location.hostname;
|
|
226
|
+
}
|
|
227
|
+
catch (_a) {
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function queueAnalytics(path, body, options) {
|
|
232
|
+
const baseURL = getBaseURL();
|
|
233
|
+
if (!baseURL) {
|
|
234
|
+
throw new Error('HTTP client is not initialized. Call initializeApi(...) first.');
|
|
235
|
+
}
|
|
236
|
+
const url = `${baseURL}${path}`;
|
|
237
|
+
const payload = JSON.stringify(body);
|
|
238
|
+
const headers = getApiHeaders();
|
|
239
|
+
const preferBeacon = (options === null || options === void 0 ? void 0 : options.preferBeacon) !== false;
|
|
240
|
+
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function' && preferBeacon) {
|
|
241
|
+
try {
|
|
242
|
+
const blob = new Blob([payload], { type: 'application/json' });
|
|
243
|
+
const queued = navigator.sendBeacon(url, blob);
|
|
244
|
+
if (queued)
|
|
245
|
+
return { queued: true, transport: 'beacon' };
|
|
246
|
+
}
|
|
247
|
+
catch (_a) {
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (typeof fetch === 'function') {
|
|
251
|
+
void fetch(url, {
|
|
252
|
+
method: 'POST',
|
|
253
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, headers),
|
|
254
|
+
body: payload,
|
|
255
|
+
keepalive: true,
|
|
256
|
+
}).catch(() => { });
|
|
257
|
+
return { queued: true, transport: 'fetch' };
|
|
258
|
+
}
|
|
259
|
+
return { queued: false, transport: 'unavailable' };
|
|
260
|
+
}
|
|
261
|
+
export var analytics;
|
|
262
|
+
(function (analytics) {
|
|
263
|
+
let collection;
|
|
264
|
+
(function (collection) {
|
|
265
|
+
/**
|
|
266
|
+
* Fire-and-forget collection analytics event.
|
|
267
|
+
* Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
|
|
268
|
+
*/
|
|
269
|
+
function track(event, options) {
|
|
270
|
+
return queueAnalytics('/public/analytics/collection', event, options);
|
|
271
|
+
}
|
|
272
|
+
collection.track = track;
|
|
273
|
+
})(collection = analytics.collection || (analytics.collection = {}));
|
|
274
|
+
let tag;
|
|
275
|
+
(function (tag) {
|
|
276
|
+
/**
|
|
277
|
+
* Fire-and-forget tag analytics event.
|
|
278
|
+
* Uses `navigator.sendBeacon()` when available, falling back to `fetch(..., { keepalive: true })`.
|
|
279
|
+
*/
|
|
280
|
+
function track(event, options) {
|
|
281
|
+
return queueAnalytics('/public/analytics/tag', event, options);
|
|
282
|
+
}
|
|
283
|
+
tag.track = track;
|
|
284
|
+
})(tag = analytics.tag || (analytics.tag = {}));
|
|
285
|
+
let browser;
|
|
286
|
+
(function (browser) {
|
|
287
|
+
function configure(config) {
|
|
288
|
+
const { visitorId } = config, nextConfig = __rest(config, ["visitorId"]);
|
|
289
|
+
analyticsBrowserState.config = Object.assign(Object.assign({}, analyticsBrowserState.config), nextConfig);
|
|
290
|
+
if (visitorId) {
|
|
291
|
+
setVisitorId(visitorId);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
browser.configure = configure;
|
|
295
|
+
function getSessionId() {
|
|
296
|
+
return getOrCreateSessionId();
|
|
297
|
+
}
|
|
298
|
+
browser.getSessionId = getSessionId;
|
|
299
|
+
function getVisitorId() {
|
|
300
|
+
return getOrCreateVisitorId();
|
|
301
|
+
}
|
|
302
|
+
browser.getVisitorId = getVisitorId;
|
|
303
|
+
function setVisitorId(visitorId, options) {
|
|
304
|
+
var _a;
|
|
305
|
+
return (_a = persistVisitorId(visitorId, options)) !== null && _a !== void 0 ? _a : visitorId;
|
|
306
|
+
}
|
|
307
|
+
browser.setVisitorId = setVisitorId;
|
|
308
|
+
function clearVisitorId(options) {
|
|
309
|
+
persistVisitorId(undefined, Object.assign(Object.assign({}, options), { persist: true }));
|
|
310
|
+
}
|
|
311
|
+
browser.clearVisitorId = clearVisitorId;
|
|
312
|
+
function captureCampaignParams(search) {
|
|
313
|
+
return getCampaignFields(search);
|
|
314
|
+
}
|
|
315
|
+
browser.captureCampaignParams = captureCampaignParams;
|
|
316
|
+
function setLocation(location) {
|
|
317
|
+
analyticsBrowserState.location = location;
|
|
318
|
+
}
|
|
319
|
+
browser.setLocation = setLocation;
|
|
320
|
+
function clearLocation() {
|
|
321
|
+
analyticsBrowserState.location = null;
|
|
322
|
+
}
|
|
323
|
+
browser.clearLocation = clearLocation;
|
|
324
|
+
function getLocation() {
|
|
325
|
+
return getResolvedLocation();
|
|
326
|
+
}
|
|
327
|
+
browser.getLocation = getLocation;
|
|
328
|
+
function detectDevice() {
|
|
329
|
+
return detectDeviceType();
|
|
330
|
+
}
|
|
331
|
+
browser.detectDevice = detectDevice;
|
|
332
|
+
async function captureLocation(options = {}) {
|
|
333
|
+
if (typeof navigator === 'undefined' || !navigator.geolocation)
|
|
334
|
+
return null;
|
|
335
|
+
const location = await new Promise((resolve) => {
|
|
336
|
+
navigator.geolocation.getCurrentPosition(({ coords }) => {
|
|
337
|
+
const nextLocation = {};
|
|
338
|
+
if (options.includeCoordinates !== false) {
|
|
339
|
+
nextLocation.latitude = coords.latitude;
|
|
340
|
+
nextLocation.longitude = coords.longitude;
|
|
341
|
+
}
|
|
342
|
+
if (options.includeAccuracyArea) {
|
|
343
|
+
nextLocation.area = coords.accuracy;
|
|
344
|
+
}
|
|
345
|
+
resolve(nextLocation);
|
|
346
|
+
}, () => resolve(null), options);
|
|
347
|
+
});
|
|
348
|
+
analyticsBrowserState.location = location;
|
|
349
|
+
return location;
|
|
350
|
+
}
|
|
351
|
+
browser.captureLocation = captureLocation;
|
|
352
|
+
function trackCollection(event, options) {
|
|
353
|
+
return collection.track(mergeCollectionEventDefaults(event), options);
|
|
354
|
+
}
|
|
355
|
+
browser.trackCollection = trackCollection;
|
|
356
|
+
function trackTag(event, options) {
|
|
357
|
+
return tag.track(mergeTagEventDefaults(event), options);
|
|
358
|
+
}
|
|
359
|
+
browser.trackTag = trackTag;
|
|
360
|
+
function trackPageView(event, options) {
|
|
361
|
+
return trackCollection(Object.assign({ eventType: 'page_view' }, event), options);
|
|
362
|
+
}
|
|
363
|
+
browser.trackPageView = trackPageView;
|
|
364
|
+
function trackLinkClick(event, options) {
|
|
365
|
+
var _a, _b, _c, _d;
|
|
366
|
+
return trackCollection(Object.assign({ eventType: 'click_link', path: (_a = event.path) !== null && _a !== void 0 ? _a : getCurrentPath(), pagePath: (_c = (_b = event.pagePath) !== null && _b !== void 0 ? _b : event.path) !== null && _c !== void 0 ? _c : getCurrentPath(), isExternal: (_d = event.isExternal) !== null && _d !== void 0 ? _d : isExternalHref(event.href) }, event), options);
|
|
367
|
+
}
|
|
368
|
+
browser.trackLinkClick = trackLinkClick;
|
|
369
|
+
function trackTagScan(event, options) {
|
|
370
|
+
return trackTag(Object.assign({ eventType: 'scan_tag' }, event), options);
|
|
371
|
+
}
|
|
372
|
+
browser.trackTagScan = trackTagScan;
|
|
373
|
+
function bindPageViews(binding = {}) {
|
|
374
|
+
if (typeof window === 'undefined' || typeof history === 'undefined')
|
|
375
|
+
return () => { };
|
|
376
|
+
const trackOptions = binding.trackOptions;
|
|
377
|
+
const includeHashChanges = binding.includeHashChanges === true;
|
|
378
|
+
let lastPath;
|
|
379
|
+
const track = () => {
|
|
380
|
+
var _a, _b;
|
|
381
|
+
const path = getCurrentPath();
|
|
382
|
+
if (!path || path === lastPath)
|
|
383
|
+
return;
|
|
384
|
+
const extraEvent = (_a = binding.getEvent) === null || _a === void 0 ? void 0 : _a.call(binding, path);
|
|
385
|
+
if (extraEvent === null)
|
|
386
|
+
return;
|
|
387
|
+
lastPath = path;
|
|
388
|
+
trackPageView(Object.assign(Object.assign({ path, pagePath: path }, ((_b = binding.event) !== null && _b !== void 0 ? _b : {})), (extraEvent !== null && extraEvent !== void 0 ? extraEvent : {})), trackOptions);
|
|
389
|
+
};
|
|
390
|
+
const originalPushState = history.pushState;
|
|
391
|
+
const originalReplaceState = history.replaceState;
|
|
392
|
+
history.pushState = function (...args) {
|
|
393
|
+
originalPushState.apply(history, args);
|
|
394
|
+
track();
|
|
395
|
+
};
|
|
396
|
+
history.replaceState = function (...args) {
|
|
397
|
+
originalReplaceState.apply(history, args);
|
|
398
|
+
track();
|
|
399
|
+
};
|
|
400
|
+
window.addEventListener('popstate', track);
|
|
401
|
+
if (includeHashChanges) {
|
|
402
|
+
window.addEventListener('hashchange', track);
|
|
403
|
+
}
|
|
404
|
+
if (binding.trackInitialPageView !== false) {
|
|
405
|
+
track();
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
lastPath = getCurrentPath();
|
|
409
|
+
}
|
|
410
|
+
return () => {
|
|
411
|
+
history.pushState = originalPushState;
|
|
412
|
+
history.replaceState = originalReplaceState;
|
|
413
|
+
window.removeEventListener('popstate', track);
|
|
414
|
+
if (includeHashChanges) {
|
|
415
|
+
window.removeEventListener('hashchange', track);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
browser.bindPageViews = bindPageViews;
|
|
420
|
+
function bindLinkTracking(binding = {}) {
|
|
421
|
+
var _a, _b;
|
|
422
|
+
if (typeof document === 'undefined')
|
|
423
|
+
return () => { };
|
|
424
|
+
const root = (_a = binding.root) !== null && _a !== void 0 ? _a : document;
|
|
425
|
+
const selector = (_b = binding.selector) !== null && _b !== void 0 ? _b : 'a[href]';
|
|
426
|
+
const handler = (event) => {
|
|
427
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
428
|
+
const mouseEvent = event;
|
|
429
|
+
const target = mouseEvent.target;
|
|
430
|
+
const anchor = (_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, selector);
|
|
431
|
+
if (!(anchor === null || anchor === void 0 ? void 0 : anchor.href))
|
|
432
|
+
return;
|
|
433
|
+
const customEvent = (_b = binding.getEvent) === null || _b === void 0 ? void 0 : _b.call(binding, anchor, mouseEvent);
|
|
434
|
+
if (customEvent === null)
|
|
435
|
+
return;
|
|
436
|
+
const external = isExternalHref(anchor.href);
|
|
437
|
+
if (binding.trackInternal === false && external === false)
|
|
438
|
+
return;
|
|
439
|
+
trackLinkClick(Object.assign(Object.assign(Object.assign({ href: anchor.href, linkTitle: ((_c = anchor.textContent) === null || _c === void 0 ? void 0 : _c.trim()) || undefined }, ((_d = binding.event) !== null && _d !== void 0 ? _d : {})), (customEvent !== null && customEvent !== void 0 ? customEvent : {})), { isExternal: (_g = (_e = customEvent === null || customEvent === void 0 ? void 0 : customEvent.isExternal) !== null && _e !== void 0 ? _e : (_f = binding.event) === null || _f === void 0 ? void 0 : _f.isExternal) !== null && _g !== void 0 ? _g : external }), binding.trackOptions);
|
|
440
|
+
};
|
|
441
|
+
root.addEventListener('click', handler);
|
|
442
|
+
return () => root.removeEventListener('click', handler);
|
|
443
|
+
}
|
|
444
|
+
browser.bindLinkTracking = bindLinkTracking;
|
|
445
|
+
})(browser = analytics.browser || (analytics.browser = {}));
|
|
446
|
+
let admin;
|
|
447
|
+
(function (admin) {
|
|
448
|
+
async function classicBreakdown(collectionId, body, config) {
|
|
449
|
+
const { metric = 'count', limit = 10, source = 'events', eventType } = body, rest = __rest(body, ["metric", "limit", "source", "eventType"]);
|
|
450
|
+
return breakdown(collectionId, Object.assign({ source, dimension: config.dimension, metadataKey: config.metadataKey, metric,
|
|
451
|
+
limit, eventType: eventType !== null && eventType !== void 0 ? eventType : config.defaultEventType }, rest));
|
|
452
|
+
}
|
|
453
|
+
async function summary(collectionId, body) {
|
|
454
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/summary`, body);
|
|
455
|
+
}
|
|
456
|
+
admin.summary = summary;
|
|
457
|
+
async function timeseries(collectionId, body) {
|
|
458
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/timeseries`, body);
|
|
459
|
+
}
|
|
460
|
+
admin.timeseries = timeseries;
|
|
461
|
+
async function breakdown(collectionId, body) {
|
|
462
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/breakdown`, body);
|
|
463
|
+
}
|
|
464
|
+
admin.breakdown = breakdown;
|
|
465
|
+
async function events(collectionId, body) {
|
|
466
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/events`, body);
|
|
467
|
+
}
|
|
468
|
+
admin.events = events;
|
|
469
|
+
async function web(collectionId, body = {}) {
|
|
470
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/web`, body);
|
|
471
|
+
}
|
|
472
|
+
admin.web = web;
|
|
473
|
+
async function clicks(collectionId, body = {}) {
|
|
474
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/clicks`, body);
|
|
475
|
+
}
|
|
476
|
+
admin.clicks = clicks;
|
|
477
|
+
async function tagScans(collectionId, body = {}) {
|
|
478
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/tag-scans`, body);
|
|
479
|
+
}
|
|
480
|
+
admin.tagScans = tagScans;
|
|
481
|
+
async function products(collectionId, body = {}) {
|
|
482
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/products`, body);
|
|
483
|
+
}
|
|
484
|
+
admin.products = products;
|
|
485
|
+
async function qrCodes(collectionId, body = {}) {
|
|
486
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/qr-codes`, body);
|
|
487
|
+
}
|
|
488
|
+
admin.qrCodes = qrCodes;
|
|
489
|
+
async function tags(collectionId, body = {}) {
|
|
490
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/tags`, body);
|
|
491
|
+
}
|
|
492
|
+
admin.tags = tags;
|
|
493
|
+
async function weekly(collectionId, body = {}) {
|
|
494
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/weekly`, body);
|
|
495
|
+
}
|
|
496
|
+
admin.weekly = weekly;
|
|
497
|
+
async function country(collectionId, body = {}) {
|
|
498
|
+
return post(`/admin/collection/${encodeURIComponent(collectionId)}/analytics/country`, body);
|
|
499
|
+
}
|
|
500
|
+
admin.country = country;
|
|
501
|
+
async function topPages(collectionId, body = {}) {
|
|
502
|
+
return classicBreakdown(collectionId, body, {
|
|
503
|
+
dimension: 'metadata',
|
|
504
|
+
metadataKey: 'pagePath',
|
|
505
|
+
defaultEventType: 'page_view',
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
admin.topPages = topPages;
|
|
509
|
+
async function topReferrers(collectionId, body = {}) {
|
|
510
|
+
return classicBreakdown(collectionId, body, {
|
|
511
|
+
dimension: 'metadata',
|
|
512
|
+
metadataKey: 'referrerHost',
|
|
513
|
+
defaultEventType: 'page_view',
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
admin.topReferrers = topReferrers;
|
|
517
|
+
async function topCampaigns(collectionId, body = {}) {
|
|
518
|
+
return classicBreakdown(collectionId, body, {
|
|
519
|
+
dimension: 'metadata',
|
|
520
|
+
metadataKey: 'utmCampaign',
|
|
521
|
+
defaultEventType: 'page_view',
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
admin.topCampaigns = topCampaigns;
|
|
525
|
+
async function topSources(collectionId, body = {}) {
|
|
526
|
+
return classicBreakdown(collectionId, body, {
|
|
527
|
+
dimension: 'metadata',
|
|
528
|
+
metadataKey: 'utmSource',
|
|
529
|
+
defaultEventType: 'page_view',
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
admin.topSources = topSources;
|
|
533
|
+
async function topDestinations(collectionId, body = {}) {
|
|
534
|
+
return classicBreakdown(collectionId, body, {
|
|
535
|
+
dimension: 'metadata',
|
|
536
|
+
metadataKey: 'destinationDomain',
|
|
537
|
+
defaultEventType: 'click_link',
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
admin.topDestinations = topDestinations;
|
|
541
|
+
})(admin = analytics.admin || (analytics.admin = {}));
|
|
542
|
+
})(analytics || (analytics = {}));
|