Purchase and event data in emails

Use purchase and event data to show users what they bought or did in your app. For example, a receipt can confirm the product, amount, and date of a payment. An onboarding email can mention the goal that the user selected in your app, such as “Sleep better”.

The data comes from the user’s own purchase or custom event: the one that made them qualify for the purpose of the email. A custom event is an event that your server reports from your app, such as a completed onboarding. To show the data, add placeholders to the email. These placeholders are a separate set from the placeholders of a destination URL.

To send a receipt, create a transactional purpose with purchases as its entry events. To send an onboarding email, create a marketing purpose with the custom event as its entry event.

Where purchase and event data comes from

The product, amount, tax and payment method of a purchase come from its payment details. The source of a purchase decides whether it comes with payment details:

  • Your server: Can add payment details to the purchases it sends to the Adapty Mail API.
  • Other sources, such as the Adapty SDK: Send purchases to Adapty Mail without payment details. Leave the product and the amount of these purchases out of emails: an email that shows either doesn’t go out.

Your server reports custom events to Adapty Mail through the API. Each one can carry data fields in its payload. To show these fields in generated emails, describe them in the purpose that has the event as an entry event.

Email a receipt after each purchase

Receipts need purchases with payment details. As transactional emails, they go out alongside marketing emails and still reach users who unsubscribed.

  1. On the Purposes page, open the Transactional tab.
  2. Create a purpose with Subscription started, Subscription renewed and One-time purchase as its entry events. To send a receipt for each purchase, keep the defaults of the purpose: no Exit rule reason, and On every entry event as the Re-entry rule.
  3. On the Campaigns page, open the Transactional tab.
  4. Create a campaign for the purpose. In the Email Destination dropdown, select a destination where buyers can manage their purchases, such as your account page.
  5. Click Generate emails. Adapty Mail may add a table of purchase details to each email, above the button. Where an email has no such table, add purchase placeholders to its HTML.
  6. To see a receipt with a sample purchase, click Send test email.
  7. To save the campaign, click Create.
  8. Create a flow that sends the campaign to the All Users segment.
  9. To see real values, make a purchase with payment details as a test user, and open the receipt in your inbox.
A receipt email in the campaign editor: its HTML with transaction placeholders, and its preview with a sample purchase

A first purchase also makes the buyer qualify for the App activation and Cancellation page purposes, unless you changed the rules of these purposes. If they have flows, their emails go out along with the receipt.

Placeholders for purchase and event data

To find the placeholders for purchase and event data, expand the Placeholders card on the campaign page. The card lists them in its Purchase and Custom event groups. Add the placeholders to the HTML or the subject of an email while the campaign is a draft. In a test email, the placeholders show a sample purchase, and each custom event field as its name in brackets.

Purchase placeholders

Purchase placeholders show the purchase that made the user qualify for the purpose, in every email of the sequence. To make sure each email has a purchase to show, only select purchases as entry events of the purpose. The purchase events are Subscription started, Subscription renewed and One-time purchase.

When the purchase lacks the value of a required placeholder, Adapty Mail holds the email back.

PlaceholderShowsRequiredNeeds payment details
{{ transaction.product }}The purchased productYesYes
{{ transaction.amount }}The amount charged, tax included, such as 9.99 USDYesYes
{{ transaction.tax }}The tax included in the amountNoYes
{{ transaction.payment_method }}The payment method, such as Visa •••• 4242NoYes
{{ transaction.date }}The purchase dateYesNo
{{ transaction.number }}The transaction numberYesNo
{{ transaction.next_charge_date }}The next charge dateNoNo

Dates appear as YYYY-MM-DD, in the timezone of the recipient.

The Placeholders list of the campaign editor with the Purchase and Custom event groups, and the hint on purchase placeholders

Custom event placeholders

To show a field of a custom event, add {{ custom_event.<field> }} and replace <field> with the name of the field. The Custom event group of the Placeholders card lists the fields you described in the purpose. To make sure each email has an event to show, only select custom events as entry events of the purpose.

An email with the custom_event.goal placeholder in its subject and text, and a preview that shows the field name in brackets

When the event lacks a field that an email includes, Adapty Mail holds the email back. A field marked May be missing in the purpose only shows in a generated email when the event has it. In HTML you write, hide such a field yourself.

Hide a placeholder that has no value

To hide a placeholder that has no value, wrap the placeholder and its label in an {% if %} block. For example, {% if transaction.tax %}Tax: {{ transaction.tax }}{% endif %} only shows the tax line when the purchase has a tax amount. For a custom event field, the block starts with {% if custom_event.<field> %}.

Use a block for each purchase placeholder that isn’t required, so its label only shows with a value. When a required placeholder inside a block has no value, the email goes out without the block.

Emails held back for missing data

When the entry event lacks the value of a required placeholder, Adapty Mail holds back the email that shows it. If the value reaches Adapty Mail within about 11 minutes after that, the email goes out. Otherwise, the sequence stops for the profile.

In the journey of the profile, the email has the Missing data chip while Adapty Mail holds it back. Once the sequence stops, the email appears as Cancelled, with the reason No data for the email.

A journey with two Missing data attempts of a receipt email, then a cancellation with the outcome No data for the email