Docs / Entwickler
Dieser Artikel wird auf Englisch angezeigt.
JavaScript SDK
The browser SDK registers the service worker, asks for permission according to your prompt settings, and stores the push subscription against your site.
Snippet
The snippet loads en-sdk.js from EngageNudge, so SDK fixes reach your site without you re-uploading anything. The dashboard snippet looks like this:
<script
src="https://engagenudge.com/sdk/v1/en-sdk.js"
data-site-key="YOUR_SITE_KEY"
data-vapid="YOUR_VAPID_PUBLIC_KEY"
data-api="https://api.engagenudge.com"
data-tenant-id="YOUR_TENANT_ID"
data-site-id="YOUR_SITE_ID"
async
></script>The API host is https://api.engagenudge.com.
You still host /en-sw.js yourself. A browser only accepts a service worker served from the page origin, but it is now a stub that imports the logic from us. See Service worker.
Versions
| URL | Cache | When to use |
|---|---|---|
https://engagenudge.com/sdk/v1/en-sdk.js | 1 hour, revalidated in the background | Default. Picks up every backward-compatible fix. |
https://engagenudge.com/sdk/1.0.0/en-sdk.js | Immutable | Pin an exact build. You upgrade by editing the URL. |
The v1 channel only ever carries backward-compatible builds. A breaking change would ship as /sdk/v2/.
Moving off a self-hosted en-sdk.js
Older installs copied en-sdk.js into their own web root. Those keep working, but they stay on the build you uploaded, and Install Doctor reports sdk_outdated once that build falls behind.
- Change
src="/en-sdk.js"tosrc="https://engagenudge.com/sdk/v1/en-sdk.js". Nothing else in the snippet changes. - Replace
/en-sw.jswith the stub from Integrations so worker fixes reach you too. Keeping the full file also works. - Delete the old
en-sdk.jsfrom your web root once the new snippet is live. - If you send a CSP, allow
https://engagenudge.cominscript-src. See CSP.
What the SDK does
- Reads
data-site-key,data-vapid, anddata-api - Registers
/en-sw.js - Shows your configured opt-in prompt, then the native permission dialog
- Sends the subscription to the API (tenant-scoped)
Do not put the VAPID private key in the page. Only the public key belongs in data-vapid.
Behavior events
track() posts to POST /v1/behavior-events. Commerce automations that consume those events are off by default. See Behavior events.
npm
A packaged SDK exists for builds that prefer an import over the snippet. The snippet path is the supported default for WordPress, GTM, and most sites.