Web SDK
Install
npm install @slnka/web@1.0.0-beta.18
Pin the version: the package is a beta and minor beta releases may change advanced options.
Configure the browser client
The package is @slnka/web. Use the default singleton export, not an invented SLNK constructor. Create a COLLECT key for the intended project and environment.
import slnka from '@slnka/web';
slnka.configure('lsk_test_REPLACE_WITH_COLLECT_KEY', {
serverUrl: 'https://api.slnk.ma',
projectId: 'REPLACE_WITH_PROJECT_ID',
requireConsent: true,
queueBeforeConsent: false,
});
// Call only after your consent interface records agreement.
slnka.optIn();
slnka.page();
slnka.track('cta_clicked', { buttonId: 'demo-request' });
slnka.identify('user_demo_42', { plan: 'pro' });
Do not embed SERVER keys, session JWTs or raw personal information in public examples. The key's server-side project scope is authoritative. A projectId in SDK configuration cannot grant cross-project access.
Consent and lifecycle
Configure the client once for the intended context. optIn() grants analytics consent; do not call it automatically as part of page rendering. optOut() revokes consent. Use reset() when changing identity according to your application's sign-out flow. Review what data your events and traits contain before enabling collection.
With queueBeforeConsent: false, this example does not retain events from before agreement. Do not add a second manual queue that replays those events after opt-in.
Click id for server-side conversions
From @slnka/web 1.0.0-beta.21, the SDK reads the slnk_cid parameter added by the SLNK redirect (the click id), removes it from the address bar together with slnk_id, and sends it with the automatic touchpoint and with recordConversion(). getClickId() returns it, or null:
// Pass the click id to your back office with the sign-up form.
const field = document.querySelector<HTMLInputElement>('input[name="slnk_cid"]');
if (field) field.value = slnka.getClickId() ?? '';
Your back office then declares the lead or the sale with a SERVER key; see Conversions API. The click id is kept 90 days in localStorage only after analytics consent, and deleted when consent is revoked. Without consent it is available for the current page only.
Transport and release compatibility
The current source uses SDK collection endpoints and supplies stable anonymous identity and fresh event IDs. A retry must retain the original eventId. flush() requests a flush of buffered events; it does not certify that every analytics projection is updated.
This guide is checked against @slnka/web 1.0.0-beta.18. Check the installed release's API before using advanced forms, feedback, heatmap or friction collection.
Server operations
Link creation and management belong in a backend integration using a SERVER key. Use Links API; never move a management key into the browser to make an example work.