Adapters
An adapter sends the events of a vendor tool on your page, for example a HubSpot form or a Calendly appointment. The SDK loads an adapter only when its vendor is on the page.
Built-in adapters
| Adapter | Example events | Can identify a person |
|---|---|---|
HubSpot forms in a frame | hubspot.form_submitted | No. The adapter reads the formId of the vendor only. |
Typeform | typeform.form_submitted | No |
Calendly | calendly.event_scheduled | No |
Cal.com | calcom.booking_created | No |
Pipedrive forms and chat | pipedrive.form_submitted | No |
Intercom | intercom.conversation_started | No |
Cookiebot, CookieYes, OneTrust | No events | No. These consent adapters read the consent of the visitor. Refer to Set consent. |
A form that the page shows needs no adapter. The core sends form.submitted for it, with _detected and the profile properties. The package therefore has no adapter for the forms of Webflow or WordPress. An adapter sends its event only for a form in a frame of a different domain.
An adapter event has the name {vendor}.{action}. An adapter identifies a person only from values that the vendor gives. It never guesses.
To stop all adapters, set data-adapters="off". To stop only some adapters, set a list with a minus sign before each name, for example data-adapters="-typeform,-intercom".
Settings
An adapter reads its settings from script attributes that start with its name:
<script async src="…/lg.js" data-key="lg-pub-live-…"
data-hubspot-portal="1234567"></script>The adapter gets these settings in ctx.config, without the prefix. For example, data-hubspot-portal gives ctx.config.portal.
Add a built-in adapter with the npm package
The script tag loads the file of a built-in adapter with no code. With the npm package, import the adapter and add it with lg.use:
import { cookiebot } from '@quickpipeaiab/lead-scoring/adapters/cookiebot';
lg.use(cookiebot);The client checks the detector of the adapter at the call, again at DOMContentLoaded, and again at the load event of the window. The first check that returns true starts the adapter one time. After the load event, the client makes no more checks:
lg.use(adapter) -> check now
-> DOMContentLoaded -> check
-> load -> check, then no more checksSo the order of the scripts on the page does not matter. A vendor that loads after the client still starts its adapter, and a vendor that is not on the page starts nothing.
Write an adapter
import type { Adapter, Context } from '@quickpipeaiab/lead-scoring/adapters';
export const chatWidget: Adapter = {
name: 'chatwidget',
detect: (win) => 'ChatWidget' in win,
start(ctx: Context) {
const onLead = (lead: { email: string }) => {
ctx.identify({ email: lead.email });
ctx.track('chatwidget.lead_captured');
};
window.ChatWidget.on('lead', onLead);
return () => window.ChatWidget.off('lead', onLead);
},
};Add the adapter to the client:
lg.use(chatWidget);With the script tag, call lg('use', chatWidget).
Adapter
| Member | Type | Description |
|---|---|---|
name | string | The name of the adapter. Use lowercase letters, digits and hyphens. |
detect | (win: Window) => boolean | Returns true when the vendor is on the page |
start | (ctx: Context) => () => void | Starts the adapter. Returns a function that stops it. |
Context
| Member | Type | Description |
|---|---|---|
track | (name: string, properties?: object) => void | Sends an event |
identify | (identifiers: PersonIdentifiers) => void | Adds identifiers of a person |
account | (identifiers: AccountIdentifiers) => void | Connects the visitor to a company |
set | (attributes: object) => void | Sets attributes of the person |
consent | (states: Partial<Record<Purpose, ConsentState>>) => void | Sets the consent state of one or more purposes. Only a consent adapter calls it. Refer to Write a consent adapter. |
config | Record<string, unknown> | The settings from the data-<name>-* script attributes |
log | (...values: unknown[]) => void | Writes in the console in debug mode |
Consent types
| Type | Values |
|---|---|
Purpose | 'analytics' or 'ads' |
ConsentState | 'unknown', 'granted' or 'denied' |
The events of an adapter get the same checks as all other events: consent, beforeSend and the batches.
Integrity
The core of the SDK contains the sha384 hash of each built-in adapter file. It loads each file with this hash and does not run a file with a different hash. Refer to Privacy and security.