Solution skill
Waiting for the Braze SDK to be ready when loaded via GTM
Complete solution
Shows how to fix waiting for the Braze SDK to be ready when loaded via GTM. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Upgrade to >= 5.4.0 to get both. From braze-web-sdk 5.4.0: wait on the ready event, window.addEventListener('braze.initialized', () => { / call getCachedContentCards() etc. here / }), or guard calls with braze.isInitialized().
Steps
- When the Braze Web SDK loads async (e.g. via GTM), don't poll window.braze yourself. From braze-web-sdk 5.4.0: wait on the ready event, window.addEventListener('braze.initialized', () => { / call getCachedContentCards() etc. here / }), or guard calls with braze.isInitialized(). Upgrade to >= 5.4.0 to get both.
When to use
You are seeing this: https://github.com/braze-inc/braze-web-sdk/issues/158: Issue braze-inc/braze-web-sdk#158 (closed, 11 comments): How to wait in a website for window.braze when it's loaded async? Use this skill when you run into "Waiting for the Braze SDK to be ready when loaded via GTM".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: braze-web-sdk 5.4.0. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Sources
- https://github.com/braze-inc/braze-web-sdk/issues/158:
Evidence
Issue gh:braze-inc/braze-web-sdk#158: the reporter asked: Issue braze-inc/braze-web-sdk#158 (closed, 11 comments): How to wait in a website for window.braze when it's loaded async? We load and initialize Braze with GTM, so in the website we are kind of waiting for window.braze in order to call getCachedContentCards and some other methods. But sometimes the SDK is not ready yet when our code runs. The verified answer was: When the Braze Web SDK loads async (e.g. via GTM), don't poll window.braze yourself. From braze-web-sdk 5.4.0: wait on the ready event, window.addEventListener('braze.initialized', () => { / call getCachedContentCards() etc. here / }), or guard calls with braze.isInitialized(). Upgrade to >= 5.4.0 to get both. Evidence thread: https://github.com/braze-inc/braze-web-sdk/issues/158
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_l186XEkURVDor53EcbuTIw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Waiting for the Braze SDK to be ready when loaded via GTM <span>— Vectle</span></a>