Add User's Current GeoIP to Email Template
Last Updated:
Overview
Applies To
- GeoIP
- Custom Email Template
- User Metadata
- Current Location
- Post Login Action
Cause
Solution
exports.onExecutePostLogin = async (event, api) => {
let city = event.request.geoip.cityName;
let country = event.request.geoip.countryName;
api.user.setUserMetadata("city", city);
api.user.setUserMetadata("country", country);
};
In this Action script, I am creating "city" and "country" user_metadata. Because this is triggered at every login, the user's current location will override the previous location.
Now that the metadata is set to the user object, we can edit the custom email template to pull this data. Navigate to the custom HTML and reference the user's location via the following variable:
{{user.user_metatdata.city}}
{{user.user_metatdata.country}}