Skip to content

Commit aeae927

Browse files
committed
Drop onetrust
1 parent 576df1a commit aeae927

File tree

8 files changed

+5
-189
lines changed

8 files changed

+5
-189
lines changed

packages/analytics-nextjs/src/AnalyticsProvider.tsx

Lines changed: 4 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@
55
import type { Analytics, Integrations, Plugin, UserOptions } from '@segment/analytics-next';
66
import { AnalyticsBrowser } from '@segment/analytics-next';
77
import type { CookieOptions } from '@segment/analytics-next/dist/types/core/storage';
8-
import { usePathname } from 'next/navigation';
98
import Script from 'next/script';
109
import PlausibleProvider from 'next-plausible';
1110
import type { PropsWithChildren } from 'react';
1211
import { createContext, useContext, useEffect, useState } from 'react';
1312

14-
import {
15-
getConsentCookie,
16-
getOnetrustCookieConsentStatus,
17-
isTrackingCookieAllowed,
18-
setConsentCookie,
19-
} from './lib';
13+
import { isTrackingCookieAllowed, setConsentCookie } from './lib';
2014
import { normalizePrezlyMetaPlugin, sendEventToPrezlyPlugin } from './plugins';
2115
import { TrackingPolicy } from './types';
2216
import type {
@@ -64,8 +58,6 @@ interface Props {
6458
ignoreConsent?: boolean;
6559
}
6660

67-
const ONETRUST_INTEGRATION_EVENT = 'OnetrustConsentModalCallback';
68-
6961
export const AnalyticsContext = createContext<Context | undefined>(undefined);
7062

7163
export function useAnalyticsContext() {
@@ -136,19 +128,7 @@ export function AnalyticsProvider({
136128
uuid,
137129
} = newsroom || {};
138130

139-
const isOnetrustIntegrationEnabled = newsroom?.onetrust_cookie_consent.is_enabled ?? false;
140-
const onetrustCookieCategory = newsroom?.onetrust_cookie_consent?.category ?? '';
141-
const onetrustIntegrationScript = newsroom?.onetrust_cookie_consent?.script ?? '';
142-
143-
const [consent, setConsent] = useState<boolean | null>(() => {
144-
if (ignoreConsent) {
145-
return true;
146-
}
147-
if (isOnetrustIntegrationEnabled) {
148-
return getOnetrustCookieConsentStatus(onetrustCookieCategory);
149-
}
150-
return getConsentCookie();
151-
});
131+
const [consent, setConsent] = useState<boolean | null>(null);
152132
const [analytics, setAnalytics] = useState<Analytics | undefined>(undefined);
153133

154134
useEffect(() => {
@@ -221,27 +201,10 @@ export function AnalyticsProvider({
221201
]);
222202

223203
useEffect(() => {
224-
if (!ignoreConsent && typeof consent === 'boolean' && !isOnetrustIntegrationEnabled) {
204+
if (!ignoreConsent && typeof consent === 'boolean') {
225205
setConsentCookie(consent);
226206
}
227-
}, [consent, ignoreConsent, isOnetrustIntegrationEnabled]);
228-
229-
useEffect(() => {
230-
if (!isOnetrustIntegrationEnabled || !onetrustCookieCategory) {
231-
// Only execute the effect if the OneTrust integration is enabled.
232-
return noop;
233-
}
234-
235-
function handleEvent() {
236-
setConsent(getOnetrustCookieConsentStatus(onetrustCookieCategory));
237-
}
238-
239-
document.body.addEventListener(ONETRUST_INTEGRATION_EVENT, handleEvent);
240-
241-
return () => {
242-
document.body.removeEventListener(ONETRUST_INTEGRATION_EVENT, handleEvent);
243-
};
244-
}, [isOnetrustIntegrationEnabled, onetrustCookieCategory]);
207+
}, [consent, ignoreConsent]);
245208

246209
return (
247210
<AnalyticsContext.Provider
@@ -257,9 +220,6 @@ export function AnalyticsProvider({
257220
trackingPolicy,
258221
}}
259222
>
260-
{isOnetrustIntegrationEnabled && onetrustIntegrationScript && (
261-
<OnetrustCookieIntegration script={onetrustIntegrationScript} />
262-
)}
263223
<GoogleAnalyticsIntegration analyticsId={newsroom?.google_analytics_id ?? null} />
264224
<PlausibleProviderMaybe
265225
isEnabled={isEnabled || isPlausibleEnabled}
@@ -272,44 +232,6 @@ export function AnalyticsProvider({
272232
);
273233
}
274234

275-
function OnetrustCookieIntegration(props: { script: string }) {
276-
const path = usePathname();
277-
278-
/*
279-
* @see https://my.onetrust.com/s/article/UUID-69162cb7-c4a2-ac70-39a1-ca69c9340046?language=en_US#UUID-69162cb7-c4a2-ac70-39a1-ca69c9340046_section-idm46212287146848
280-
*/
281-
useEffect(() => {
282-
document.getElementById('onetrust-consent-sdk')?.remove();
283-
284-
if (window.OneTrust) {
285-
window.OneTrust.Init();
286-
287-
setTimeout(() => {
288-
window.OneTrust?.LoadBanner();
289-
}, 1000);
290-
}
291-
}, [path]);
292-
293-
return (
294-
<div
295-
id="onetrust-cookie-consent-integration"
296-
dangerouslySetInnerHTML={{
297-
__html: `
298-
${props.script}
299-
<script>
300-
window.OptanonWrapper = (function () {
301-
const prev = window.OptanonWrapper || function() {};
302-
return function() {
303-
prev();
304-
document.body.dispatchEvent(new Event("${ONETRUST_INTEGRATION_EVENT}")); // allow listening to the OptanonWrapper callback from anywhere.
305-
};
306-
})();
307-
</script>`,
308-
}}
309-
/>
310-
);
311-
}
312-
313235
function GoogleAnalyticsIntegration(props: { analyticsId: string | null }) {
314236
if (props.analyticsId?.startsWith('GTM-')) {
315237
return <GoogleTagManager analyticsId={props.analyticsId as `GTM-${string}`} />;
@@ -366,7 +288,3 @@ function GoogleAnalytics(props: { analyticsId: string }) {
366288
</>
367289
);
368290
}
369-
370-
function noop() {
371-
// nothing
372-
}

packages/analytics-nextjs/src/__mocks__/newsroom.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ export const DEFAULT_NEWSROOM: Newsroom = {
136136
custom_privacy_policy_link: null,
137137
custom_data_request_link: null,
138138
tracking_policy: Newsroom.TrackingPolicy.DEFAULT,
139-
onetrust_cookie_consent: {
140-
is_enabled: false,
141-
category: '',
142-
script: '',
143-
},
144139
ga_tracking_id: null,
145140
google_analytics_id: null,
146141
segment_analytics_id: '',
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
declare interface Window {
2-
OnetrustActiveGroups?: string;
3-
OneTrust?: {
4-
Init(): void;
5-
ToggleInfoDisplay(): void;
6-
LoadBanner(): void;
7-
Close(): void;
8-
AllowAll(): void;
9-
RejectAll(): void;
10-
};
11-
}
1+
declare interface Window {}

packages/analytics-nextjs/src/hooks/useCookieConsent.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

packages/analytics-nextjs/src/lib/getOnetrustCookieConsentStatus.test.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/analytics-nextjs/src/lib/getOnetrustCookieConsentStatus.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/analytics-nextjs/src/lib/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './cookieState';
22
export * from './getApiUrl';
3-
export * from './getOnetrustCookieConsentStatus';
43
export * from './getRecipientInfo';
54
export * from './isTrackingCookieAllowed';
65
export * from './stringify';

packages/analytics-nextjs/src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export type PickedNewsroomProperties = Pick<
2626
| 'google_analytics_id'
2727
| 'is_plausible_enabled'
2828
| 'plausible_site_id'
29-
| 'onetrust_cookie_consent'
3029
>;
3130

3231
export type PickedStoryProperties = Pick<Story, 'uuid'>;

0 commit comments

Comments
 (0)