Skip to main content

lead-capture

The lead-capture feature enables merchants to capture leads on their storefront by recognizing returning Shop users and facilitating email collection.

It supports two main flows:

  • Discount flow — Offer a discount code in exchange for an email, using the onAuthenticate callback.
  • Default flow — Standard email capture without a discount incentive.

The feature detects whether the current visitor is a known Shop user and can display a call-to-action button (for example, "Continue with Shop") or integrate inline with an existing email input field.


Create a lead-capture instance via the SDK:

const sdk = window.ShopSDK.initialize({
apiKey: 'YOUR_STOREFRONT_API_KEY',
});

const leadCapture = await sdk.create('lead-capture', {
attributes: {
emailInputSelector: '#email',
},
onComplete(event) {
console.log('Lead captured:', event.email);
},
});

document.querySelector('#mount').appendChild(leadCapture.element);

You can also eagerly preload the feature loader before calling create:

const sdk = window.ShopSDK.initialize({
apiKey: 'YOUR_STOREFRONT_API_KEY',
features: { 'lead-capture': true },
});

Config accepted by sdk.create('lead-capture', config).

Derived from LeadCaptureRegistrationSpec: includes all component attributes, all event handlers, plus SDK-specific fields like appearance.

Anchor to appearance
appearance

Component-level appearance overrides. Variables set here take precedence over those set in initialize or update().

Anchor to attributes
attributes
{ apiKey?: string; clientId?: string; devMode?: boolean; emailInputSelector?: string; buttonType?: ; buttonLayout?: ; storefrontOrigin?: string; uxMode?: "redirect" | "iframe" | "windoid"; scope?: string; disclosureScope?: string; disclosureText?: string; disclosureTitle?: string; phoneCapture?: boolean; phoneCaptureDisclosureText?: string; }

Component attributes. These map to HTML attributes on the underlying <shop-lead-capture> element.

Anchor to onAuthenticate
onAuthenticate
() => Promise<{ discount: ; }>

Fired during the discount flow to retrieve the discount to offer.

Anchor to onBeforeAuthenticate
onBeforeAuthenticate
() => void | Promise<void>

Fired before authentication begins. Can be async.

Anchor to onComplete
onComplete
(event: ) => void

Fired when the lead capture flow completes successfully.

Anchor to onConfirmSuccess
onConfirmSuccess
() => void

Fired after the user confirms a successful action.

Anchor to onError
onError
(event: ) => void

Fired when an error occurs during the flow.

Anchor to onGetEmailInput
onGetEmailInput
() => HTMLInputElement

Fired to retrieve the email input element (alternative to emailInputSelector).

Anchor to onLoad
onLoad
(event: ) => void

Fired when the component loads and user recognition completes.

Anchor to onReady
onReady
(event: ) => void

SDK-level ready handler (fires when the element's loader resolves).

Anchor to onRestart
onRestart
() => void

Fired when the user restarts the flow.

Runtime instance returned by sdk.create('lead-capture').

Exposes:

  • All component methods from the registration spec
  • setAttribute for updating attributes after creation
  • Event subscription methods for each event handler
  • onReady with late-subscriber semantics
  • element for DOM insertion
  • destroy for cleanup
Anchor to destroy
destroy
() => void
required

Tear down listeners and remove the element from the DOM if attached.

Anchor to element
element
HTMLElement
required

The underlying custom element. The consumer is responsible for inserting it into the DOM.

Anchor to notifyEmailFieldShown
notifyEmailFieldShown
() => void
required

Notify the component that the email field has been shown.

Anchor to onAuthenticate
onAuthenticate
(handler: () => Promise<{ discount: ; }>) => void
required

Register an onAuthenticate handler.

Anchor to onBeforeAuthenticate
onBeforeAuthenticate
(handler: () => void | Promise<void>) => void
required

Register an onBeforeAuthenticate handler.

Anchor to onComplete
onComplete
(handler: (event: ) => void) => void
required

Register an onComplete handler.

Anchor to onConfirmSuccess
onConfirmSuccess
(handler: () => void) => void
required

Register an onConfirmSuccess handler.

Anchor to onError
onError
(handler: (event: ) => void) => void
required

Register an onError handler.

Anchor to onLoad
onLoad
(handler: (event: ) => void) => void
required

Register an onLoad handler.

Anchor to onReady
onReady
(handler: (event: ) => void) => void
required

Register an onReady handler. Fires immediately if already ready.

Anchor to onRestart
onRestart
(handler: () => void) => void
required

Register an onRestart handler.

Anchor to setAttribute
setAttribute
(attrs: Partial<{ apiKey?: string; clientId?: string; devMode?: boolean; emailInputSelector?: string; buttonType?: ; buttonLayout?: ; storefrontOrigin?: string; uxMode?: "redirect" | "iframe" | "windoid"; scope?: string; disclosureScope?: string; disclosureText?: string; disclosureTitle?: string; phoneCapture?: boolean; phoneCaptureDisclosureText?: string; }>) => void
required

Update one or more attributes on the underlying element. Accepts the same attribute keys as config.attributes.

Anchor to start
start
(email?: string) => void
required

Trigger the lead-capture flow, optionally with a pre-filled email.

Anchor to leadcapturecompleteeventLeadCaptureCompleteEvent

Event payload dispatched when the lead capture flow completes successfully.

Anchor to email
email
string
required

The email address captured from the user.

Anchor to signedIn
signedIn
boolean
required

Whether the user signed in during the flow (as opposed to only providing their email).

Anchor to consentedScopes
consentedScopes
string

A space-separated list of OAuth scopes the user consented to.

Anchor to customerAccessToken
customerAccessToken
string

A customer access token issued after authentication, if available.

Anchor to customerAccessTokenExpiresAt
customerAccessTokenExpiresAt
string

ISO 8601 timestamp of when the customer access token expires.

Anchor to customerUpdateErrors
customerUpdateErrors
string

Error messages from the customer update mutation, if any.

Anchor to disclosureAgreed
disclosureAgreed
boolean

Whether the user agreed to the disclosure presented during the flow.

Anchor to emailVerified
emailVerified
boolean

Whether the user's email has been verified.

Anchor to phoneShareConsent
phoneShareConsent
boolean

Whether the user consented to share their phone number.

Anchor to shopConsentToken
shopConsentToken
string

A token that can be exchanged in the Shop Partners API to receive access for a user in the Shop Users API

Anchor to leadcaptureerroreventLeadCaptureErrorEvent

Event payload dispatched when an error occurs during lead capture.

string
required

A machine-readable error code.

Anchor to message
message
string
required

A human-readable error message.

Anchor to email
email
string

The email address associated with the error, if available.

Anchor to leadcaptureloadeventLeadCaptureLoadEvent

Event payload dispatched when the lead capture component finishes loading.

Anchor to userFound
userFound
boolean
required

Whether a recognized Shop user was detected for the current browser session.



Was this page helpful?