Skip to content

Commit

Permalink
Remove @guardian/braze-components (#26880)
Browse files Browse the repository at this point in the history
DRR are happy that frontend represents a small enough percentage of
pageviews and Braze message impressions that we can stop rendering
Braze messages here.

There is some Braze code remaining here. If a user changes their
consents or logs out we still want to clear any data set locally by
either our own code or the Braze web SDK. I've inlined a small amount of
code from @guardian/braze-components around clearing the local message
cache.
  • Loading branch information
tjmw authored Feb 12, 2024
1 parent ad57e84 commit 643b214
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 438 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@guardian/ab-core": "^5.0.0",
"@guardian/atom-renderer": "^2.0.0",
"@guardian/automat-modules": "^0.3.8",
"@guardian/braze-components": "^16.3.0",
"@guardian/commercial": "14.4.1",
"@guardian/consent-management-platform": "13.7.3",
"@guardian/core-web-vitals": "^5.0.0",
Expand Down
63 changes: 9 additions & 54 deletions static/src/javascripts/bootstraps/enhanced/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,16 @@ import { init as initIdentity } from 'bootstraps/enhanced/identity-common';
import { init as initBannerPicker } from 'common/modules/ui/bannerPicker';
import { trackConsentCookies } from 'common/modules/analytics/send-privacy-prefs';
import { getAllAdConsentsWithState } from 'common/modules/commercial/ad-prefs.lib';
import ophan from 'ophan/ng';
import { adFreeBanner } from 'common/modules/commercial/ad-free-banner';
import { init as initReaderRevenueDevUtils } from 'common/modules/commercial/reader-revenue-dev-utils';
import {
cmpBannerCandidate,
addPrivacySettingsLink,
} from 'common/modules/ui/cmp-ui';
import { signInGate } from 'common/modules/identity/sign-in-gate';
import { buildBrazeBanner } from 'common/modules/commercial/braze/brazeBanner';
import { buildBrazeMessaging } from 'common/modules/commercial/braze/buildBrazeMessaging';
import { handleBraze } from 'common/modules/commercial/braze/buildBrazeMessaging';
import { readerRevenueBanner } from 'common/modules/commercial/reader-revenue-banner';
import { init as initGoogleAnalytics } from 'common/modules/tracking/google-analytics';
import { bufferedNotificationListener } from 'common/modules/bufferedNotificationListener';
import { eitherInOktaExperimentOrElse } from 'common/modules/identity/api';

const initialiseTopNavItems = () => {
Expand Down Expand Up @@ -262,71 +259,28 @@ const initPublicApi = () => {
window.guardian.api = {};
};

const initialiseHeaderNotifications = (brazeCardsPromise) => {
const isValid = (card) => Boolean(
card.extras.target
&& card.extras.message
&& card.extras.ophanLabel
);

brazeCardsPromise.then(brazeCards => {
return brazeCards.getCardsForProfileBadge();
}).then(cards => {
const notifications = cards.filter((card) => isValid(card))
.map((card) => {
return {
id: card.id,
target: card.extras.target,
message: card.extras.message,
ophanLabel: card.extras.ophanLabel,
logImpression: () => {
card.logImpression();
}
};
})

if (notifications.length > 0) {
bufferedNotificationListener.emit(notifications);
}
})
};

const initialiseBanner = (brazeMessagesPromise) => {
const brazeBanner = buildBrazeBanner(brazeMessagesPromise);

const initialiseBanner = () => {
const isPreview = config.get('page.isPreview', false)
// ordered by priority
// in preview we don't want to show most banners as they are an unnecessary interruption
// however braze banner does use preview for testing
const bannerList = isPreview ? [
cmpBannerCandidate,
brazeBanner,
] : [
cmpBannerCandidate,
signInGate,
membershipBanner,
readerRevenueBanner,
adFreeBanner,
brazeBanner,
];

initBannerPicker(bannerList);
};

const initialiseMessageSlots = () => {
const brazeMessagingPromise = buildBrazeMessaging();

const brazeMessagesPromise = brazeMessagingPromise.then(
({ brazeMessages }) => brazeMessages
);
const brazeCardsPromise = brazeMessagingPromise.then(
({ brazeCards }) => brazeCards
);

initialiseBanner(brazeMessagesPromise);
initialiseHeaderNotifications(brazeCardsPromise);
};

const handleBrazeAndReportErrors = () => {
handleBraze().catch((err) => {
reportError(err, { module: 'c-braze' })
});
}

const initialiseConsentCookieTracking = () =>
trackConsentCookies(getAllAdConsentsWithState());
Expand Down Expand Up @@ -361,7 +315,8 @@ const init = () => {
['c-media-listeners', mediaListener],
['c-accessibility-prefs', initAccessibilityPreferences],
['c-membership', initMembership],
['c-message-slots', initialiseMessageSlots],
['c-banner', initialiseBanner],
['c-braze', handleBrazeAndReportErrors],
['c-reader-revenue-dev-utils', initReaderRevenueDevUtils],
['c-add-privacy-settings-link', addPrivacySettingsLink],
['c-load-google-analytics', loadGoogleAnalytics],
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 643b214

Please sign in to comment.