diff --git a/packages/analytics-browser/src/browser-client.ts b/packages/analytics-browser/src/browser-client.ts index 929d3cb34..c429eeb94 100644 --- a/packages/analytics-browser/src/browser-client.ts +++ b/packages/analytics-browser/src/browser-client.ts @@ -1,17 +1,16 @@ +import { AmplitudeCore, Destination, Identify, returnWrapper, Revenue, UUID } from '@amplitude/analytics-core'; import { - IdentityEventSender, getAnalyticsConnector, getAttributionTrackingConfig, getPageViewTrackingConfig, + IdentityEventSender, isAttributionTrackingEnabled, + isSessionTrackingEnabled, isFileDownloadTrackingEnabled, isFormInteractionTrackingEnabled, - isSessionTrackingEnabled, setConnectorDeviceId, - setConnectorOptOut, setConnectorUserId, } from '@amplitude/analytics-client-common'; -import { AmplitudeCore, Destination, Identify, Revenue, UUID, returnWrapper } from '@amplitude/analytics-core'; import { BrowserClient, BrowserConfig, @@ -22,15 +21,15 @@ import { Revenue as IRevenue, TransportType, } from '@amplitude/analytics-types'; -import { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser'; +import { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper'; +import { Context } from './plugins/context'; +import { useBrowserConfig, createTransport } from './config'; import { webAttributionPlugin } from '@amplitude/plugin-web-attribution-browser'; -import { createTransport, useBrowserConfig } from './config'; +import { pageViewTrackingPlugin } from '@amplitude/plugin-page-view-tracking-browser'; +import { formInteractionTracking } from './plugins/form-interaction-tracking'; +import { fileDownloadTracking } from './plugins/file-download-tracking'; import { DEFAULT_SESSION_END_EVENT, DEFAULT_SESSION_START_EVENT } from './constants'; import { detNotify } from './det-notification'; -import { Context } from './plugins/context'; -import { fileDownloadTracking } from './plugins/file-download-tracking'; -import { formInteractionTracking } from './plugins/form-interaction-tracking'; -import { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper'; export class AmplitudeBrowser extends AmplitudeCore implements BrowserClient { // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -150,11 +149,6 @@ export class AmplitudeBrowser extends AmplitudeCore implements BrowserClient { setConnectorDeviceId(deviceId, this.config.instanceName); } - setOptOut(optOut: boolean): void { - setConnectorOptOut(optOut, this.config.instanceName); - super.setOptOut(optOut); - } - reset() { this.setDeviceId(UUID()); this.setUserId(undefined); diff --git a/packages/analytics-browser/test/browser-client.test.ts b/packages/analytics-browser/test/browser-client.test.ts index 1dcd6d2e3..72c858bd3 100644 --- a/packages/analytics-browser/test/browser-client.test.ts +++ b/packages/analytics-browser/test/browser-client.test.ts @@ -1,18 +1,18 @@ +import { AmplitudeBrowser } from '../src/browser-client'; +import * as core from '@amplitude/analytics-core'; +import * as Config from '../src/config'; +import * as CookieMigration from '../src/cookie-migration'; +import { UserSession } from '@amplitude/analytics-types'; import { CookieStorage, FetchTransport, getAnalyticsConnector, getCookieName, } from '@amplitude/analytics-client-common'; -import * as core from '@amplitude/analytics-core'; -import { UserSession } from '@amplitude/analytics-types'; -import * as webAttributionPlugin from '@amplitude/plugin-web-attribution-browser'; -import { AmplitudeBrowser } from '../src/browser-client'; -import * as Config from '../src/config'; -import * as CookieMigration from '../src/cookie-migration'; +import * as SnippetHelper from '../src/utils/snippet-helper'; import * as fileDownloadTracking from '../src/plugins/file-download-tracking'; import * as formInteractionTracking from '../src/plugins/form-interaction-tracking'; -import * as SnippetHelper from '../src/utils/snippet-helper'; +import * as webAttributionPlugin from '@amplitude/plugin-web-attribution-browser'; describe('browser-client', () => { let apiKey = ''; @@ -404,18 +404,6 @@ describe('browser-client', () => { }); }); - describe('setOptOut', () => { - test('should set opt out config', async () => { - const client = new AmplitudeBrowser(); - await client.init(API_KEY, undefined, { - ...attributionConfig, - }).promise; - expect(client.config.optOut).toBe(false); - client.setOptOut(true); - expect(client.config.optOut).toBe(true); - }); - }); - describe('reset', () => { test('should reset user id and generate new device id config', async () => { await client.init(apiKey, { defaultTracking }).promise; diff --git a/packages/analytics-client-common/package.json b/packages/analytics-client-common/package.json index d0b4fa9e8..5fc4b0a50 100644 --- a/packages/analytics-client-common/package.json +++ b/packages/analytics-client-common/package.json @@ -35,7 +35,7 @@ "url": "https://github.com/amplitude/Amplitude-TypeScript/issues" }, "dependencies": { - "@amplitude/analytics-connector": "^1.5.0", + "@amplitude/analytics-connector": "^1.4.8", "@amplitude/analytics-core": "^2.0.3", "@amplitude/analytics-types": "^2.1.1", "tslib": "^2.4.1" diff --git a/packages/analytics-client-common/src/analytics-connector.ts b/packages/analytics-client-common/src/analytics-connector.ts index 17f66087c..4d2fb87bb 100644 --- a/packages/analytics-client-common/src/analytics-connector.ts +++ b/packages/analytics-client-common/src/analytics-connector.ts @@ -13,7 +13,3 @@ export const setConnectorUserId = (userId: string | undefined, instanceName?: st export const setConnectorDeviceId = (deviceId: string, instanceName?: string): void => { getAnalyticsConnector(instanceName).identityStore.editIdentity().setDeviceId(deviceId).commit(); }; - -export const setConnectorOptOut = (optOut: boolean, instanceName?: string): void => { - getAnalyticsConnector(instanceName).identityStore.editIdentity().setOptOut(optOut).commit(); -}; diff --git a/packages/analytics-client-common/src/index.ts b/packages/analytics-client-common/src/index.ts index 4a30160eb..ab94858ff 100644 --- a/packages/analytics-client-common/src/index.ts +++ b/packages/analytics-client-common/src/index.ts @@ -1,13 +1,14 @@ -export { - getAnalyticsConnector, - setConnectorDeviceId, - setConnectorOptOut, - setConnectorUserId, -} from './analytics-connector'; export { CampaignParser } from './attribution/campaign-parser'; export { CampaignTracker } from './attribution/campaign-tracker'; -export { BASE_CAMPAIGN } from './attribution/constants'; +export { getQueryParams } from './query-params'; export { getCookieName, getOldCookieName } from './cookie-name'; +export { CookieStorage } from './storage/cookie'; +export { FetchTransport } from './transports/fetch'; +export { getAnalyticsConnector, setConnectorDeviceId, setConnectorUserId } from './analytics-connector'; +export { IdentityEventSender } from './plugins/identity'; +export { getLanguage } from './language'; +export { BASE_CAMPAIGN } from './attribution/constants'; +export { getGlobalScope } from './global-scope'; export { getPageViewTrackingConfig, getAttributionTrackingConfig, @@ -17,9 +18,3 @@ export { isPageViewTrackingEnabled, isSessionTrackingEnabled, } from './default-tracking'; -export { getGlobalScope } from './global-scope'; -export { getLanguage } from './language'; -export { IdentityEventSender } from './plugins/identity'; -export { getQueryParams } from './query-params'; -export { CookieStorage } from './storage/cookie'; -export { FetchTransport } from './transports/fetch'; diff --git a/packages/analytics-client-common/test/analytics-connector.test.ts b/packages/analytics-client-common/test/analytics-connector.test.ts index 990fa69e4..c764f992a 100644 --- a/packages/analytics-client-common/test/analytics-connector.test.ts +++ b/packages/analytics-client-common/test/analytics-connector.test.ts @@ -1,10 +1,5 @@ import { AnalyticsConnector } from '@amplitude/analytics-connector'; -import { - getAnalyticsConnector, - setConnectorDeviceId, - setConnectorOptOut, - setConnectorUserId, -} from '../src/analytics-connector'; +import { getAnalyticsConnector, setConnectorDeviceId, setConnectorUserId } from '../src/analytics-connector'; describe('analytics-connector', () => { describe('getAnalyticsConnector', () => { @@ -32,9 +27,6 @@ describe('analytics-connector', () => { updateUserProperties: function () { return this; }, - setOptOut: function () { - return this; - }, commit, }; const instance = new AnalyticsConnector(); @@ -62,9 +54,6 @@ describe('analytics-connector', () => { updateUserProperties: function () { return this; }, - setOptOut: function () { - return this; - }, commit, }; const instance = new AnalyticsConnector(); @@ -75,34 +64,4 @@ describe('analytics-connector', () => { expect(commit).toHaveBeenCalledTimes(1); }); }); - - describe('setConnectorOptOut', () => { - test('should commit opt out to connector instance', () => { - const commit = jest.fn(); - const identityEditor = { - setUserId: function () { - return this; - }, - setDeviceId: function () { - return this; - }, - setUserProperties: function () { - return this; - }, - updateUserProperties: function () { - return this; - }, - setOptOut: function () { - return this; - }, - commit, - }; - const instance = new AnalyticsConnector(); - jest.spyOn(instance.identityStore, 'editIdentity').mockReturnValueOnce(identityEditor); - const getInstance = jest.spyOn(AnalyticsConnector, 'getInstance').mockReturnValueOnce(instance); - expect(setConnectorOptOut(true)).toBe(undefined); - expect(getInstance).toHaveBeenCalledTimes(1); - expect(commit).toHaveBeenCalledTimes(1); - }); - }); });