Skip to content

Commit

Permalink
adjust DNT logic (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
fvanham-coveo authored Mar 22, 2024
1 parent 17e3660 commit 8989dc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/client/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {IAnalyticsRequestOptions} from './analyticsRequestClient';
import {CookieAndLocalStorage, CookieStorage, NullStorage} from '../storage';
import HistoryStore from '../history';
import {mockFetch} from '../../tests/fetchMock';
import {BrowserRuntime} from './runtimeEnvironment';
import {BrowserRuntime, NoopRuntime} from './runtimeEnvironment';
import * as doNotTrack from '../donottrack';
import {Cookie} from '../cookieutils';
import {CoveoLinkParam} from '../plugins/link';
import {NoopAnalytics} from './noopAnalytics';

const aVisitorId = '123';
jest.mock('uuid', () => ({
Expand Down Expand Up @@ -663,7 +664,7 @@ describe('doNotTrack', () => {

let client = new CoveoAnalyticsClient({});

expect(client.runtime).toBeInstanceOf(BrowserRuntime);
expect(client.runtime).toBeInstanceOf(NoopRuntime);
expect(client.runtime.storage).toBeInstanceOf(NullStorage);
});

Expand Down
5 changes: 3 additions & 2 deletions src/client/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
preprocessRequest: this.options.preprocessRequest,
};

this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
if (doNotTrack()) {
this.runtime.storage = new NullStorage();
this.runtime = new NoopRuntime();
} else {
this.runtime = this.options.runtimeEnvironment || this.initRuntime(clientsOptions);
}

this.addEventTypeMapping(EventType.view, {newEventType: EventType.view, addClientIdParameter: true});
Expand Down

0 comments on commit 8989dc3

Please sign in to comment.