JS SDK Customization Options
Overview
This guide shows how to customize the MomentScience JavaScript SDK to match your product experience. You can control when offers appear, override styles, and subscribe to offer lifecycle events.
With the JS SDK, you can:
- Track offer lifecycle events using callbacks
- Customize appearance and layout
- Override settings dynamically in code
- Control when offers are fetched or shown
Callback functions
The JavaScript SDK accepts a callback function that is triggered during key lifecycle events. You can use this callback to extend your user experience, such as showing a survey, logging analytics, or redirecting a user, based on how they interact with the Moments unit.
Passing a callback function
To register a callback, pass a function as the second parameter to window.Adpx.init(). This function will be invoked whenever the SDK emits an event.
You can use this to trigger additional behavior, such as showing a survey, logging user behavior, or adjusting the UI, based on offer interactions.
window.Adpx.init(AdpxConfig, (event, payload) => {
console.log('Received event from MomentScience SDK:', event, payload);
if (event === 'closed_ads') {
showMySurvey();
}
if (event === 'ad_taken') {
console.log(`User took offer ${payload.current} of ${payload.total}`);
}
if (event === 'ad_not_taken') {
console.log(`User passed on offer ${payload.current} of ${payload.total}`);
}
});Supported events
The following events are fired by the JavaScript SDK during the offer lifecycle. You can use them to track user interactions and trigger custom behaviors.
Event | Description | Payload fields |
|---|---|---|
ads_found | Offers were found and returned by the SDK. |
|
no_ads_found | No relevant offers were returned. No further events will be triggered. after this event. | None |
ad_taken | User clicked the positive CTA (e.g. Claim Now) and the offer opened in a new browser tab. |
|
ad_not_taken | User clicked the negative CTA (e.g. No Thanks). |
|
closed_ads | Offer unit was closed or completed. Triggered when:
| None |
Overriding Settings and Styles
In addition to dashboard configuration, you can programmatically override appearance and behavior using the settings and stylesfields in your AdpxConfigobject.
This gives you precise control over unit behavior, button logic, text appearance, layout, and positioning, without requiring changes from the dashboard.
window.AdpxConfig = {
accountId: 'YOUR_SDK_ID',
autoShow: true,
settings: {
// Add custom behavior options here
},
styles: {
// Add style overrides here
}
};Overriding Offer Unit Settings
Within the window.AdxConfig, you can add a parameter called settings, which is an object containing all the settings you want to override. The following properties are supported in the settings override:
Setting | Type | Description |
|---|---|---|
ad_position | String | Defines the placement of the Offer Unit on the screen for desktop environments. The default position is center. Available values:
|
darken_bg | Boolean | When true, adds a background overlay behind the Offer Unit for focused attention.
|
darken_bg_non_centered | Boolean | Similar to darken_bg, but applies the background overlay when ad_positionis not center. |
delay | Integer | Number of seconds to wait after fetching offers before displaying the Offer Unit. Useful for giving context or delaying display until key moments. |
privacy_policy | String | Link to your Privacy Policy. If provided, it will be shown in the footer of the Offer Unit. |
screen_margin | Integer | Pixel value for the margin between the Offer Unit and the browser window edges. |
show_disclaimer | Boolean | If true, displays disclaimer text in the Offer Unit footer. You can configure the actual disclaimer text via the dashboard. |
button_order | String | Controls which CTA button is shown first, available options are:
|
enable_vertical_offset | Boolean |
|
mobile_vertical_offset
| Integer | For mobile web, It specifies the pixel margin from the top of the container. Leaving this blank or entering 0 will cause the container to load at the center of the window. |
multi_offer_unit | Boolean | Determines whether the Offer Unit is displayed as a Multi Offer Unit (MOU) or the Standard Offer Unit (SOU). By default, it is set to false.
Learn more about Multi Offer Unit |
show_multi_offer_unit | Boolean | Controls whether the multi offer layout is displayed at runtime.
Use this toggle to conditionally render the multi-tile layout based on user behavior or feature flags. |
show_ads_on_exit | Boolean | When enabled, the Offers Unit is triggered when a user intends to exit or close a page, based on tracked mouse movement.
|
close_ad_on_click_outside
| Boolean | When this option is enabled, the user can close the Offer by clicking anywhere outside the ad.
This feature is only applicable in Desktop Web environments. |
ad_animation | String | By default, the animation is set to null. This attribute allows you to customize the entry animation of the Offers Unit with the following values:
|
show_close | Boolean | It determines whether to show or disable the Close Offer (X) button at the top right corner of the Offers Unit.
|
enable_close_delay | Boolean | When true, the close (X) button will not appear immediately. Requires close_delay. |
close_delay | Integer | It allows you to add a delay before showing the Close Offer (X) button after displaying the Offers Unit.
|
embedded | Object | An object that can contain the following :
Learn more about Embedding the Moments Offer Unit |
enable_effect_shimmer_pos_cta | Boolean | Determines whether to activate a shimmer effect specifically on the positive call-to-action (CTA). When set to true, the shimmer effect will be enabled, providing a visually appealing animation to highlight the positive CTA button. |
enable_offerwall | Boolean | Determine whether to enable the offerwall. If set to false, none of the offerwall-related settings will be operational. |
fixed_progress_bar | Boolean | Determine if a fixed progress bar should be used on the Offers Unit. Turning this on will show a Progress Bar on the Offers Unit with the ability to view the next and previous Offers. |
open_offerwall | Boolean | Determine whether to open the Perkswall in a new tab after clicking on the close button. |
open_overlay_offerwall | Boolean | Determine whether to open Perskwall as an overlay within the Offers Unit. |
offerText | Object | Defines the styling attributes for text elements within the offer unit, contains the following:
|
enable_usp | Boolean | Enables the User Selected Perks (USP) feature for the Offer Unit. When true, the Offers Unit displays checkboxes allowing users to select specific offers. |
usp_all_offers_checked | Boolean | Determines whether all available offers should be pre-selected (checkboxes checked) when the Offer Unit loads. This setting is only applicable when enable_uspis true. |
usp_cta_text | String | Custom text displayed next to the checkbox for each offer. This string appears only if enable_usp is enabled. |
progress_bar_type | String | Defines the visual style of the offer navigation indicator. Accepted values:
|
enable_perkswallet | Boolean | Enables the PerksWallet feature for the selected theme. When set to true, a “Save for later” call-to-action (CTA) is displayed below the main offer button, allowing users to save offers to their PerksWallet for future use. |
perkswallet_show_cta | Boolean | Controls the visibility of the “Save for later” CTA. If true, the CTA will be shown when enable_perkswalletis enabled. |
saved_offer_text | String | Sets the custom text for the “Save for later” CTA button (e.g., “Save for later”, “Add to Wallet”). |
perkswallet_cta | String | Defines the confirmation message shown after a user clicks the PerksWallet CTA (e.g., “Offer saved!”). |
Overriding Offer Unit Styles
You can customize the appearance of the Moments Offer Unit by passing a stylesobject inside your AdpxConfig. This allows you to control fonts, colors, spacing, borders, and more, to match your product's visual design.
styles.popup
Use this section to control the appearance of the main Offer Unit popup container.
Property | Type | Description |
|---|---|---|
background | String | Background color of the popup container (e.g., #ffffff). |
borderRadius | Object | Controls corner radius for the popup. Accepts keys: top_left, top_right, bottom_left, bottom_right. Values are strings representing pixels (e.g., "5"). |
shadow | String | Hex color code for the box shadow applied around the popup (e.g., #000000). |
lightBox | String | Background color for the lightbox effect behind the popup (e.g., #000). |
image_position | String | Position of the image inside the offer layout. Accepts: left or right. |
showImage | Boolean | Whether to display the image associated with each offer. |
styles:{
//Customize the Offers Unit Container
popup: {
background: "#ffffff",
borderRadius: {
bottom_left: "12",
bottom_right: "12",
top_left: "12",
top_right: "12"
},
shadow: "#8f8f8f",
lightBox: "#000",
image_position: "left",
showImage: true
}
}styles.header
Use this section to customize the header portion of the Offers Unit.
Property | Type | Description |
|---|---|---|
text | String | Main header message displayed at the top of the Offers Unit (e.g., "Your order is complete"). |
background | String | Background color of the header section (e.g., #1A56DB). |
textColor | String | Color of the header text (e.g., #fff). |
fontSize | Integer | Size of the header text (e.g., 16). |
headLineAndLeadInFontSize | Integer | Font size used for both headline and lead-in text (e.g., 14). |
lead_in_text | String | Additional introductory text shown under the main header (e.g., "Here are some offers from brands you love!"). |
lead_in_text_color | String | Color of the lead-in text (e.g., #000000). |
heading_font_size | String | Font size of the header text using a CSS value (e.g., "14px"). |
lead_in_alignment | String | Horizontal alignment of the lead-in text. Accepts: "start", "center", or "end". |
styles:{
// Customize the Offers Header
header: {
background: "#0b1937",
fontSize: 16,
lead_in_text: "Here's something we think you'd love!",
lead_in_text_color: "#477ba5",
headLineAndLeadInFontSize: 15,
text: "Your order is complete",
textColor: "#fff"
},
}styles.offerText
This section customizes the text, fonts, and CTA buttons within each offer tile.
Property | Type | Description |
|---|---|---|
cta_text_size | String | Font size of the call-to-action (CTA) text (e.g., "13px"). |
cta_text_style | String | CSS style applied to the CTA text. Accepts values like "normal", "italic", etc. |
hide_adv_name | Boolean | When set to true, the advertiser’s name will not be shown inside the offer tile. |
textColor | String | Hex color code for general text content (e.g., "#000"). |
font | String | Font family for all offer text (must be a valid Google Fonts name, e.g., "Roboto"). |
fontSize | Integer | Font size used for the offer description text (e.g., 13). |
buttonYes | Object | Styling for the positive CTA button (e.g., "Claim Offer").Includes:
|
buttonNo | Object | Styling for the negative CTA button (e.g., "No Thanks").Includes:
|
offerwall_mou_button_radius | Integer | Border radius (in pixels) for buttons shown in the Offerwall or Multi Offer Unit. |
show_image | Boolean | If true, the image for each offer tile will be shown; if false, it will be hidden. |
styles:{
// Customize the Offers Unit content
offerText: {
buttonNo: {
background: "#fff",
color: "#6B7280",
hover: "#E5E7EB",
stroke: "#9CA3AF"
},
buttonYes: {
background: "#000000",
color: "#fff",
hover: "#0b1937",
stroke: "#0b1937"
},
font: "Roboto",
fontSize: 14,
textColor: "#000",
offerwall_mou_button_radius: 5,
show_image: true
},
}styles.footer
This section controls the footer area of the Offers Unit, including legal links and publisher branding.
Property | Type | Description |
|---|---|---|
disclaimer | String | Text displayed at the bottom of the unit to clarify terms (e.g., "External link. Clicking an offer will take you to the advertiser's website..."). |
text | String | Footer message text, usually a credit or branding note (e.g., "Powered by MomentScience"). |
publisher_privacy_policy | String or null | Custom URL to the publisher's privacy policy. Overrides the default MomentScience privacy link if set. |
publisher_name | String | Name of the publisher to display in the footer. |
styles:{
// Customize the Offers Footer content
footer: {
disclaimer: "",
publisher_name: "MomentScience Publisher",
publisher_privacy_policy: null,
text: "Powered by MomentScience"
}
}styles.offerwall
Customize the appearance of the Offerwall including tile layout and button styling for the Multi Offer Unit (MOU).
All color values must be provided as valid hex codes (e.g., #ffffff for white or #000000 for black).
Parent Key | Property | Type | Description |
|---|---|---|---|
offerwall.button | offerwall_mou_button_background | String | Background color of the Perkswall button |
| offerwall_mou_button_color | String | Text color used inside the Perkswall button |
| offerwall_mou_button_hover | String | Background color shown when hovering over the button. |
| offerwall_mou_button_stroke | String | Border (stroke) color of the Offerwall button. |
offerwall.tile | offerwall_mou_border_color | String | Border color for each Offerwall tile. |
| offerwall_mou_border_thickness | Integer | Thickness of the tile border in pixels. |
| offerwall_mou_tile_background_hover_color | String | Background color of the tile on hover. |
| mou_tile_background_color | String | Default background color of each tile. |
offerwall | tile_radius | Integer | Corner radius of each tile in pixels. |
| mou_tile_gap | Integer | Space (in pixels) between multi offer unit tiles |
styles:{
offerwall: {
button: {
offerwall_mou_button_background: "#FFF",
offerwall_mou_button_color: "#6B7280",
offerwall_mou_button_hover: "#E5E7EB",
offerwall_mou_button_stroke: "#9CA3AF"
},
tile: {
offerwall_mou_border_color: null,
offerwall_mou_border_thickness: null,
offerwall_mou_tile_background_hover_color: null
},
tile_radius: 4
}
}📢 If you're running into any issues while going through the integration process, feel free to contact us at help@momentscience.com