@esri/telemetry-amazon 6.0.0-beta.4 → 6.0.0-beta.5
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/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.test.js +17 -0
- package/dist/esm/index.test.js.map +1 -1
- package/dist/esm/plugins/esri.js +149 -54
- package/dist/esm/plugins/esri.js.map +1 -1
- package/dist/esm/plugins/esri.test.js +346 -61
- package/dist/esm/plugins/esri.test.js.map +1 -1
- package/dist/esm/plugins/shared.js +1 -0
- package/dist/esm/plugins/shared.js.map +1 -1
- package/dist/esm/plugins/utils/browser.js +97 -0
- package/dist/esm/plugins/utils/browser.js.map +1 -0
- package/dist/esm/plugins/utils/os.js +42 -0
- package/dist/esm/plugins/utils/os.js.map +1 -0
- package/dist/node/index.js +2 -2
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.test.js +17 -0
- package/dist/node/index.test.js.map +1 -1
- package/dist/node/plugins/esri.js +148 -53
- package/dist/node/plugins/esri.js.map +1 -1
- package/dist/node/plugins/esri.test.js +347 -61
- package/dist/node/plugins/esri.test.js.map +1 -1
- package/dist/node/plugins/shared.js +3 -1
- package/dist/node/plugins/shared.js.map +1 -1
- package/dist/node/plugins/utils/browser.js +101 -0
- package/dist/node/plugins/utils/browser.js.map +1 -0
- package/dist/node/plugins/utils/os.js +46 -0
- package/dist/node/plugins/utils/os.js.map +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/esri.d.ts +2 -1
- package/dist/types/plugins/shared.d.ts +1 -0
- package/dist/types/plugins/utils/browser.d.ts +12 -0
- package/dist/types/plugins/utils/os.d.ts +5 -0
- package/dist/types/types.d.ts +7 -2
- package/dist/umd/telemetry-amazon.js +287 -55
- package/dist/umd/telemetry-amazon.js.map +1 -1
- package/dist/umd/telemetry-amazon.min.js +287 -55
- package/dist/umd/telemetry-amazon.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1667,6 +1667,144 @@
|
|
|
1667
1667
|
return [HOST_SERVICES[service] || service, region || '']
|
|
1668
1668
|
}
|
|
1669
1669
|
|
|
1670
|
+
function parseOS(userAgent) {
|
|
1671
|
+
var _a;
|
|
1672
|
+
const cleanAgent = userAgent.toLowerCase().replace(/ /g, '');
|
|
1673
|
+
const osMatchers = [
|
|
1674
|
+
{
|
|
1675
|
+
name: 'Windows',
|
|
1676
|
+
regex: /windowsnt/i,
|
|
1677
|
+
versionRegex: /windowsnt([\d\.]+)/i,
|
|
1678
|
+
},
|
|
1679
|
+
{
|
|
1680
|
+
name: 'MacOS',
|
|
1681
|
+
regex: /macos|macosx|macintosh|macintel|darwin/i,
|
|
1682
|
+
versionRegex: /osx([\d_\.]+)/i,
|
|
1683
|
+
},
|
|
1684
|
+
{
|
|
1685
|
+
name: 'Android',
|
|
1686
|
+
regex: /android/i,
|
|
1687
|
+
versionRegex: /android([\d\.]+)/i,
|
|
1688
|
+
},
|
|
1689
|
+
{
|
|
1690
|
+
name: 'iOS',
|
|
1691
|
+
regex: /iphone|ipad|ipod/i,
|
|
1692
|
+
versionRegex: /os([\d_\.]+)/i,
|
|
1693
|
+
},
|
|
1694
|
+
{
|
|
1695
|
+
name: 'Linux',
|
|
1696
|
+
regex: /linux/i,
|
|
1697
|
+
},
|
|
1698
|
+
];
|
|
1699
|
+
const matched = osMatchers.find((entry) => entry.regex.test(cleanAgent));
|
|
1700
|
+
if (!matched) {
|
|
1701
|
+
return {};
|
|
1702
|
+
}
|
|
1703
|
+
const version = matched.versionRegex
|
|
1704
|
+
? (_a = (cleanAgent.match(matched.versionRegex) || [])[1]) === null || _a === void 0 ? void 0 : _a.replace(/_/g, '.')
|
|
1705
|
+
: undefined;
|
|
1706
|
+
return {
|
|
1707
|
+
name: matched.name,
|
|
1708
|
+
version,
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
function getNavigatorSafe() {
|
|
1713
|
+
if (typeof window === 'undefined' || !window.navigator) {
|
|
1714
|
+
return undefined;
|
|
1715
|
+
}
|
|
1716
|
+
return window.navigator;
|
|
1717
|
+
}
|
|
1718
|
+
function getLanguageInfo(nav) {
|
|
1719
|
+
if (!nav) {
|
|
1720
|
+
return '';
|
|
1721
|
+
}
|
|
1722
|
+
const lang = nav.language ||
|
|
1723
|
+
nav.browserLanguage ||
|
|
1724
|
+
(Array.isArray(nav.languages) && nav.languages.length > 0
|
|
1725
|
+
? nav.languages[0]
|
|
1726
|
+
: 'en_US') ||
|
|
1727
|
+
'';
|
|
1728
|
+
return String(lang).toLowerCase().replace('-', '_');
|
|
1729
|
+
}
|
|
1730
|
+
function getBrowserTimezone() {
|
|
1731
|
+
const tzMatch = /\(([A-Za-z\s].*)\)/.exec(new Date().toString());
|
|
1732
|
+
return tzMatch ? tzMatch[1] || '' : '';
|
|
1733
|
+
}
|
|
1734
|
+
function parseBrowserType(userAgent) {
|
|
1735
|
+
const operaMatch = /.+(Opera[\s[A-Z]*|OPR[\sA-Z]*)\/([0-9\.]+).*/i.exec(userAgent);
|
|
1736
|
+
if (operaMatch) {
|
|
1737
|
+
return {
|
|
1738
|
+
type: operaMatch[1],
|
|
1739
|
+
version: operaMatch[2],
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
const edgeOrTridentMatch = /.+(Trident|Edge)\/([0-9\.]+).*/i.exec(userAgent);
|
|
1743
|
+
if (edgeOrTridentMatch) {
|
|
1744
|
+
return {
|
|
1745
|
+
type: edgeOrTridentMatch[1],
|
|
1746
|
+
version: edgeOrTridentMatch[2],
|
|
1747
|
+
};
|
|
1748
|
+
}
|
|
1749
|
+
const headlessMatch = /(headlesschrome)(?:\/([\w\.]+)| )/i.exec(userAgent);
|
|
1750
|
+
if (headlessMatch) {
|
|
1751
|
+
return {
|
|
1752
|
+
type: headlessMatch[1],
|
|
1753
|
+
version: headlessMatch[2],
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
const browserMatch = /.+(Chrome|Firefox|FxiOS)\/([0-9\.]+).*/i.exec(userAgent);
|
|
1757
|
+
if (browserMatch) {
|
|
1758
|
+
return {
|
|
1759
|
+
type: browserMatch[1],
|
|
1760
|
+
version: browserMatch[2],
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
const safariMatch = /.+(Safari)\/([0-9\.]+).*/i.exec(userAgent);
|
|
1764
|
+
if (safariMatch) {
|
|
1765
|
+
return {
|
|
1766
|
+
type: safariMatch[1],
|
|
1767
|
+
version: safariMatch[2],
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
const webkitMatch = /.+(AppleWebKit)\/([0-9\.]+).*/i.exec(userAgent);
|
|
1771
|
+
if (webkitMatch) {
|
|
1772
|
+
return {
|
|
1773
|
+
type: webkitMatch[1],
|
|
1774
|
+
version: webkitMatch[2],
|
|
1775
|
+
};
|
|
1776
|
+
}
|
|
1777
|
+
const anyMatch = /.*([A-Z]+)\/([0-9\.]+).*/i.exec(userAgent);
|
|
1778
|
+
const fallback = anyMatch || ['', 'NA', '0.0.0'];
|
|
1779
|
+
return {
|
|
1780
|
+
type: fallback[1],
|
|
1781
|
+
version: fallback[2],
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
function getBrowserClientInfo() {
|
|
1785
|
+
const nav = getNavigatorSafe();
|
|
1786
|
+
if (!nav) {
|
|
1787
|
+
return {};
|
|
1788
|
+
}
|
|
1789
|
+
const userAgent = nav.userAgent || '';
|
|
1790
|
+
const browser = parseBrowserType(userAgent);
|
|
1791
|
+
const isBrave = (nav.brave && nav.brave.isBrave) || false;
|
|
1792
|
+
const type = isBrave ? 'Brave' : browser.type;
|
|
1793
|
+
const os = parseOS(userAgent);
|
|
1794
|
+
const vendorToken = (nav.vendor || '').split(' ').filter(Boolean)[0];
|
|
1795
|
+
const make = type === 'Brave' ? type : vendorToken || nav.product || '';
|
|
1796
|
+
return {
|
|
1797
|
+
language: getLanguageInfo(nav),
|
|
1798
|
+
make,
|
|
1799
|
+
model: type,
|
|
1800
|
+
version: browser.version,
|
|
1801
|
+
name: [type, browser.version].filter(Boolean).join('/'),
|
|
1802
|
+
timezone: getBrowserTimezone(),
|
|
1803
|
+
platform: nav.platform,
|
|
1804
|
+
os,
|
|
1805
|
+
};
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1670
1808
|
// Shared utilities for plugins
|
|
1671
1809
|
const PINPOINT_ENDPOINT_KEY = 'TELEMETRY_PINPOINT_ENDPOINT_ID';
|
|
1672
1810
|
const LOG_PREFIX = '[telemetry-amazon]';
|
|
@@ -1721,6 +1859,7 @@
|
|
|
1721
1859
|
const SESSION_START_EVENT = '_session.start';
|
|
1722
1860
|
const SESSION_STOP_EVENT = '_session.stop';
|
|
1723
1861
|
const DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000;
|
|
1862
|
+
const DEFAULT_DEBOUNCE_MS = 5000;
|
|
1724
1863
|
/** Converts a string to a number, guarded against invalid values */
|
|
1725
1864
|
function getNumber(value, fallback = 0) {
|
|
1726
1865
|
const numeric = Number(value);
|
|
@@ -1762,58 +1901,77 @@
|
|
|
1762
1901
|
metrics,
|
|
1763
1902
|
};
|
|
1764
1903
|
}
|
|
1765
|
-
function buildBatchEventPayload({
|
|
1766
|
-
var _a, _b, _c, _d;
|
|
1767
|
-
const
|
|
1768
|
-
const timestamp = new Date().toISOString();
|
|
1769
|
-
const sessionContext = session ||
|
|
1904
|
+
function buildBatchEventPayload({ queuedEvents, trackerName, appName, appVersion, }) {
|
|
1905
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1906
|
+
const endpointEvent = queuedEvents[queuedEvents.length - 1] ||
|
|
1770
1907
|
{
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
startUnixMs: Date.now(),
|
|
1908
|
+
payload: {},
|
|
1909
|
+
browserInfo: {},
|
|
1774
1910
|
};
|
|
1775
|
-
const
|
|
1776
|
-
const
|
|
1911
|
+
const payload = endpointEvent.payload || {};
|
|
1912
|
+
const browserInfo = endpointEvent.browserInfo || {};
|
|
1913
|
+
const endpointId = getEndpointId();
|
|
1914
|
+
const location = {};
|
|
1915
|
+
if (payload === null || payload === void 0 ? void 0 : payload.city) {
|
|
1916
|
+
location.City = payload.city;
|
|
1917
|
+
}
|
|
1918
|
+
if (payload === null || payload === void 0 ? void 0 : payload.country) {
|
|
1919
|
+
location.Country = payload.country;
|
|
1920
|
+
}
|
|
1921
|
+
if ((payload === null || payload === void 0 ? void 0 : payload.lat) !== undefined && (payload === null || payload === void 0 ? void 0 : payload.lat) !== null) {
|
|
1922
|
+
location.Lat = getNumber(payload.lat);
|
|
1923
|
+
}
|
|
1924
|
+
if ((payload === null || payload === void 0 ? void 0 : payload.lon) !== undefined && (payload === null || payload === void 0 ? void 0 : payload.lon) !== null) {
|
|
1925
|
+
location.Lon = getNumber(payload.lon);
|
|
1926
|
+
}
|
|
1777
1927
|
return {
|
|
1778
1928
|
BatchEvent: {
|
|
1779
1929
|
Endpoint: {
|
|
1780
1930
|
Id: endpointId,
|
|
1931
|
+
Demographic: Object.assign({ Locale: (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.language) || '', Make: (payload === null || payload === void 0 ? void 0 : payload.deviceMake) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.make) || '', Model: (payload === null || payload === void 0 ? void 0 : payload.deviceModel) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.model) || '', ModelVersion: (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.version) || '', Platform: ((_a = browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.os) === null || _a === void 0 ? void 0 : _a.name) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.platform) || '' }, (((_b = browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.os) === null || _b === void 0 ? void 0 : _b.version)
|
|
1932
|
+
? { PlatformVersion: browserInfo.os.version }
|
|
1933
|
+
: {})),
|
|
1781
1934
|
Device: {
|
|
1782
|
-
Make: (payload === null || payload === void 0 ? void 0 : payload.deviceMake) || '',
|
|
1783
|
-
Model: (payload === null || payload === void 0 ? void 0 : payload.deviceModel) || '',
|
|
1784
|
-
},
|
|
1785
|
-
Location: {
|
|
1786
|
-
City: (payload === null || payload === void 0 ? void 0 : payload.city) || '',
|
|
1787
|
-
Country: (payload === null || payload === void 0 ? void 0 : payload.country) || '',
|
|
1788
|
-
Lat: getNumber(payload === null || payload === void 0 ? void 0 : payload.lat),
|
|
1789
|
-
Lon: getNumber(payload === null || payload === void 0 ? void 0 : payload.lon),
|
|
1935
|
+
Make: (payload === null || payload === void 0 ? void 0 : payload.deviceMake) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.make) || '',
|
|
1936
|
+
Model: (payload === null || payload === void 0 ? void 0 : payload.deviceModel) || (browserInfo === null || browserInfo === void 0 ? void 0 : browserInfo.model) || '',
|
|
1790
1937
|
},
|
|
1938
|
+
Location: location,
|
|
1791
1939
|
Application: {
|
|
1792
|
-
AppTitle: (
|
|
1793
|
-
AppVersion: (
|
|
1794
|
-
ClientSdkVersion: (
|
|
1940
|
+
AppTitle: (_d = (_c = payload === null || payload === void 0 ? void 0 : payload.appTitle) !== null && _c !== void 0 ? _c : appName) !== null && _d !== void 0 ? _d : trackerName,
|
|
1941
|
+
AppVersion: (_e = payload === null || payload === void 0 ? void 0 : payload.appVersion) !== null && _e !== void 0 ? _e : appVersion,
|
|
1942
|
+
ClientSdkVersion: (_f = payload === null || payload === void 0 ? void 0 : payload.clientSdkVersion) !== null && _f !== void 0 ? _f : trackerName,
|
|
1795
1943
|
},
|
|
1796
1944
|
},
|
|
1797
|
-
Events:
|
|
1798
|
-
|
|
1799
|
-
|
|
1945
|
+
Events: queuedEvents.map((queuedEvent) => {
|
|
1946
|
+
console.log('queued event', queuedEvent.eventName);
|
|
1947
|
+
const timestamp = queuedEvent.timestamp;
|
|
1948
|
+
const { attributes, metrics } = splitEventData(queuedEvent.payload);
|
|
1949
|
+
const sessionContext = queuedEvent.session ||
|
|
1950
|
+
{
|
|
1951
|
+
id: `${queuedEvent.unixMs}-${Math.random().toString(16).slice(2)}`,
|
|
1952
|
+
startTimestamp: timestamp,
|
|
1953
|
+
startUnixMs: queuedEvent.unixMs,
|
|
1954
|
+
};
|
|
1955
|
+
const isStopEvent = queuedEvent.eventName === SESSION_STOP_EVENT;
|
|
1956
|
+
return {
|
|
1957
|
+
EventType: queuedEvent.eventName,
|
|
1800
1958
|
Timestamp: timestamp,
|
|
1801
1959
|
Session: {
|
|
1802
1960
|
Id: sessionContext.id,
|
|
1803
1961
|
StartTimestamp: sessionContext.startTimestamp,
|
|
1804
1962
|
EndTimestamp: timestamp,
|
|
1805
1963
|
Duration: isStopEvent
|
|
1806
|
-
? Math.max(0,
|
|
1964
|
+
? Math.max(0, queuedEvent.unixMs - sessionContext.startUnixMs)
|
|
1807
1965
|
: 0,
|
|
1808
1966
|
},
|
|
1809
1967
|
Attributes: attributes,
|
|
1810
1968
|
Metrics: metrics,
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1969
|
+
};
|
|
1970
|
+
}),
|
|
1813
1971
|
},
|
|
1814
1972
|
};
|
|
1815
1973
|
}
|
|
1816
|
-
function createEsriPlugin({ trackerName, appName, appId, appVersion, userPoolID, fips, }) {
|
|
1974
|
+
function createEsriPlugin({ trackerName, appName, appId, appVersion, userPoolID, fips, debounceMs = DEFAULT_DEBOUNCE_MS, }) {
|
|
1817
1975
|
const url = ESRI_ENDPOINT_URL(appId);
|
|
1818
1976
|
let isDisabled = false;
|
|
1819
1977
|
let hasWarned = false;
|
|
@@ -1821,8 +1979,10 @@
|
|
|
1821
1979
|
let sessionStopSent = false;
|
|
1822
1980
|
let activeSession;
|
|
1823
1981
|
let idleTimerId;
|
|
1982
|
+
let debounceTimerId;
|
|
1824
1983
|
let lifecycleListenersAttached = false;
|
|
1825
1984
|
const removeLifecycleListeners = [];
|
|
1985
|
+
let pendingEvents = [];
|
|
1826
1986
|
const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
1827
1987
|
const warnOnce = (message, details) => {
|
|
1828
1988
|
if (hasWarned) {
|
|
@@ -1860,32 +2020,43 @@
|
|
|
1860
2020
|
clearTimeout(idleTimerId);
|
|
1861
2021
|
idleTimerId = undefined;
|
|
1862
2022
|
};
|
|
1863
|
-
const
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
}
|
|
1867
|
-
|
|
2023
|
+
const clearDebounceTimer = () => {
|
|
2024
|
+
if (!debounceTimerId) {
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
clearTimeout(debounceTimerId);
|
|
2028
|
+
debounceTimerId = undefined;
|
|
1868
2029
|
};
|
|
1869
|
-
const
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
2030
|
+
const clearPendingEvents = () => {
|
|
2031
|
+
pendingEvents = [];
|
|
2032
|
+
};
|
|
2033
|
+
const enqueueEvent = (event) => {
|
|
2034
|
+
pendingEvents.push(event);
|
|
2035
|
+
};
|
|
2036
|
+
const dequeuePendingEvents = () => {
|
|
2037
|
+
if (pendingEvents.length === 0) {
|
|
2038
|
+
return [];
|
|
2039
|
+
}
|
|
2040
|
+
const queuedEvents = pendingEvents;
|
|
2041
|
+
pendingEvents = [];
|
|
2042
|
+
return queuedEvents;
|
|
1876
2043
|
};
|
|
1877
|
-
const
|
|
2044
|
+
const sendQueuedEvents = (queuedEvents) => {
|
|
2045
|
+
var _a;
|
|
2046
|
+
if (queuedEvents.length === 0) {
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
1878
2049
|
if (isDisabled || !url || !userPoolID) {
|
|
1879
2050
|
debugLog('Skipping esri track call', {
|
|
1880
|
-
eventName,
|
|
2051
|
+
eventName: (_a = queuedEvents[queuedEvents.length - 1]) === null || _a === void 0 ? void 0 : _a.eventName,
|
|
1881
2052
|
reason: 'plugin-disabled',
|
|
1882
2053
|
});
|
|
1883
|
-
return
|
|
2054
|
+
return;
|
|
1884
2055
|
}
|
|
1885
|
-
debugLog('Sending esri endpoint event', {
|
|
1886
|
-
eventName,
|
|
2056
|
+
debugLog('Sending esri endpoint batch event', {
|
|
1887
2057
|
trackerName,
|
|
1888
2058
|
url,
|
|
2059
|
+
eventCount: queuedEvents.length,
|
|
1889
2060
|
});
|
|
1890
2061
|
void getCredentials(userPoolID, { fips })
|
|
1891
2062
|
.then((credentials) => {
|
|
@@ -1908,39 +2079,100 @@
|
|
|
1908
2079
|
'Content-Type': 'application/json',
|
|
1909
2080
|
},
|
|
1910
2081
|
body: JSON.stringify(buildBatchEventPayload({
|
|
1911
|
-
|
|
1912
|
-
payload: payload,
|
|
2082
|
+
queuedEvents,
|
|
1913
2083
|
trackerName,
|
|
1914
2084
|
appName,
|
|
1915
2085
|
appVersion,
|
|
1916
|
-
session: sessionOverride || activeSession,
|
|
1917
2086
|
})),
|
|
1918
2087
|
});
|
|
1919
2088
|
})
|
|
1920
2089
|
.then(() => {
|
|
1921
2090
|
debugLog('Endpoint event sent', {
|
|
1922
|
-
eventName,
|
|
1923
2091
|
trackerName,
|
|
2092
|
+
eventCount: queuedEvents.length,
|
|
1924
2093
|
});
|
|
1925
2094
|
})
|
|
1926
2095
|
.catch((error) => {
|
|
2096
|
+
var _a;
|
|
1927
2097
|
isDisabled = true;
|
|
1928
2098
|
clearIdleTimer();
|
|
2099
|
+
clearDebounceTimer();
|
|
2100
|
+
clearPendingEvents();
|
|
1929
2101
|
removeAllLifecycleListeners();
|
|
1930
2102
|
warnOnce('Esri telemetry disabled after endpoint track failure', {
|
|
1931
|
-
eventName,
|
|
2103
|
+
eventName: (_a = queuedEvents[queuedEvents.length - 1]) === null || _a === void 0 ? void 0 : _a.eventName,
|
|
1932
2104
|
trackerName,
|
|
1933
2105
|
message: (error === null || error === void 0 ? void 0 : error.message) || String(error),
|
|
1934
2106
|
});
|
|
1935
2107
|
});
|
|
2108
|
+
};
|
|
2109
|
+
const flushPendingEvents = (eventToAppend) => {
|
|
2110
|
+
clearDebounceTimer();
|
|
2111
|
+
const queuedEvents = dequeuePendingEvents();
|
|
2112
|
+
if (eventToAppend) {
|
|
2113
|
+
queuedEvents.push(eventToAppend);
|
|
2114
|
+
}
|
|
2115
|
+
console.log('flushing', eventToAppend);
|
|
2116
|
+
console.log('stack', queuedEvents);
|
|
2117
|
+
sendQueuedEvents(queuedEvents);
|
|
2118
|
+
};
|
|
2119
|
+
const scheduleDebounceFlush = () => {
|
|
2120
|
+
clearDebounceTimer();
|
|
2121
|
+
debounceTimerId = setTimeout(() => {
|
|
2122
|
+
flushPendingEvents();
|
|
2123
|
+
}, debounceMs);
|
|
2124
|
+
};
|
|
2125
|
+
const removeAllLifecycleListeners = () => {
|
|
2126
|
+
removeLifecycleListeners.splice(0).forEach((removeListener) => {
|
|
2127
|
+
removeListener();
|
|
2128
|
+
});
|
|
2129
|
+
lifecycleListenersAttached = false;
|
|
2130
|
+
};
|
|
2131
|
+
const createSession = () => {
|
|
2132
|
+
const now = Date.now();
|
|
2133
|
+
return {
|
|
2134
|
+
id: `${now}-${Math.random().toString(16).slice(2)}`,
|
|
2135
|
+
startTimestamp: new Date(now).toISOString(),
|
|
2136
|
+
startUnixMs: now,
|
|
2137
|
+
};
|
|
2138
|
+
};
|
|
2139
|
+
const sendEvent = (eventName, payload, sessionOverride, options, forceImmediate = false) => {
|
|
2140
|
+
if (isDisabled || !url || !userPoolID) {
|
|
2141
|
+
debugLog('Skipping esri track call', {
|
|
2142
|
+
eventName,
|
|
2143
|
+
reason: 'plugin-disabled',
|
|
2144
|
+
});
|
|
2145
|
+
return false;
|
|
2146
|
+
}
|
|
2147
|
+
debugLog('Queueing esri endpoint event', {
|
|
2148
|
+
eventName,
|
|
2149
|
+
trackerName,
|
|
2150
|
+
immediate: Boolean((options === null || options === void 0 ? void 0 : options.immediate) || forceImmediate),
|
|
2151
|
+
});
|
|
2152
|
+
const queuedEvent = {
|
|
2153
|
+
eventName,
|
|
2154
|
+
payload: payload,
|
|
2155
|
+
session: sessionOverride || activeSession,
|
|
2156
|
+
browserInfo: getBrowserClientInfo(),
|
|
2157
|
+
timestamp: new Date().toISOString(),
|
|
2158
|
+
unixMs: Date.now(),
|
|
2159
|
+
};
|
|
2160
|
+
if ((options === null || options === void 0 ? void 0 : options.immediate) || forceImmediate) {
|
|
2161
|
+
flushPendingEvents(queuedEvent);
|
|
2162
|
+
}
|
|
2163
|
+
else {
|
|
2164
|
+
enqueueEvent(queuedEvent);
|
|
2165
|
+
scheduleDebounceFlush();
|
|
2166
|
+
}
|
|
1936
2167
|
return true;
|
|
1937
2168
|
};
|
|
1938
2169
|
const sendSessionLifecycleEvent = (eventName, reason, sessionOverride) => {
|
|
1939
2170
|
return sendEvent(eventName, {
|
|
1940
2171
|
reason,
|
|
1941
|
-
}, sessionOverride);
|
|
2172
|
+
}, sessionOverride, undefined, true);
|
|
1942
2173
|
};
|
|
1943
2174
|
const stopSession = (reason) => {
|
|
2175
|
+
console.log('stopping session');
|
|
1944
2176
|
if (!hasSessionStarted || sessionStopSent) {
|
|
1945
2177
|
return false;
|
|
1946
2178
|
}
|
|
@@ -2008,7 +2240,7 @@
|
|
|
2008
2240
|
lifecycleListenersAttached = true;
|
|
2009
2241
|
};
|
|
2010
2242
|
return {
|
|
2011
|
-
track: (eventName, payload) => {
|
|
2243
|
+
track: (eventName, payload, options) => {
|
|
2012
2244
|
attachLifecycleListeners();
|
|
2013
2245
|
const isSessionStopEvent = eventName === SESSION_STOP_EVENT;
|
|
2014
2246
|
if (!hasSessionStarted &&
|
|
@@ -2033,7 +2265,7 @@
|
|
|
2033
2265
|
resetIdleTimer();
|
|
2034
2266
|
}
|
|
2035
2267
|
const sessionForEvent = activeSession;
|
|
2036
|
-
const didSend = sendEvent(eventName, payload, sessionForEvent);
|
|
2268
|
+
const didSend = sendEvent(eventName, payload, sessionForEvent, options, eventName === SESSION_START_EVENT || eventName === SESSION_STOP_EVENT);
|
|
2037
2269
|
if (isSessionStopEvent && didSend) {
|
|
2038
2270
|
activeSession = undefined;
|
|
2039
2271
|
}
|
|
@@ -2111,14 +2343,14 @@
|
|
|
2111
2343
|
const result = this.analytics.track('pageView', telemetryPayload);
|
|
2112
2344
|
return typeof result === 'boolean' ? result : true;
|
|
2113
2345
|
}
|
|
2114
|
-
logEvent(event = {}) {
|
|
2346
|
+
logEvent(event = {}, trackOptions) {
|
|
2115
2347
|
const telemetryPayload = createEventLog({
|
|
2116
2348
|
event,
|
|
2117
2349
|
dimensionLookup: this.dimensions,
|
|
2118
2350
|
metricLookup: this.metrics,
|
|
2119
2351
|
});
|
|
2120
2352
|
const { name } = telemetryPayload;
|
|
2121
|
-
const result = this.analytics.track(name, telemetryPayload);
|
|
2353
|
+
const result = this.analytics.track(name, telemetryPayload, trackOptions);
|
|
2122
2354
|
return typeof result === 'boolean' ? result : true;
|
|
2123
2355
|
}
|
|
2124
2356
|
}
|