CleverTap error: Cannot set properties of undefined (getCleverTapID)
The CleverTap web error `Cannot set properties of undefined (setting "getCleverTapID")` means code ran against a `clevertap` object that did not exist yet. Declare the object from the docs snippet first, load the SDK once, and call methods only after it loads. Send a unique Identity per user.
Sohail Hussain9 min readShort answer
- This error means the SDK tried to assign a property on the clevertap object, but that object was undefined at that moment. The usual cause is load order, so declare the clevertap object from the docs snippet before the SDK script runs and call SDK methods only after it has loaded.
- Check typeof window.clevertap in the console, then work through the causes below. If you also see merged profiles, send a unique Identity per user.
You copied the web integration snippet from CleverTap's docs, loaded your page, and the console shows this:
Cannot set properties of undefined (setting "getCleverTapID")
I can't see inside CleverTap's minified file, so I won't claim to know the exact line that throws. What I can do is list the causes that fit this error and give you a fast way to tell which one is yours. The problem was reported on Stack Overflow in December 2021, and CleverTap's snippet may have changed since, so compare your code with the current web SDK docs before changing anything.
What the error means
This is a plain JavaScript TypeError, not a CleverTap account or network error. Something tried to write a property named getCleverTapID onto a value that was undefined. Current Chrome and Node phrase it as "Cannot set properties of undefined"; older engines said "Cannot set property 'x' of undefined".
Your account ID can be perfectly correct and you will still see it. The target of the assignment is the clevertap object or something attached to it. Either that object was never created, it was created in a scope the SDK can't see, or the SDK ran before your setup code did.
Why it happens
Most common first:
- The setup object is missing, reordered or scoped away from the SDK script.
- Your code calls an SDK method before the SDK has finished loading.
- A framework (SSR, hot reload, route changes) runs the snippet at the wrong time or twice.
- The script is blocked, or two copies are loaded.
Which one you have is easy to narrow down with the console.
How to tell which cause is yours
- Open the browser console and expand the error to read the stack trace. If the top frame is in the SDK file, the SDK ran without its setup object. If it is in your own bundle, your wrapper is calling something too early.
- After the page settles, type
typeof window.clevertap. - If it returns
"undefined", the setup line never ran, or it ran in a private scope. - If it returns
"object", the object exists now but did not exist when the error fired. That points to a timing problem.
Step-by-step fixes
Fix 1: keep the docs snippet whole and in global scope
The docs snippet declares the clevertap object with its queue arrays first, pushes your account ID, and only then injects the SDK script. If you copied just the injection part, or reordered it, the SDK has nothing to attach to. The shape to preserve looks like this (use your own account ID and the current script from CleverTap's docs, not mine):
<script type="text/javascript">
var clevertap = {event:[], profile:[], account:[], onUserLogin:[], notifications:[], privacy:[]};
clevertap.account.push({"id": "YOUR_ACCOUNT_ID"});
clevertap.privacy.push({optOut: false});
clevertap.privacy.push({useIP: false});
// the docs' script-injection block follows here, unchanged
</script>
- Put the whole block in the page head as one inline script.
- Do not split it across files or move the injection above the declaration.
- Make sure it is not wrapped in a function, ES module or tag manager sandbox. Inside those,
var clevertapis local and the SDK can't see it. - If you must run it from a module, assign
window.clevertap = {...}explicitly.
Fix 2: wait for the SDK before calling it
The arrays (event, profile, onUserLogin and so on) act as a queue before the script arrives. That is what they are for. Direct method calls, such as asking for the user's CleverTap ID, are a different matter: I'd treat them as unsafe until the SDK is loaded, because I can't confirm from the docs how each one behaves before load.
- Defer the call until the script's
loadevent or until your app has mounted. - While debugging, guard the call:
if (window.clevertap && typeof window.clevertap.getCleverTapID === "function") {
const id = window.clevertap.getCleverTapID();
}
If the guard fails on every call, go back to Fix 1.
Fix 3: single-page apps, SSR and the npm package
React, Angular, Vue and Next.js add their own ways to hit this.
- Server-side rendering runs your code where
windowdoes not exist. Import and initialize the SDK only in client-side code, for example in an effect that runs after mount. - With the npm package, initialize once at startup, as the docs describe, before any component uses it.
- Don't mix the npm package and the script snippet. Two copies compete for the same global.
- In TypeScript, a
declareline silences the compiler but does not create the object. - Hot reload and route changes can re-run initialization. Check
window.clevertapfirst so it runs once.
Fix 4: rule out blocking and duplicates
- Open the Network tab and reload. Look for a failed or blocked request to the SDK file.
- Test in an incognito window with extensions off. Ad blockers and privacy extensions sometimes block analytics hosts.
- If you use a Content Security Policy, check the console for CSP violations on the injected script.
- Search the page source for a second copy of the snippet. It often appears when both a tag manager and the site template include it.
Don't silence it with try/catch
Wrapping the call in try/catch hides the error but leaves the SDK uninitialized, so events and profile updates are silently lost. Fix the load order instead.
Cause, symptom and fix at a glance
| Cause | What you see | Fix |
|---|---|---|
| Setup object missing or reordered | typeof window.clevertap is "undefined" | Restore the full docs snippet in the head |
| Snippet inside a function or module | Object exists in your code, not on window | Assign window.clevertap explicitly |
| Method called before load | "object" later, error at page start | Defer calls until the SDK has loaded |
| SSR | Error on the server render only | Initialize in client-side code only |
| Script blocked | Failed request in Network tab | Test without extensions; check CSP |
| Two copies loaded | Snippet appears twice in source | Keep one source of the snippet |
The related iOS problem: same Identity for two users
A GitHub issue on CleverTap's iOS SDK repository gets mixed up with this error, but it is a different bug. The reporter saw onUserLogin appending identities when the same Identity was reused for two different users. It does not cause the web TypeError above; it matters only if you also see merged or duplicated profiles.
The fix is to send a unique, stable Identity per user, such as your internal user ID. Avoid shared placeholders like "guest" or a test value left in code, and call onUserLogin only at an actual login.
Use your own user ID
Pick an ID that never changes and is never shared, such as your database user ID. Email addresses work only if they are unique and stable in your system.
Checklist before you try again
- The full docs snippet sits in the head as one inline script.
typeof window.clevertapis"object"right after the snippet runs.- Only one copy of the snippet or package is loaded.
- SDK calls happen after load, and only in client-side code.
- The SDK request succeeds in the Network tab with extensions off.
- Each user has a unique Identity.
If nothing works
If typeof window.clevertap is "object", the script loads cleanly, and the error still fires, contact CleverTap support through your dashboard or their documentation site. This is a vendor SDK problem, so they are the authority on the current setup. Include the SDK version or script URL, the full console stack trace, the browser and version, whether you use the snippet or the npm package, and the steps above that you already tried.
Subject: Web SDK TypeError: Cannot set properties of undefined (setting "getCleverTapID")
Hi CleverTap support,
Our web integration throws this error on page load:
Cannot set properties of undefined (setting "getCleverTapID")
Details:
- Account ID: {your-account-id}
- Integration: {script snippet / npm package + version}
- Browser and version: {browser}
- Page URL: {url}
- Timestamp of the error: {date and time, timezone}
- typeof window.clevertap after load: {result}
- Already tried: full docs snippet in head, single copy, no extensions, client-side init only
Full console stack trace is attached. Could you confirm the current recommended setup for our framework?
Thanks,
{name}
Common questions
Is this error caused by a wrong account ID?
No. A wrong account ID produces failed requests or missing data, not a TypeError on an undefined object. This error is about code order and scope.
Does it only happen with React or Next.js?
No, the plain script snippet can trigger it if the declaration is missing or reordered. Frameworks make it more likely through SSR, modules and re-initialization.
Do I need a unique Identity to fix the TypeError?
No. The Identity problem is separate and affects profiles, not script execution. Fix load order first, then check Identities if your profiles look merged.
Can I just reload the SDK when it fails?
I'd avoid that. Loading it a second time risks duplicate copies fighting over the same global. Find out why the first load failed instead.
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