Version 7 of the Braze Web SDK (@braze/web-sdk) changes how the Banner cache is refreshed and how cached Banners are returned. A refresh now updates only the placements it asked for, expired Banners are dropped from the cache rather than surfaced as null, and the banners map typings have been corrected to match.
It also changes when refresh callbacks are called for Banners, Content Cards, and Feature Flags, and adds new subscribeTo*Events() methods that replace the subscribeTo*Updates() methods.
-
requestBannersRefresh()no longer replaces the entire Banner cache. Previously each refresh discarded the cache and kept only the placements in that request. A refresh now updates only the placements it asked for and leaves every other placement in place, sogetAllBanners()can return placements from earlier requests rather than only the most recent one. If you were treating its result as "the placements from my last refresh", read the placements you need by ID, either from the map or withgetBanner(). -
getAllBanners()no longer includes expired Banners. Previously an expired Banner's placement ID mapped tonull; those placement IDs are now absent from the map entirely. Update code that iterates the returned keys, or that treats anullentry differently from a missing one. Reading a placement directly and checking for a falsy value continues to work unchanged. -
The success and error callbacks of
requestBannersRefresh(),requestContentCardsRefresh(), andrefreshFeatureFlags()are now called at most once per call, with the first result:- If the channel is not enabled, including before the first server config is received, the error callback is called right away. Previously, Banners and Content Cards waited for the server config and then called the callbacks with the refresh result.
- If the SDK refreshes again later, such as on an automatic retry or once the channel is enabled, the callbacks are not called again.
If your code waits for the success callback to know when fresh data is available, use
subscribeToBannersEvents(),subscribeToContentCardsEvents(), orsubscribeToFeatureFlagsEvents()instead. They receive every refresh result, including retries. -
Banners, Content Cards, and Feature Flags refreshes no longer retry automatically after a client error (an HTTP 4xx response other than 429). HTTP 429, 5xx, and network failures are still retried. The
subscribeTo*Events()methods report this as an error with aDO_NOT_RETRYretry state.
- The banners map returned by
getAllBanners(), and passed to thesubscribeToBannersUpdates()callback, is now typedRecord<string, Banner | undefined>instead ofRecord<string, Banner | null>. The map never contains anullvalue and reading an uncached placement yieldsundefined. Truthiness checks such asif (banners[placementId])are unaffected. Two cases need attention:- A check for
=== nullwill never match. Use a falsy check instead. - TypeScript code that explicitly annotates the
subscribeToBannersUpdatescallback parameter will fail to compile until the annotation is updated. Callbacks that rely on inference need no change.
- A check for
The following methods still work, but will be removed in a future major version:
Version 6 of the Braze Web SDK (@braze/web-sdk) removes the legacy News Feed feature and deprecated banner APIs, introduces stricter typings, and makes small rendering changes for improved accessibility.
- The
insertBanner()method now automatically tracks impressions and clicks. The separateBanner.html,logBannerClick(), andlogBannerImpressions()APIs have been removed. - The images in In-App Messages with
cropType: CENTER_CROP(e.g.FullScreenMessage) are now rendered using an<img>tag instead of a<span>. This improves accessibility but may require updating CSS customizations that target.ab-center-cropped-img. - TypeScript typings now reflect that some methods return
undefinedwhen the SDK has not been initialized. This can surface new TypeScript compile-time errors if your code assumed a value. Add guards/optional chaining, or refine types where needed.
The following methods and properties have been removed:
| API | Details |
|---|---|
braze.Banner.html / braze.logBannerClick() / braze.logBannerImpressions() |
Replaced by insertBanner(), which handles rendering, impressions, and clicks. |
Legacy News Feed (braze.Feed class) |
Fully removed, along with: destroyFeed(), getCachedFeed(), logFeedDisplayed(), requestFeedRefresh(), showFeed(), subscribeToFeedUpdates(), toggleFeed(). |
logCardClick() / logCardImpressions() |
Use logContentCardClick() and logContentCardImpressions() instead. |
Card.created and Card.categories |
Fields used by legacy News Feed and removed from Card subclasses. |
ImageOnly.linkText (and constructor param) |
Unused and removed. |
Version 5 of the Braze Web SDK (@braze/web-sdk) includes a few functional improvements and removal of previously deprecated APIs, thus improving the bundle size.
- The
subscribeToFeatureFlagsUpdates()callback will now always be called, regardless of refresh success/failure. If there is a failure in receiving updates, the callback will be called with currently cached feature flags. - The
getFeatureFlag()method now returnsnullif the feature flag does not exist. - The SDK no longer throws runtime errors anywhere. If Braze methods are called prior to initialization, a warning will be logged to the console instead.
- The SDK no longer adds default Braze in-app message styles to custom HTML in-app messages. These styles were previously used by legacy in-app message types.
The following methods and properties have been removed:
| API | Details |
|---|---|
braze.logContentCardsDisplayed() |
Obsolete, no-op method that has been deprecated since 4.0.4. |
enableHtmlInAppMessages initialization option |
Deprecated since 3.3.0 in favor of allowUserSuppliedJavascript option which has the same functionality |
braze.Banner class |
Deprecated since 4.9.0 in favor of braze.ImageOnly with the same functionality |
ab-banner CSS classname |
This is part of braze.Banner class removal. CSS customizations should instead target ab-image-only CSS class. |
Version 4 of the Braze Web SDK (@braze/web-sdk package) now supports tree-shaking 🎉 and has been rewritten as native, side-effect free ES Modules.
You can now import individual methods and classes, or use wildcard syntax to import the entire SDK. In both approaches, your javascript module bundlers can remove any unused code resulting in faster website performance.
import * as braze from "@braze/web-sdk";
// or, if you prefer to import individual modules:
// import { initialize } from "@braze/web-sdk";
braze.initialize("YOUR-API-KEY", { baseUrl: "YOUR-SDK-ENDPOINT" });
braze.automaticallyShowInAppMessages();
braze.subscribeToContentCardsUpdates(function(contentCards) {
console.log(contentCards);
});
braze.openSession();Version 4 has been rewritten as individually exported ES Modules. If you use a modern javascript bundler (like Webpack or Rollup) you can benefit from "tree-shaking", which automatically removes unused SDK code to make your website more performant.
The table below shows how many kilobytes you may save as a result of upgrading to v4. Note that these are estimates, and your bundle sizes may vary based on your webpage structure and the individual methods you actually use.
For context, version @braze/web-sdk@3.5 and @braze/web-sdk-core@3.5 weigh in at 51.9kB and 37.3kB respectively, whereas v4 starts at 25.5kB and builds based on features you use. The "Estimated Savings" column compares @braze/web-sdk@3.5 to importing only the given feature.
| Module or Feature | Estimated Size (gzipped) | Estimated Savings |
|---|---|---|
| Analytics | 0.9kB |
~ 49.1% reduction (26.4kB total) |
| Push | 2.4kB |
~ 46.2% reduction (27.9kB total) |
| Content Cards (no UI) | 4.5kB |
~ 44.1% reduction (29.0kB total) |
| Content Cards UI | 12.0kB |
~ 27.7% reduction (37.5kB total) |
| In-App Messages UI | 12.7kB |
~ 26.4% reduction (38.2kB total) |
Notes:
- "Analytics" was measured by including
logCustomEvent,setCustomUserAttribute, andchangeUsermethods. - "In-App Messages UI" was measured by including
automaticallyShowInAppMessagesorshowInAppMessage - "Content Cards UI" was measured by including
showContentCards,hideContentCardsortoggleContentCards - "Push" was measured by including
requestPushPermission
- The
automaticallyShowInAppMessages()orsubscribeToInAppMessage()methods must be called prior toopenSession()to ensure session-start triggered messages are processed. - Content Cards will now only refresh on session start if
subscribeToContentCardsUpdates()is called prior toopenSession. You can manually refresh Content Cards usingrequestContentCardsRefresh().
The following methods have been renamed:
| Old (v3.x) | New (v4.0) |
|---|---|
appboy.registerAppboyPushMessages() |
requestPushPermission() |
appboy.unregisterAppboyPushMessages() |
unregisterPush() |
appboy.automaticallyShowNewInAppMessages() |
automaticallyShowInAppMessages() |
appboy.toggleAppboyLogging() |
toggleLogging() |
appboy.display.* |
The appboy.display namespace has been removed. To upgrade, find and replace all references to appboy.display. with braze. |
The following methods and properties have been removed:
| API | Details |
|---|---|
appboy.isPushGranted() |
Deprecated since 1.6.2 in favor of isPushPermissionGranted() |
appboy.subscribeToNewInAppMessages() |
Deprecated since 2.4.0 in favor of subscribeToInAppMessage() |
appboy.trackLocation() |
Deprecated since 3.3.0 in favor of using the native Geolocation API and passing the location data to User.setLastKnownLocation(). The corresponding appboyBridge.trackLocation() method has also been removed. |
appboy.stopWebTracking() |
Deprecated since 3.5.0 in favor of using disableSDK() |
appboy.resumeWebTracking() |
Deprecated since 3.5.0 in favor of using enableSDK() |
safariWebsitePushId parameter from the appboy.registerAppboyPushMessages() method |
Deprecated & undocumented since 1.6.1 in favor of the initialization option with the same name |
devicePropertyWhitelist initialization option |
Deprecated since 3.1.0 in favor of devicePropertyAllowlist which has the same functionality |
language initialization option |
Use the localization option which has the same functionality |
cardId and campaignId properties of In-App Messages |
If you are manually constructing instances of InAppMessage subclasses, you will need to update the constructors (docs) |
User.setAvatarImageUrl() |
Method no longer used |
Version 3 of the Braze Web SDK (@braze/web-sdk) now comes bundled with TypeScript definitions!
The TypeScript defintions include documentation and autocomplete in IDEs that support it, even if your project does not use TypeScript.
Note: The SDK loading snippet has been updated. If you integrate the Braze Web SDK using the CDN, you must update the loading snippet when upgrading to 3.0.
The following breaking changes have been made to allow for a better TypeScript experience:
| API | details |
|---|---|
appboy.ab |
The ab namespace has been removed. To upgrade, find and replace all references to appboy.ab with appboy |
InAppMessage.Button |
Renamed to InAppMessageButton. To upgrade, find and replace all references to InAppMessage.Button with InAppMessageButton |
openSession(callback) |
The callback parameter has been removed since v2.3.1. |
changeUser(callback) |
The callback parameter has been removed since v2.3.1. |
baseUrl initialization option |
Now required to initialize the SDK. If your integration did not already provide the baseUrl option, it should now be set to the previous default value of sdk.iad-01.braze.com (e.g, appboy.initialize('YOUR-API-KEY', { baseUrl: 'sdk.iad-01.braze.com' });) |