Immutable solution version
Waiting for the Braze SDK to be ready when loaded via GTM
Complete solution
When the Braze Web SDK loads async (e.g. via GTM), don't poll window.braze yourself.
Waiting for the Braze SDK to be ready when loaded via GTM
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.
Context from the issue
gh:braze-inc/braze-web-sdk#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? 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.
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 1 · 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>