Appboy must be initialized before calling methods: fix
The Braze Web SDK throws "Appboy must be initialized before calling methods." when a method such as logCustomEvent runs before initialize. Call initialize with your API key and base URL first, then everything else. If it keeps happening, check load order, async scripts and framework lifecycles.
Sohail Hussain8 min readShort answer
- The error means your code called a Braze Web SDK method such as logCustomEvent before initialize had run, so the SDK has no API key or endpoint yet.
- Call initialize first (appboy.initialize in older snippets, braze.initialize in newer SDK versions), and route every other SDK call through one place that runs after it.
- If the order looks right in your code, check for queued calls replaying on script load, async or deferred scripts, framework lifecycles and consent gates that skip initialization.
You open the browser console and see this, usually right after adding a tracking call or changing how the SDK loads:
Appboy must be initialized before calling methods.
The word "Appboy" is left over from the SDK's original name. Your SDK may expose braze instead of appboy, but the message and the cause are the same. Check your SDK version's documentation for the current namespace and method names.
Why it happens
The SDK keeps internal state (API key, base URL, session and user data) that only initialize creates. Public methods check for that state and throw if it is missing, rather than silently dropping your event.
This is a client-side JavaScript error raised in the browser. No server, SMTP reply or email delivery problem is involved. It was reported in the braze-web-sdk repository on GitHub (issue 63, from 2019), and the maintainer's answer there was to call initialize first. Because that thread is old, confirm method names and behavior against the current Braze Web SDK documentation.
The causes, most common first:
| Cause | Symptom | Fix |
|---|---|---|
A method runs before initialize | Error points at your own call | Reorder so initialize comes first |
| Queued calls replay on script load | Stack trace points into the SDK script | Initialize right after the loader snippet |
| Async or deferred script, SPA lifecycle | Works sometimes, fails on some page loads | One wrapper module that owns initialization |
| Initialization skipped or blocked | initialize is in your code but never runs | Check console, Network tab and consent gates |
Step-by-step fixes
Fix 1: put initialize before every other call
This is the most common case. A minimal reproduction:
// Throws: Appboy must be initialized before calling methods.
appboy.logCustomEvent("signup_clicked");
appboy.initialize("YOUR-API-KEY", { baseUrl: "YOUR-SDK-ENDPOINT" });
Reorder it:
appboy.initialize("YOUR-API-KEY", { baseUrl: "YOUR-SDK-ENDPOINT" });
appboy.openSession();
appboy.logCustomEvent("signup_clicked");
- Put a
console.logon the line withinitializeand another on the line that throws. - Reload the page with the console open. If the throwing line prints first, you have an ordering bug.
- Move
initializeabove every other SDK call, then callopenSession. - Take the API key and SDK endpoint from your Braze dashboard; the endpoint depends on your Braze cluster.
Fix 2: handle queued calls that replay on script load
The standard Braze loader snippet defines stub methods that queue calls made before the real library has downloaded. When the script finishes loading, the queue replays in order. So a call you made early can run against a library that has not been initialized, and the throw happens at replay time, not at the line you wrote. That is why the stack trace can point into the SDK's own script instead of your code.
- Put the
initializecall in the same snippet, immediately after the loader and before any other SDK call. - Search your codebase for every call to
logCustomEvent,changeUser,openSession,logPurchaseand similar. Confirm none can execute before that snippet. - If a tag manager injects your event calls, use its tag sequencing so the initialization tag fires first.
Read the stack trace twice
If the trace points into the SDK file rather than your code, suspect the replay queue. Look for the earliest SDK call on the page, not the line named in the error.
Fix 3: sort out async loading and framework lifecycles
In single-page apps the order is less obvious. Typical traps:
- A component's mount hook fires an event before the app root has initialized the SDK.
- The SDK script loads with
asyncordefer, and your inline code runs before it arrives. - Two bundles each call the SDK, and the one that does not initialize runs first.
- Server-side rendering: the code runs on the server, where there is no browser SDK.
The sturdiest pattern is one wrapper module that owns initialization:
let ready = false;
export function initBraze() {
if (ready) return;
appboy.initialize("YOUR-API-KEY", { baseUrl: "YOUR-SDK-ENDPOINT" });
appboy.openSession();
ready = true;
}
export function trackEvent(name, props) {
if (!ready) initBraze();
appboy.logCustomEvent(name, props);
}
Call initBraze() once at app startup, in the browser only: inside useEffect in React, mounted in Vue, or behind a typeof window !== "undefined" check. Because trackEvent checks the flag too, a stray early call initializes instead of throwing. I'd keep this wrapper even after the bug is fixed.
Fix 4: confirm initialization actually ran
If initialize comes first in your code but the error persists, check whether it ran at all.
- Open the browser console and look for an earlier error, such as a missing or blocked script.
- Open the Network tab and reload. If the SDK file failed to load, or an ad blocker or content security policy blocked it, the real library never arrived.
- Make sure
initializeis not inside a conditional (consent check, feature flag) that sometimes skips it while other code still calls the SDK.
Consent gates need to cover every call
If you hold back initialization until the visitor gives consent, hold back every SDK call the same way. Otherwise users who decline will trigger this error on each event.
Checklist before you try again
initializeruns once, before anylogCustomEvent,changeUser,logPurchaseor similar call.- The API key and SDK endpoint match your Braze workspace and cluster.
- The SDK script loads without errors in the Network tab (no ad blocker, no CSP block).
- No SDK code runs on the server during server-side rendering.
- Tag manager tags that send events fire after the initialization tag.
- Every consent or feature-flag condition around
initializealso wraps your SDK calls.
Preventing it
- Keep one initialization point and route all SDK calls through it.
- Avoid calling the SDK from module top-level code that can run early.
- Guard server-rendered code so SDK calls only run in the browser.
- Fire a test event right after page load in staging.
If nothing works
If the order is correct, the key and endpoint are right, and the error still appears, contact Braze support through your Braze dashboard or account team. Include your SDK version, how you load it (snippet, npm package or tag manager), the full stack trace, the browser and version, and a minimal reproduction. A short message you can adapt:
Subject: Web SDK error "Appboy must be initialized before calling methods."
Hi Braze support,
Our site throws "Appboy must be initialized before calling methods." in the browser console.
SDK version: {version}
Loaded via: {snippet / npm package / tag manager}
Browser and version: {browser}
Page URL where it happens: {url}
Full stack trace: {paste}
What we have tried: confirmed initialize runs before other SDK calls, checked the Network tab for blocked scripts, tested with ad blockers off.
Minimal reproduction: {paste code}
Can you confirm whether anything in our setup would cause initialize to be skipped?
Common questions
Why does the error say "Appboy" when I use braze?
Appboy was the SDK's original name, and the message text kept it. The error is the same one whichever namespace your version uses.
Does this error affect email delivery?
No. It is a browser JavaScript error. Nothing in it involves SMTP, bounces or sending, so email deliverability is unaffected.
Can I call logCustomEvent before the SDK script finishes downloading?
The loader snippet queues early calls and replays them once the library loads, so it can work. The risk is that the replay runs before initialize, which is why initialize belongs right after the loader.
The error only happens on some page loads. Why?
That points to a race: an async or deferred script, a component mounting early, or a tag manager firing tags out of order. A single wrapper that initializes on first use removes the race.
Explore: Email Marketing Strategy
Related Articles
414 Request-URI Too Large in n8n's Amazon SES node: fix
The error 414 Request-URI Too Large in n8n's AWS SES node means a server in the path refused a request whose URL was too long, which a long HTML body can cause when it travels in the URL. Send through the SES v2 API with an HTTP Request node, or use SES SMTP.
Access denied, bad outbound sender: Outlook cold email fix
"Access denied, bad outbound sender" (550 5.1.8) means Microsoft 365 has put your mailbox on its restricted users list for spam-like sending. An admin must unblock it under Restricted entities in the Microsoft Defender portal. Then clean your list, lower your volume and resume gradually.
Acoustic Campaign "Application error" on login: bookmark fix
Acoustic Campaign shows "application error" at login when you open it from a bookmark saved while you were logged in, because the bookmark carries the old session. Log out, type your pod URL (campaign-us-[X].goacoustic.com) into the address bar, log in, then save a fresh bookmark.
ActiveCampaign 502 Bad Gateway and Tags Failed to Load: Fixes
"Bad gateway Error code 502" in ActiveCampaign means Cloudflare, the proxy in front of the app, got no valid response from ActiveCampaign's servers. That is usually their side. Check the status page, retry in a clean browser session, clear cookies, then send support the Ray ID if it persists.
Ready to supercharge your email marketing?
Start sending smarter emails with AI-powered campaigns. No credit card required.
Get Started Free