If your phone numbers are being tracked in an incorrect international format (missing the "+" sign), we suggest fixing 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.
You can create a scenario to take phone numbers from customer profiles and transform them using the following snippets. 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, please ensure you have tested it on a few customer profiles.
To adjust profiles, you can create, for example, the following scenario logic:
You can apply more filtering if it makes sense for your specific use case. Depending on whether the problem with the international format of the phone number is recurring or one-time, you can run this scenario once or regularly.
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 }}