If your phone numbers are being tracked in an incorrect international format (for example, missing the "+" sign), we suggest updating your database using the snippets below. They will help you transform the tracked value from the incorrect format to the correct format with the "+" prefix.
Scenario with a transformation snippet
You can create a scenario to take phone numbers from customer profiles and transform them using the snippets shown below. These snippets will ensure that the numbers tracked are also in string format, which can be used correctly in campaigns.
You'll be able to adjust the snippet based on the country prefix you need to fix. Each country should have its own prefix snippet, as the prefix and format of the number may vary. Before applying snippets to the customer database, ensure you have tested them on a few customer profiles.
To adjust profiles, you can create, for example, the following scenario logic:
- Use Now trigger
- Filter profiles that do ot containt +
- Filter customers based on their country
- Set phone attribute using a snippet with the correct country prefix
You can apply more filtering if it makes sense for your specific use case. Depending on whether the problem with the international phone number format is recurring or one-time, you can run this scenario once or regularly.
Examples
Here are three examples of transformation snippets for three different countries:
UK numbers with prefix +44
{%- set phone = customer.phone | string -%}
{%- set phone = phone.replace(' ','') -%}
{%- set phone = phone.replace('(','') -%}
{%- set phone = phone.replace(')','') -%}
{%- set phone = phone.replace('-','') -%}
{%- set phone = phone.replace('.','')-%}
{%- if phone | length == 10 -%}
{%- set phone = "+44" ~ phone -%}
{%- elif phone | length == 12 -%}
{%- set phone = "+" ~ phone -%}
{%- elif phone.startswith("044") -%}
{%- set phone = phone | replace("044", "+44", 1) -%}
{%- endif -%}
{{ phone }}US numbers with prefix +1
{%- set phone = customer.phone | string -%}
{%- set phone = phone.replace(' ','') -%}
{%- set phone = phone.replace('(','') -%}
{%- set phone = phone.replace(')','') -%}
{%- set phone = phone.replace('-','') -%}
{%- set phone = phone.replace('.','')-%}
{%- if phone | length == 10 -%}
{%- set phone = "+1" ~ phone -%}
{%- elif phone | length == 11 -%}
{%- set phone = "+" ~ phone -%}
{%- elif phone.startswith("001") -%}
{%- set phone = phone | replace("001", "+1", 1) -%}
{%- endif -%}
{{ phone }}SK numbers with prefix +421
{%- set phone = customer.phone | string -%}
{%- set phone = phone.replace(' ','') -%}
{%- set phone = phone.replace('(','') -%}
{%- set phone = phone.replace(')','') -%}
{%- set phone = phone.replace('-','') -%}
{%- set phone = phone.replace('.','')-%}
{%- if phone | length == 9 -%}
{%- set phone = "+421" ~ phone -%}
{%- elif phone | length == 12 -%}
{%- set phone = "+" ~ phone -%}
{%- elif phone.startswith("00421") -%}
{%- set phone = phone | replace("00421", "+421", 1) -%}
{%- endif -%}
{{ phone }}Note
If you intend to use the Pen editor, you should output the phone property as a valid JSON.
{
"phone": {{ phone | json }}
}