Skip to main content

Web SDK

Render Disco offers on any web page you control. The Web SDK is the serving integration behind two setups:

  • Publishers adding DiscoOffers to their own post-purchase pages, such as order confirmation and order tracking.
  • DiscoBeat channel partners serving offers on the web surfaces of the publishers on their channel. If that's you, start with How your DiscoBeat launch works for the full picture, then come back here for the build.

The steps below are the same for both.

DiscoBeat channel partners: one key per publisher

Offers serve per publisher, so the SDK loads with each publisher's own ad-serving key, created when Disco approves that publisher. Publisher keys follow the same environment split: _sandbox_ keys in staging, _live_ keys in production. Creating publishers and managing their keys is covered by Channel Management and the Channel API.

1. Load the SDK​

Add this script to your <head>.

Recommended: replace disco_pk_live_... with your Disco public key.

<script
src="https://d1zcmvsklxjbur.cloudfront.net/static/disco-sdk.js"
type="text/javascript"
api_key="disco_pk_live_..."
></script>

Legacy: replace PUBLISHER_ID with your ID.

<script
src="https://d1zcmvsklxjbur.cloudfront.net/static/disco-sdk.js"
type="text/javascript"
publisher_id="PUBLISHER_ID"
></script>
Environment

Add environment="staging" to hit the staging environment instead of production. When using api_key with staging, use a _sandbox_ key. _live_ keys are not accepted in staging.

2. Add the mount point​

Place this where you want DiscoOffers to appear. The top of the page is recommended.

<div id="disco-widget"></div>

3. Pass order data​

Call loadWidget() as soon as order data is available. The more context you pass, the more relevant the recommendations Disco can serve your shoppers, which is also what drives your earnings.

window.discoLauncher.loadWidget({
email: "shopper@example.com", // required (or email_hash)
email_hash: "sha256...", // required (or email)
first_name: "Monica", // required
order_id: "67890XYZ", // required
page_type: "thank_you", // "thank_you" | "order_status"
purchases: [ // required
{ product_id: "PROD123", name: "Headphones", type: "Electronics", quantity: "1" }
],
cost: "124.00",
phone: "+1 (415) 123-4567",
shipping: { address_line_1: "123 Main St", city: "San Francisco", state: "CA", zip: "94105" }
});
info

page_type only accepts "thank_you" or "order_status".

GTM setup​

Integrate via Google Tag Manager. Direct SDK integration (above) is recommended for best results.

1. Push data to the Data Layer

window.dataLayer.push({ email: "shopper@example.com" });

2. Create a Data Layer Variable: In Google Tag Manager, go to Variables → User-Defined Variables → New, set type to Data Layer Variable, enter the key name (e.g. email) and save.

3. Create a Custom HTML Tag

<script
src="https://d1zcmvsklxjbur.cloudfront.net/static/disco-sdk.js?publisher_id=PUBLISHER_ID"
type="text/javascript"
></script>
info

Enable Support document.write in the tag settings.

4. Set the trigger: Single-page app: use a History Change trigger set to Some History Changes, matched to your confirmation-page URL. Multi-page app: use a Page View trigger set to Some Page Views, matched to your confirmation-page URL.

Field reference​

Complete field definitions for loadWidget().

Customer fields

FieldTypeRequiredDetails
emailStringconditionalPlain-text email. Provide email or email_hash
email_hashStringconditionalSHA-256 hash (lowercased, trimmed). Provide email_hash or email
first_nameString✓Shopper first name
last_nameStringShopper last name
phoneStringPhone number (any format)
order_idString✓Unique order identifier
confirmation_idStringConfirmation identifier
costStringTotal order cost
page_typeEnum✓"thank_you" or "order_status"
purchasesArray✓Purchased items array
shippingObjectShipping address
billingObjectBilling address
click_idStringClick identifier for attribution

Purchase item fields

FieldTypeDetails
product_idStringUnique product ID
nameStringProduct name
typeStringProduct category
descriptionStringProduct description
variantStringColor, size, etc.
quantityStringQuantity purchased

Address fields (used for both shipping and billing)

FieldTypeDetails
address_line_1StringStreet address
address_line_2StringApt, suite, unit
cityStringCity
stateStringState or province
zipStringZIP / postal code