Write and retrieve company insights
Your backend sends the current application session. Mementom resolves its keyring and returns only this app’s permitted values. Another company, or another app you own, has a separate record—even for the same field name.
1. Configure your application
- Sign in to the Developer Console. Register your app, exact HTTPS callback and allowed site origins.
- Use your existing company server credential, or have the owner create the first credential in company settings. It appears once. Replacing it invalidates the previous credential for all apps using it.
- Publish the app’s Login connection challenge, select it in Integration → SDK setup, and register the server’s public RSA key. A draft or OFF challenge does not issue an authenticated session. Use your intended access policy; insight use does not require nCent’s membership policy or an unrelated action challenge.
- In Insights → Catalog, register a standard field such as
shopping.interest. Custom fields need owner/admin approval in Review.
- In Validation → Datasets, register a non-sample Company activity dataset. Copy its ID and your application ID. Validate synthetic observations before sending live events.
2. Use the consolidated SDK
Use Node.js 22.12 or later. Save the server SDK and example together outside your public web directory. Add the browser controller to your browser assets. No npm package, repository access or Mementom database access is needed.
The server SDK includes authentication, insights and the optional session cookie helper. Review and commit the downloaded modules in your company repository to pin the exact source. Do not import a changing remote URL at runtime. Existing private-package users can use @mementom/sdk, @mementom/sdk/insights and @mementom/sdk/session-cookie.
3. Connect the current visit
The example exports createCompanyInsights. Await its initialization with the three SDK inputs: application ID, company credential and private RSA key. Also supply the dataset ID for your business data and your existing persistent 32-byte cookie encryption key. The same key must be available to every instance of your backend.
- On a direct tap, open a named authorization popup pointing to your backend’s sign-in route. Require a same-origin request. If blocked, offer a retry; do not collect credentials on your page.
- Call
beginSignIn(), set its setCookie response header and send a 303 to its location. The prepared URL preserves Mementom’s issued request and required popup marker.
- At your registered callback, call
finishSignIn(request, {code, state}) with the URL parameters. Append both returned cookies as separate Set-Cookie headers, then redirect to your own clean completion page. Never log the callback query.
- The completion page may close the popup; the original site refreshes its own status. Keep session IDs and company credentials out of browser JavaScript. For QR, cancel/status and advanced destination flows, reuse the established authorization integration.
4. Respect collection and sharing choices
A valid company session permits registered company observations unless the owner has stopped collection. Saving a value does not enable company reads or audience matching. Those have separate owner controls in Mementom.
Honor the current dataset, destination scope and owner settings. Company reads return only permitted values; an empty result is valid. Your company cannot auto-enable sharing or audience matching.
5. Write and read
Call saveActivity(request, event) with meaningful insight values, such as an expressed preference or confirmed purchase, then readActivity(request). Persist the event ID, original observation time and values before sending. Reuse them for bounded retries. A browser-submitted claim is not evidence of a purchase or other business event.
The cookie carries only a temporary encrypted session; you do not need a consumer/keyring database. On a later sign-in, Mementom resolves the fresh session to the same permitted, unexpired records. Never use a saved session as permanent identity.
Use signOut(request, registeredReturnUrl) for logout, with your fixed company return URL and CSRF protection. Apply both cookie-clearing headers and send a 303 to the returned location so Mementom also clears this app’s browser-held file access. If no session cookie exists, location is absent; return to your own signed-out page. The server session is invalidated before this redirect.
Acceptance checklist
Verify write/readback, a later session, no permission, withdrawal, changed domains, expired sessions and duplicate events. Write different values for the same field in two company apps and confirm each retrieves only its own. No bounty or cross-company disclosure is enabled by this integration.