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