How-To

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 HussainSohail Hussain9 min read

Short 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:

  1. The setup object is missing, reordered or scoped away from the SDK script.
  2. Your code calls an SDK method before the SDK has finished loading.
  3. A framework (SSR, hot reload, route changes) runs the snippet at the wrong time or twice.
  4. 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

  1. 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.
  2. After the page settles, type typeof window.clevertap.
  3. If it returns "undefined", the setup line never ran, or it ran in a private scope.
  4. 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>
  1. Put the whole block in the page head as one inline script.
  2. Do not split it across files or move the injection above the declaration.
  3. Make sure it is not wrapped in a function, ES module or tag manager sandbox. Inside those, var clevertap is local and the SDK can't see it.
  4. 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.

  1. Defer the call until the script's load event or until your app has mounted.
  2. 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.

  1. Server-side rendering runs your code where window does not exist. Import and initialize the SDK only in client-side code, for example in an effect that runs after mount.
  2. With the npm package, initialize once at startup, as the docs describe, before any component uses it.
  3. Don't mix the npm package and the script snippet. Two copies compete for the same global.
  4. In TypeScript, a declare line silences the compiler but does not create the object.
  5. Hot reload and route changes can re-run initialization. Check window.clevertap first so it runs once.

Fix 4: rule out blocking and duplicates

  1. Open the Network tab and reload. Look for a failed or blocked request to the SDK file.
  2. Test in an incognito window with extensions off. Ad blockers and privacy extensions sometimes block analytics hosts.
  3. If you use a Content Security Policy, check the console for CSP violations on the injected script.
  4. 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

CauseWhat you seeFix
Setup object missing or reorderedtypeof window.clevertap is "undefined"Restore the full docs snippet in the head
Snippet inside a function or moduleObject exists in your code, not on windowAssign window.clevertap explicitly
Method called before load"object" later, error at page startDefer calls until the SDK has loaded
SSRError on the server render onlyInitialize in client-side code only
Script blockedFailed request in Network tabTest without extensions; check CSP
Two copies loadedSnippet appears twice in sourceKeep one source of the snippet

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.clevertap is "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.

strategyclevertaperror-codes
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

Building Mailneo — AI-powered email marketing for growing businesses.

Ready to supercharge your email marketing?

Start sending smarter emails with AI-powered campaigns. No credit card required.

Get Started Free