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:

html
<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

URLCacheWhen to use
https://engagenudge.com/sdk/v1/en-sdk.js1 hour, revalidated in the backgroundDefault. Picks up every backward-compatible fix.
https://engagenudge.com/sdk/1.0.0/en-sdk.jsImmutablePin 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.

  1. Change src="/en-sdk.js" to src="https://engagenudge.com/sdk/v1/en-sdk.js". Nothing else in the snippet changes.
  2. Replace /en-sw.js with the stub from Integrations so worker fixes reach you too. Keeping the full file also works.
  3. Delete the old en-sdk.js from your web root once the new snippet is live.
  4. If you send a CSP, allow https://engagenudge.com in script-src. See CSP.

What the SDK does

  • Reads data-site-key, data-vapid, and data-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.