Skip to content

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 ​

AdapterExample eventsCan identify a person
HubSpot forms in a framehubspot.form_submittedNo. The adapter reads the formId of the vendor only.
Typeformtypeform.form_submittedNo
Calendlycalendly.event_scheduledNo
Cal.comcalcom.booking_createdNo
Pipedrive forms and chatpipedrive.form_submittedNo
Intercomintercom.conversation_startedNo
Cookiebot, CookieYes, OneTrustNo eventsNo. 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:

html
<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:

ts
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:

text
lg.use(adapter) -> check now
                -> DOMContentLoaded -> check
                -> load             -> check, then no more checks

So 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 ​

ts
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:

ts
lg.use(chatWidget);

With the script tag, call lg('use', chatWidget).

Adapter ​

MemberTypeDescription
namestringThe name of the adapter. Use lowercase letters, digits and hyphens.
detect(win: Window) => booleanReturns true when the vendor is on the page
start(ctx: Context) => () => voidStarts the adapter. Returns a function that stops it.

Context ​

MemberTypeDescription
track(name: string, properties?: object) => voidSends an event
identify(identifiers: PersonIdentifiers) => voidAdds identifiers of a person
account(identifiers: AccountIdentifiers) => voidConnects the visitor to a company
set(attributes: object) => voidSets attributes of the person
consent(states: Partial<Record<Purpose, ConsentState>>) => voidSets the consent state of one or more purposes. Only a consent adapter calls it. Refer to Write a consent adapter.
configRecord<string, unknown>The settings from the data-<name>-* script attributes
log(...values: unknown[]) => voidWrites in the console in debug mode
TypeValues
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.