Skip to content

Commit 960e9f5

Browse files
Merge pull request #13718 from guardian/@braze/web-sdk-v3-to-v4-to-v5
Upgrading Braze SDK from [email protected] to [email protected]
2 parents a0eff55 + a002dcd commit 960e9f5

File tree

6 files changed

+56
-56
lines changed

6 files changed

+56
-56
lines changed

dotcom-rendering/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
"@babel/preset-react": "7.26.3",
3131
"@babel/preset-typescript": "7.27.0",
3232
"@babel/runtime": "7.27.0",
33-
"@braze/web-sdk-core": "3.5.1",
33+
"@braze/web-sdk": "5.8.1",
3434
"@creditkarma/thrift-server-core": "1.0.4",
3535
"@emotion/babel-plugin": "11.13.5",
3636
"@emotion/cache": "11.14.0",
3737
"@emotion/react": "11.14.0",
3838
"@emotion/server": "11.11.0",
3939
"@guardian/ab-core": "8.0.0",
40-
"@guardian/braze-components": "22.0.0",
40+
"@guardian/braze-components": "22.2.0",
4141
"@guardian/bridget": "8.1.0",
4242
"@guardian/browserslist-config": "6.1.0",
4343
"@guardian/cdk": "50.13.0",

dotcom-rendering/src/components/StickyBottomBanner/BrazeBanner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const containerStyles = css`
4141
// - We're not on a Glabs paid content page
4242
// - We've got a Braze UUID from the API, given a user's ID Creds
4343
// - The user has given Consent via CCPA or TCFV2
44-
// - The Braze websdk appboy initialisation does not throw an error
44+
// - The Braze websdk initialisation does not throw an error
4545
// - The Braze app Boy subscription to in app message returns meta info
4646
// OR
4747
// - The force-braze-message query string arg is passed

dotcom-rendering/src/lib/braze/buildBrazeMessaging.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
setHasCurrentBrazeUser,
2020
} from '../hasCurrentBrazeUser';
2121
import { checkBrazeDependencies } from './checkBrazeDependencies';
22-
import { getInitialisedAppboy } from './initialiseAppboy';
22+
import { getInitialisedBraze } from './initialiseBraze';
2323

2424
const maybeWipeUserData = async (
2525
apiKey?: string,
@@ -35,8 +35,8 @@ const maybeWipeUserData = async (
3535
if (userHasLoggedOut || userHasRemovedConsent || brazeHasBeenDisabled) {
3636
try {
3737
if (apiKey) {
38-
const appboy = await getInitialisedAppboy(apiKey);
39-
appboy.wipeData();
38+
const braze = await getInitialisedBraze(apiKey);
39+
braze.wipeData();
4040
}
4141
LocalMessageCache.clear();
4242
clearHasCurrentBrazeUser();
@@ -98,7 +98,7 @@ export const buildBrazeMessaging = async (
9898
'braze-sdk-load',
9999
);
100100

101-
const appboy = await getInitialisedAppboy(
101+
const braze = await getInitialisedBraze(
102102
dependenciesResult.data.apiKey as string,
103103
);
104104

@@ -116,14 +116,14 @@ export const buildBrazeMessaging = async (
116116
};
117117

118118
setHasCurrentBrazeUser();
119-
appboy.changeUser(dependenciesResult.data.brazeUuid as string);
120-
appboy.openSession();
119+
braze.changeUser(dependenciesResult.data.brazeUuid as string);
120+
braze.openSession();
121121

122122
const brazeCards = window.guardian.config.switches.brazeContentCards
123-
? new BrazeCards(appboy, errorHandler)
123+
? new BrazeCards(braze, errorHandler)
124124
: new NullBrazeCards();
125125
const brazeMessages = new BrazeMessages(
126-
appboy,
126+
braze,
127127
LocalMessageCache,
128128
errorHandler,
129129
canRenderBrazeMsg,

dotcom-rendering/src/lib/braze/initialiseAppboy.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type * as braze from '@braze/web-sdk';
2+
import { isUndefined, log } from '@guardian/libs';
3+
4+
const SDK_OPTIONS: braze.InitializationOptions = {
5+
enableLogging: true,
6+
noCookies: true,
7+
baseUrl: 'https://sdk.fra-01.braze.eu/api/v3',
8+
sessionTimeoutInSeconds: 1,
9+
minimumIntervalBetweenTriggerActionsInSeconds: 0,
10+
devicePropertyAllowlist: [],
11+
};
12+
13+
const initialiseBraze = async (apiKey: string): Promise<typeof braze> => {
14+
const importedBraze = (await import(
15+
/* webpackChunkName: "braze-web-sdk-core" */ '@braze/web-sdk'
16+
)) as unknown as typeof braze;
17+
18+
importedBraze.setLogger((message) => log('tx', message));
19+
importedBraze.initialize(apiKey, SDK_OPTIONS);
20+
21+
return importedBraze;
22+
};
23+
24+
const getInitialisedBraze = (() => {
25+
let cache: Promise<typeof braze>;
26+
27+
return (apiKey: string): Promise<typeof braze> => {
28+
if (isUndefined(cache)) {
29+
cache = initialiseBraze(apiKey);
30+
}
31+
32+
return cache;
33+
};
34+
})();
35+
36+
export { getInitialisedBraze };

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)