Manuel Scan – matelso script with Single-page applications and AJAX requests

The matelso script searches, respectively scans the content of a web page automatically for the set search texts in order to replace them with a call tracking number. This automatic search can be supplemented or completely replaced, if the appropriate places in the HTML of the code for the matelso Script are marked.
The function is called “manual scan” and is executed by a JavaScript code.
The function can be used to improve the performance on the page, if for this the automatic scan is completely switched off. You can find the option for this in the control panel in the domain settings:

In some cases, the function is also necessary for the number to be exchanged at all.

 

Single-page applications and AJAX requests #

A peculiarity of web applications and pages with AJAX requests is that they load additional elements after the page itself has actually finished loading. As a result, the tracking library cannot independently detect that additional page elements have been loaded. In order for phone numbers to be replaced in the loaded elements, you must use the manual scan to instruct the tracking library to scan the page again once all elements are loaded.

 

How to run the manual scan #

You can do this by executing the following JavaScript code after the AJAX request is successfully executed. Alternatively, you can set another trigger when to activate this script.

MANUAL SCAN:
// test if the tracking library is already loaded

if (mtls.loaded) {

// run the manual scan on the site

mtls.scan();

}

 

If you know exactly which DOM element was loaded, you can also pass it to the scan function.

This shortens the runtime of the scan function.

SCAN WITH ELEMENT
mtls.scan(window.document.getElementById('id_des_geladenen_elements'));

 

Using the manual scan does not replace the matelso script or the S&R configuration. Both must still be set up for the website. It only replaces or supplements the script scan function according to the set up search texts.