Stape
Search
Try for free

Phone Number Formatter variable for Google Tag Manager container

Updated
Oct 14, 2024
Published
Sep 23, 2024

Phone Number Formatter variable allows you to format phone numbers into a standardized format, such as E.164, which is commonly used in international telecommunications. It can be particularly useful when you need to ensure that phone numbers collected from various sources (e.g., form submissions, data layers) are consistently formatted before being sent to external systems like CRMs, analytics tools, or other third-party services.

In this blog post we will discuss how Phone Number Formatter variable works and how to set it up for both: server and web Google Tag Manager containers.

The initial development of these templates was done by Lars Friis, and it is now maintained by Stape.

How it works

Phone Number Formatter Variable works by taking two inputs:

  • Phone Number: digits you want to format.
  • Country Code (ISO 3166): country code of the phone number, which helps in formatting the number correctly according to the international standard. E.g. ‘DK’. Note that the variable now only supports European countries. 

The variable processes the inputs and converts the phone number into the desired standardized format. It changes the libphonenumber library (developed by Google) to correctly interpret and format the phone number based on the country code provided.

How to set up Phone Number Formatter variable

1. Download:

Phone Number Formatter variable

2. Import the variable to your Google Tag Manager container by clicking: Templates → New Variable Template → Click three dots in the top right corner → Click import → Add template that you’ve recently downloaded.

Phone Number Formatter variable

3. Configure the variable, by adding Phone Number and Country Code. Click Save.

Phone Number Formatter variable

Conclusion

This setup will help you maintain consistent phone number formatting across your various data flows within the Google Tag Manager container. And if you need help with the setup - don’t hesitate to ask for the audit or a consultation.

Host your GTM server at Staperight now!