Installation
The npm package name is @usesophi/sophi-web-object. Published artifacts live under dist/ in the package.
| File | Use case |
|---|---|
sophi.min.js |
Production: <script src="..."> or GTM Custom HTML |
sophi.js |
Debugging (source maps, readable bundle) |
sophi.esm.js |
Bundlers / import |
The package is publicly available on the jsDelivr CDN:
| URL | Resolves to |
|---|---|
https://cdn.jsdelivr.net/npm/@usesophi/sophi-web-object@latest/dist/sophi.min.js |
Latest published version |
https://cdn.jsdelivr.net/npm/@usesophi/sophi-web-object@0.1.0/dist/sophi.min.js |
Pinned version (example) |
Version pinning
@latest always tracks the newest release, which is convenient during development. For production, pin to a specific version (e.g. @0.1.0) so your integration is not affected by future breaking changes.
Script tag
Load the script after inline code that defines window.sophi_object with at least config.apiKey, or ensure config exists before the tracker runs.
<script>
window.sophi_object = {
config: {
apiKey: 'YOUR_API_KEY'
},
page: {
type: 'Home',
url: 'https://example.com/'
}
};
</script>
<script src="https://cdn.jsdelivr.net/npm/@usesophi/sophi-web-object@latest/dist/sophi.min.js" async></script>
async is supported: the SDK waits for DOMContentLoaded (or runs immediately if the document is already loaded) before bootstrapping.
npm / ESM
import '@usesophi/sophi-web-object/dist/sophi.esm.js';
// window.SophiTracker and window.sophi_object are available after bootstrap
Ensure window.sophi_object.config is set before the module executes, or set it in your app entry before importing.
Google Tag Manager
GTM supports two loading strategies — choose one per tag.
Option A — load from jsDelivr (recommended)
- Create a Custom HTML tag.
-
Add a
<script src="...">pointing at the jsDelivr URL: -
Trigger on Consent Granted (or your policy equivalent), then All Pages if appropriate.
Note
For production GTM deployments, replace @latest with a pinned version such as @0.1.0 so a new release cannot silently change tracking behaviour after you publish the container.
Option B — inline the bundle
- Create a Custom HTML tag.
- Paste the full contents of
sophi.min.jsdirectly into the tag body, then prepend thewindow.sophi_objectconfig block. - Trigger identically to Option A.
Inlining avoids an extra network round-trip and ensures the tracker fires even if the CDN is temporarily unreachable, at the cost of a larger GTM container payload.
Define window.sophi_object in a tag that fires before the tracker tag (e.g. a prior Custom HTML or a data layer variable mapped in a tag template). For consent-sensitive fields, see Configuration and Types reference (UserObject / PII gating).
Next steps
-
Configuration —
apiKey,userId, retries, debounce, debug -
The
window.sophi_objectlayer — what to set on the data layer - SophiTracker API — SPA updates