Advanced Settings
Implementing Macros
21 min
overview macros transform static offer messages into dynamic, personalized content by replacing placeholder variables with real customer and transaction data this creates experiences that feel tailored to each user, increasing trust and conversion rates what you can achieve with macros personalize greetings address customers by name when available confirm transactions display order numbers and purchase amounts adapt messaging show different content based on data availability maintain professionalism deliver grammatically correct messages regardless of missing data how macros work macros are dynamic placeholders written as {{key}} that pull values from your data payload or url parameters when an offer displays, momentscience replaces each macro with its corresponding value, or handles it gracefully if the data is missing three ways to use macros simple replacement {{firstname}} becomes "alex" when firstname data exists fallback values {{firstname|'valued customer'}} displays a default when firstname is missing conditional logic {{#if firstname}}hey {{firstname}}, {{/if}} shows content only when data exists this flexibility ensures your messages remain polished and professional in every scenario macro patterns 1\ simple replacement {{key}} the most basic pattern replaces a placeholder with its value if the value is missing, nothing is displayed syntax {{key}} example your order {{confirmationref}} is ready with data ( confirmationref "ord 123" ) โ your order ord 123 is ready without data โ your order is ready (leaves a blank space) use when the field always has a value in your data flow 2\ fallback values {{key|'default'}} provides a default value when data is missing, preventing blank spaces in your messages syntax {{key|'default value'}} example hello {{firstname|'there'}}! with data ( firstname "alex" ) โ hello alex! without data โ hello there! use when you want to substitute a specific alternative value rather than leaving the field empty 3\ conditional blocks {{#if key}} {{/if}} shows or hides entire sections based on whether data exists this prevents awkward grammar and punctuation issues the problem simple replacement creates broken grammar when data is missing hey {{firstname}}, your order is confirmed without firstname data, this renders as hey , your order is confirmed the solution wrap the entire greeting in a conditional block {{#if firstname}}hey {{firstname}}, {{/if}}your order is confirmed results with data ( firstname "alex" ) โ hey alex, your order is confirmed without data โ your order is confirmed (clean, no awkward comma) when the condition is false, the entire block, including "hey", the space, and the comma, disappears, maintaining grammatically correct messages use when entire phrases should appear or disappear based on data availability 4\ conditional with alternative {{#if key}} {{else}} {{/if}} displays different content depending on whether data exists, giving you full control over both scenarios syntax {{#if key}}content when present{{else}}content when missing{{/if}} example {{#if firstname}}hey {{firstname}}, {{else}}hi there, {{/if}}your order is confirmed results with data โ hey alex, your order is confirmed without data โ hi there, your order is confirmed use when you want to show different messages rather than simply hiding content when using macros through the shopify integration, only {{first name}} and {{last name}} are supported these macros will render only if the customer is logged in to their shopify account at the time of purchase if the customer checks out as a guest, no macros will be displayed for more information about configuring and personalizing offers with momentperks, refer to the docid\ jcczrozbi5d0pvdqm15kx guide macro syntax quick reference all macro patterns supported in offer unit messages true 165,165,165,165 left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type combining patterns you can combine conditionals with simple replacements and fallbacks {{#if firstname}}hey {{firstname}}, {{/if}}your order {{orderid|'n/a'}} is confirmed when firstname = "jon" and orderid = "#5678" hey jon, your order #5678 is confirmed when firstname is null and orderid is null your order n/a is confirmed recommended macros true 220,285,155 left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type use these macros in your theme's text fields to dynamically insert relevant customer or transaction data, improving both user trust and conversion rates best practices when to use each pattern simple replacement ( {{key}} ) use when the field is always present in your data example order confirmation numbers in post purchase flows fallback values ( {{key|'default'}} ) use when you want to substitute a specific alternative value example {{firstname|'valued customer'}} provides a polite greeting alternative conditional blocks ( {{#if key}} {{/if}} ) use when entire phrases should appear or disappear based on data availability prevents awkward punctuation and maintains grammar example {{#if firstname}}hey {{firstname}}, {{/if}}your order is ready conditional with alternative ( {{#if key}} {{else}} {{/if}} ) use when you want different messages for different scenarios example {{#if firstname}}welcome back, {{firstname}}{{else}}welcome{{/if}} implementation steps to dynamically render personalized content in your offer units, macro placeholders must be correctly defined and matched with values in your payload if a value is missing, the placeholder will appear blank using javascript sdk step 1 configure macros in your theme navigate to the theme customizer in your momentscience dashboard in the header or lead in text fields, insert your macro placeholders using double curly braces {{ }} for example {{firstname}} to insert the customer's first name {{firstname|'valued customer'}} to insert the first name with a fallback value {{#if firstname}}hey {{firstname}}, {{/if}}your order is confirmed for conditional greeting {{amount}} for transaction amount {{confirmationref}} for the order confirmation number use the preview panel to confirm the layout and styling render correctly with the placeholder macros the macro key used in the theme must exactly match the key provided in your payload with no spaces or special characters example use {{firstname}} , not {{ first name }} step 2 pass customer data in the payload add relevant customer and transaction data to your window\ adpxuser object window\ adpxuser = { email "customer\@example com", firstname "alex", lastname "johnson", confirmationref "ord 12345", amount "$75 50", currency "usd", paymenttype "credit", zipcode "10001", country "us" }; use macros sparingly and purposefully, avoid overcrowding messages with variables step 3 test the implementation test your implementation with various user scenarios to ensure macros render correctly in all cases no double spaces appear in the rendered message punctuation (commas, exclamation points) only appears when the value is present messages remain professional and natural in all scenarios fallback values display correctly when primary values are missing using direct links perkswall supports macros within title text, allowing you to personalize user experiences without initializing through the sdk to pass macro values, include them as query parameters in the perkswall url each macro key corresponds to a parameter name, and when the link opens, perkswall replaces placeholders (for example, {{firstname}} ) with the provided values example https //naojs pubtailer com/perkswall?accountid=fb2220c22202f4\&themeid=maintheme\&firstname=jon\&confirmationref=ord 78910\&amount=45 50 if your title text is thanks, {{firstname}}! your order #{{confirmationref}} totaling ${{amount}} is confirmed it displays as thanks, jon! your order #ord 78910 totaling $45 50 is confirmed example use cases true 220,220,220 left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type if you encounter any issues or need support during integration, contact us at mailto\ help\@momentscience com