diff --git a/src/client/analyticsFetchClient.ts b/src/client/analyticsFetchClient.ts index bd41ff5..c4006c7 100644 --- a/src/client/analyticsFetchClient.ts +++ b/src/client/analyticsFetchClient.ts @@ -1,7 +1,8 @@ import {AnalyticsRequestClient, IAnalyticsRequestOptions, IAnalyticsClientOptions} from './analyticsRequestClient'; import {AnyEventResponse, EventType, IRequestPayload} from '../events'; -import {fetch} from 'cross-fetch'; +import {crossFetch} from 'cross-fetch'; +const isoFetch = fetch ?? crossFetch; export class AnalyticsFetchClient implements AnalyticsRequestClient { constructor(private opts: IAnalyticsClientOptions) {} @@ -25,7 +26,7 @@ export class AnalyticsFetchClient implements AnalyticsRequestClient { let response: Response; try { - response = await fetch(url, fetchData); + response = await isoFetch(url, fetchData); } catch (error) { console.error('An error has occured when sending the event.', error); return; diff --git a/src/donottrack.ts b/src/donottrack.ts index a09878d..70195bd 100644 --- a/src/donottrack.ts +++ b/src/donottrack.ts @@ -4,13 +4,13 @@ // gathering data of actions of an user as long as it is not associated to the // identity of that user, doNotTrack is not enabled here. -import {hasNavigator} from './detector'; +import {hasNavigator, hasWindow} from './detector'; const doNotTrackValues = ['1', 1, 'yes', true]; export function doNotTrack(): boolean { return ( - hasNavigator() && + hasNavigator() && hasWindow() && [ (navigator).globalPrivacyControl, (navigator).doNotTrack,