Sub topic 2
Where personalisation data comes from
Every personalised email is a template filled with data. If the data is wrong, missing, or collected without permission, no amount of clever template syntax will rescue the message. This chapter covers where that data lives, how it reaches your email platform, and what to check before you reference a field in a template.
This chapter assumes you can send a campaign in an email platform and know what contacts, lists and fields are. It builds on the previous chapter's distinction between merge tags (which insert a value) and dynamic content (which changes what the email contains). Both depend on the sources described here.
The contact record
Most personalisation reads from the contact record. This is the row your platform stores for each subscriber. It holds fields, which are named pieces of data such as email, first_name, country or plan.
Fields come in a few kinds:
| Kind | Example | Typical use in a template |
|---|---|---|
| Text | `first_name`, `company` | Merge tag in a greeting or body line |
| Choice (a fixed set of values) | `plan`: free, pro | Condition in an if/else block |
| Number | `loyalty_points` | Merge tag or comparison |
| Date | `renewal_date` | Merge tag, usually needing a format filter |
| Boolean (true or false) | `is_trial` | Condition |
The field's type matters later. A date stored as text cannot be formatted or compared as a date. A number stored as text may sort incorrectly ("100" before "20"). Choose the right type when you create the field, because changing it later often means re-importing the data.
Core fields and custom fields
Platforms usually split fields into two groups. Core (or standard) fields, such as email address and first name, exist in every account. Custom fields are ones you define, such as plan or favourite_category. Names differ by platform. The same first-name field may be FNAME, first_name or FirstName. Check your platform's field list before writing a tag, because a misspelled field name is one of the most common causes of blank output.
Four ways data gets into the platform
Data reaches the contact record through four main routes. Knowing which one fills a field tells you how fresh it is and how likely it is to be wrong.
- Sign-up forms. The subscriber types the data in. It is consented and current at the time of entry, but people leave fields blank, mistype, or use odd capitalisation.
- File imports. You upload a CSV (comma-separated values) file. This is common when migrating from another tool. Quality depends entirely on the source file, and column mapping errors can put data in the wrong field.
- Integrations and APIs. A shop, CRM (customer relationship management system) or app sends data automatically, either on a schedule or whenever something changes. This is the freshest route, but a broken connection can fail silently and leave stale values.
- Tracked behaviour. The platform or a connected site records actions, such as a page viewed, a product added to a basket, or an email clicked. This is covered in a later chapter on behavioural data.
Contact data versus event and order data
Not everything fits in a single field. A contact has one first_name, but may have many orders, and each order has many items. Platforms handle this in two ways.
- Contact-level data is one value per contact. You reference it directly:
{{ customer.first_name }}. - Related or event data is a collection attached to a contact, such as orders, cart contents or events. You reach it through an object such as
orderand usually repeat it with a loop.
The templates in this tutorial use the same pattern for both. This is how the first example looked in the plan:
Hi {{ customer.first_name | default: "there" }},
Thanks for being with us.Here customer is an object (a named bundle of fields), first_name is one of its fields, and default: "there" is a filter that supplies a replacement when the value is empty. Syntax differs between platforms, so the object and field names in your account will not match these exactly. Some use *|FNAME|*, {{first_name}} or %%FirstName%% for the same job. The idea is the same: a placeholder is replaced by a value read from the data.
The loop example reads from an order object instead of the customer:
{% for item in order.items %}
{{ item.name }} x {{ item.quantity }}
{% endfor %}The data for order does not come from a sign-up form. It comes from an integration with a shop, which sends the order as part of the send. Both examples are covered in detail in later chapters. For now, note that what you can write in a template is limited by what data the platform holds or receives.
When the data is read
Data is read at one of two moments, and the difference causes real mistakes.
- At send time. The platform looks up each recipient's values when the email is sent. This is the normal case for a bulk campaign. If a subscriber changes their name an hour before the send, the new name is used.
- At trigger time. For automated emails, such as an order confirmation, the data is usually captured when the event happens and passed along with it. The email may then show the data as it was at that moment, even if the contact record changes later.
Check which applies to your message. An abandoned-cart email, for example, should use the cart as it was when the shopper left, not whatever the contact record says days later.
Checking a field before you use it
Before you put a field in a template, run through these checks. They take a few minutes and prevent most embarrassing sends.
- Does the field exist, and is the name exactly right? Copy it from the platform's field list instead of typing from memory.
- How many contacts have a value? Filter the list for contacts where the field is empty. If 40% are blank, a merge tag without a fallback will produce a gap for 40% of your audience.
- What do the values look like? Export a sample of 50 rows. Look for all-caps names, trailing spaces, initials, test entries such as "asdf", and email addresses typed into the name field.
- Which source fills it? If an integration fills it, confirm the last successful sync. If a form fills it, confirm the form field is required or optional.
- Is it appropriate to use? The next section covers this.
The Python snippet below shows why steps 2 and 3 matter. It renders one template with Jinja2, a template engine whose syntax is close to Liquid. The first call has an empty first name, and the default filter with true as its second argument replaces empty strings as well as missing values. The second call omits plan entirely, and StrictUndefined makes that an error instead of a blank.
from jinja2 import Environment, StrictUndefined
env = Environment(undefined=StrictUndefined)
template = env.from_string("Hi {{ first_name | default('there', true) }}, your plan is {{ plan }}.")
print(template.render(first_name="", plan="Pro"))
try:
template.render(first_name="Sam")
except Exception as error:
print(type(error).__name__)The output is Hi there, your plan is Pro. followed by UndefinedError. Your email platform will usually not raise an error for a missing field. It will quietly send a blank. That is why you check the data before you send, and why the testing chapter has you preview with incomplete records.
Data you should not use
Having a field does not mean you should personalise with it. Two limits apply.
Consent. People agreed to receive email for certain purposes. Data collected for one purpose, such as shipping an order, may not be fair to use for another, such as tailoring promotions. Rules such as the GDPR (the European Union's data protection law) and similar laws elsewhere require a lawful basis and often clear notice. Check your privacy notice and your platform's consent fields. Where the rules are unclear, ask whoever handles privacy for your organisation. The dedicated chapter on consent covers this more fully.
Data minimisation. Use the least data that achieves the goal. A greeting needs a first name, not a birth date. Every extra field you collect is one more thing to secure, keep accurate, and explain.
There is also a tone limit. A message that reveals what the sender knows, such as "We noticed you searched for..." about a sensitive topic, can feel intrusive even when it is lawful. Reserve the more specific personalisation for data the subscriber gave you knowing it would be used this way.
Common errors
- Wrong field name. The tag renders blank or, on some platforms, as literal text such as
{{ customer.firstname }}. Check spelling and case. - Using a field that only some sources fill. A
planfield filled only by an integration will be empty for contacts imported from a CSV. - Treating "no value" as one case. A field can be missing, empty, or contain placeholder text such as "N/A". A fallback only catches the first two unless you clean the data.
- Assuming data is fresh. A nightly sync means today's purchase may not appear in today's email.
- Mapping columns wrongly on import. Last names end up in the first-name field. Review the mapping preview before confirming.
Exercise
Your template uses {{ customer.plan }} in a condition. A colleague says the field is filled only by a nightly sync from your billing system, and you import some contacts from CSV files without that column. Name two checks you should run before sending, and one problem each check would reveal.
Show answer
First, filter the list for contacts where plan is empty. This shows how many contacts (for example, those imported from CSV) would fall into the else branch or show a blank. Second, check the time of the last successful sync, or compare a few contacts' plan values against billing. This reveals stale data, such as someone who upgraded today but still shows as free. You should also make sure the template has an else branch for contacts with no plan.
Exercise
A subscriber filled in a sign-up form with the first name "SAM" and another entered "n/a". Which data source produced these values, and does a default filter fix both?
Show answer
Both came from a sign-up form, where people type their own data. A default filter fixes neither. "SAM" is a value, so it is shown as typed in capitals. "n/a" is also a value, so the fallback never applies. Both need data cleaning, which is covered in the data quality chapter.