Solutions
MomentPerks
JavaScript SDK Guide
15 min
overview momentperks makes it easy to integrate personalized offers into your website, online store, mobile app, or other digital experiences using our javascript sdk, you can quickly start showing offers to users at the right time, such as after a purchase or during checkout this guide will walk you through how to get your sdk snippet from the momentscience dashboard add the sdk to your website configure runtime options pass user specific data to personalize offers validate that your integration is working correctly requirements before you begin, ensure you have sdk id this is your unique identifier for momentscience, you can find it in the momentscience dashboard under profile settings for detailed instructions on how to retrive your sdk id, see getting your sdk id docid\ cjrqr7fqdkybwzudxxza9 integration steps to help you get started, the following interactive demo walks through the process of getting the javascript sdk code snippt from the dashboard the "sdk id" is also referred to as the "account id" in the javascript snippet shown in the dashboard these terms are interchangeable, they refer to the same value step 1 access your integration code to retrieve your javascript sdk integration code go to the momentscience dashboard from the left sidebar, click integrations and select moments you'll be redirected to the momentperks integration page click the install theme tab, or go directly to this link your javascript sdk code will appear you can copy it directly or download it for later use step 2 add the sdk to your website paste the integration code before the closing \</head> tag of your site ensure your accountid value in your script matches your getting your sdk id docid\ cjrqr7fqdkybwzudxxza9 from the momentscience dashboard example javascript snippet \<script type="module"> (function (window) { window\ adpxconfig = { accountid 'your sdk id', // replace with your account's sdk id autoshow true }; window\ adpxuser = { // optional define user specific values }; })(window\ self !== window\ top ? window\ top window); (async function (window) { const target = window\ document head || window\ document body; const script = document createelement('script'); script type = 'text/javascript'; script src = 'https //cdn pubtailer com/launcher min js'; script crossorigin = 'anonymous'; script async = true; script id = 'adpx launcher'; target appendchild(script); await new promise((resolve) => { window\ adpx ? resolve() script addeventlistener('load', resolve); }); window\ adpx init(window\ adpxconfig); })(window\ self !== window\ top ? window\ top window); \</script> step 3 configure sdk initialization the sdk uses window\ adpxconfig to configure offer behavior at runtime you must set this configuration before the sdk script is loaded on the page the table below explains all supported attributes for adpx init() parameter type required description default accountid string yes your unique momentscience account identifier also referred to as the sdk id the sdk uses this value to associate offer delivery, analytics, and creative rendering with your account getting your sdk id β autoload boolean no controls whether the sdk automatically fetches offers when initialized true the sdk loads offers automatically once initialized false \ you must manually trigger offer loading by calling window\ adpx refresh() this is useful if you want to delay offer fetching until after a specific user action or event for more information refer to customize offer unit timing true autoshow boolean no controls whether offers are automatically displayed after being fetched true \ offers will appear automatically once fetched false you must explicitly call window\ adpx show() to display offers note if autoload is set to false , autoshow has no effect and will be ignored for more information refer to customize offer unit timing true prefetch boolean no enables offer prefetching for faster performance and smoother experiences when set to true fetches and stores offers in localstorage during the first page load reuses the same offers and session id on subsequent page loads within 1 hour maintains the selected state across page reloads when user selected perks docid\ mck87it11jxvj9kyc 543 (usp) is enabled avoids an extra network request on second load by using cached data cache expiration rules valid for 2 page views or 1 hour, whichever comes first after expiration or the third load, the sdk fetches new offers and generates a new session id false dev boolean no enables developer testing mode when set to true the sdk fetches offers in a developer safe environment no engagement or impression data is recorded geo targeting is disabled returns all possible offers, ignoring targeting rules recommended when validating payloads, testing integration, or debugging issues false settings object no allows you to override momentscience dashboard settings at runtime common use cases force a specific placement (e g , " post transaction ") apply a custom theme per page adjust unit behavior for certain views for more information refer to customization options {} styles object no enables custom styling of the moments unit at runtime supported customization areas include unit layout and spacing header appearance (background, text) content font styles and sizes primary cta (positive button) styling secondary cta (negative button) styling body font and colors footer content and style for more information refer to customization options {} example configuration window\ adpxconfig = { accountid 'your sdk id', autoload true, autoshow true, dev true, settings {}, styles {} }; step 4 pass in user data ( recommended ) you can optionally provide user specific payload values using the window\ adpxuser object this allows momentscience to personalize offer content, improve targeting, and enhance reporting user data must be defined before the sdk initialization ( window\ adpx init() ), and can be set from either the client side or injected server side at page render for detailed information about passing payload values using the js sdk, refer to passing payload values docid\ yz38zu4 miummwtnnsg98 why pass user data? use case benefit personalization show offers relevant to each user better targeting deliver offers based on specific user attributes like geography, membership status, or custom segments improved reporting track engagement by user or segment loyalty support enable reward based experiences for users who engage with partner offers using provided ids example payload data you can include any custom key value pairs, but the following are commonly used key example description placement 'post transaction' context in which the offer appears (e g , 'checkout' , 'thank you' ) pub user id 'user abc 123' unique identifier for the user from your system firstname 'john' userβs first name used in personalized messages zipcode '74839' helps geo target specific offers country 'us' country code (iso 3166 1 alpha 2) adpx fp 'df983hgjdl9023klasjd' adpx fingerprint or tracking token custom fields 'plan' 'gold' add any extra targeting or analytics attributes as needed example payload data window\ adpxuser = { placement 'post transaction', pub user id `uniquepubuserid`, firstname 'john', zipcode '74839', country 'us', adpx fp 'df983hgjdl9023klasjd', loyalty program id '23445665393', }; step 5 verify your integration once you've added the sdk open a page where the sdk is installed complete an action where an offer should display (e g , after checkout) open your browserβs developer tools β console and confirm window\ adpx exists window\ adpxuser shows the correct payload values if offers do not appear, make sure your accountid is correct and check for errors in the console next steps now that youβve set up the javascript sdk, the next step is to choose how offers are displayed to your users momentscience provides multiple presentation options, including modal popups, multi offer layouts, and embedded units so you can match the experience to your websiteβs design for implementation details and customization guidance, see the docid 9ukjgfqbk0fvd1qahw51l documentation if you have any issues or questions, contact us at help\@momentscience com