Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

With some CMS's it can be difficult to get the data into the datalayer or send it via Javascript, an alternative solution can be to scrape the data from the HTML elements via Google Tag Manager. Below are some scripts that help with this, although you'll need to make a few changes.

The first step is to create a 'Custom Javascript' variable at 'Variables' with this as code:

function() {
  var email = document.getElementById("sMailAddress").value;
  var reg = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
  
  if (reg.test(email) == true) {
    return email;
  } else {
    return "";
  }
}

In line 2, change the sMailAddress value to the ID that is in your form. We also validate if the given value is in a valid email format.

 How do I find the ID?

Right click on the input field you want to measure, e-mail in this example, and click 'Inspect'. Next, a screen opens which shows you the HTML element including the ID.

Invalid file id - UNKNOWN_MEDIA_ID

You will see id=sMailAddress for this example

The next step is to send an event to Squeezely with this variable. So you create a custom HTML tag with the code below, where we have built in a check so you do not send an empty event:

<script>
  if ({{Email variabele}}.length > 0) {
   window._sqzl.push({
          "event"      : "EmailOptIn",
          "email"      : "{{Email variabele}}",
        });
  }
</script>  

Here "Email variable" is the name as you saved the above JS function in GTM. The trigger for this tag will usually be a click on the submit button of the form, for example:

Invalid file id - UNKNOWN_MEDIA_ID

The class name for the button can be found in the same way as the ID of the input field, see "How do I find the ID?" above. You can choose between an ID or a class.

  • No labels