Install the tracking script¶
The tracking script swaps the phone number on your website for a tracking number from each number pool, and links the visitor's session to any call they make. Install it once, on every page of the website.
The script is one tag:
<script async src="https://ctjs.au/ct.js" data-tracking-code="YOUR_TRACKING_CODE"></script>
YOUR_TRACKING_CODE is the tracking site's code, which starts with E-. Copy the complete tag from the Enfonica Console rather than typing it.
Before you begin¶
- The tracking site is active and its Allowed domains include the website's hostname. See Manage site settings.
- The site has a number pool with at least one rule and at least one number. Without them the script loads but has nothing to swap. See Create a number pool and its rules.
- You can edit the website's HTML, or its Google Tag Manager container. For Tag Manager, see Install with Google Tag Manager.
Install the script¶
- In the Console, open the tracking site and click Settings.
- Scroll to Tracking script and click Copy script.
- Paste the tag into the
<head>element of every page of the website. If you use a template or a shared header, paste it once there. - Publish the website.
- Verify the installation.
Once the change is live, visitors see a tracking number instead of the original number.
How the script works¶
- It loads without blocking the page. The
asyncattribute lets the browser keep rendering. The script is about 30 KB compressed. - It identifies the visitor's session. On the first page view the script creates a session ID and stores it in the browser's web storage. The session continues across pages and tabs, and ends after 30 minutes without activity. The script doesn't set cookies.
- It asks Call Tracking for numbers. The script sends the tracking code, the page URL, the referrer and any campaign parameters and click IDs in the URL, and receives a tracking number for each pool rule that applies to the page.
- It swaps the numbers. The script finds the rule's number in the page text and in
tel:links, in any common format, and replaces it with the tracking number in the rule's display format. It keeps checking for a short time so numbers added by other scripts during page load are swapped too. - It keeps the assignment while the visitor is active. While the visitor is on the site, the number stays assigned to them, so the number they see is the one they dial.
- It handles single-page applications. The script re-runs when the URL changes without a page load. See Single-page applications.
Where the number can be¶
The script swaps a number that is written in one text node or in the href of a tel: link. It matches the number in any usual Australian format, including with spaces, brackets and the +61 prefix. It doesn't swap a number that is:
- Split across HTML elements, such as
<span>02</span> <span>8123 4567</span>. - Inside an image.
- Inside an attribute other than a
tel:link'shref, such asaltoraria-label. - Added to the page well after it has loaded.
Write the number in one piece, and use a tel: link so mobile visitors can tap it.
Content Security Policy¶
If the website sends a Content-Security-Policy header, allow the script and its requests:
script-src https://ctjs.au; connect-src https://ctjs.au;
Consent management¶
The script doesn't set cookies or collect form data, page content or contact details. It stores a random session ID in the browser and reads the _ga cookies that Google Analytics has already set, so that calls can be linked to the same session in Google Analytics 4.
If your consent tool blocks the script until the visitor accepts, numbers aren't swapped for visitors who haven't accepted, and their calls can't be attributed. See Why attribution can be missing or ambiguous.
Updates¶
Enfonica updates the script at https://ctjs.au/ct.js in place, so changes reach your visitors without any action on your part.