Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
<script>
  if ({{Email variabelevariable}}.length > 0) {
   window._sqzl.push({
          "event"      : "EmailOptInEmail",
          "email"      : "{{Email variabelevariable}}",
        });
  }
</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:

...

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.

Sending optin

In many order funnels, there’s a checkbox for a newsletter optin. You can send this in events as "newsletter" : "yes" when it is checked. However you might not want an immediate optout when the box isn’t checked. We will explain how you can built in an extra check and send an optin with the email event described above.

First, just as with the email addres, we will create a “Custom JavaScript” variable for the newsletter. Here we will want to get the status of the checbox. So just as with email address, you need the ID of the checkbox.

...

In the example above, the checkbox gives back checked="checked", so we can use this to create our own check. Within the variable you can add the script below, which will give back if checked is true or false:

Code Block
function() {
  return document.getElementById("ContentPlaceHolder1_chkMailing").checked;
}

If you want to check for yourself if you’ve captured the right field, you can always enter the script in the console of the developer tool. If you have done it right, you will see what the result of your script is, when the box is not check, or when it is. So false in the first instance and true in the second:

...

Finally you want to send out the fields as before, event Email with the email address, and add the newsletter = yes, but only when the box is checked. If it is not checked, we will just send the email address, without an optin status. We’ll need to adjust the custom HTML a bit, so we can add this final check. In the example below, you will need to change the variable {{Newsletter checked}} to the variable you made to check the checkbox status. The difference in this example code is that we collect all the contents of the event first in data before we send it out with window._sqzl.push(data)

Code Block
<script>
  if ({{Email variabele}}.length > 0) {
     var data = {
       "event"      : "Email",
       "email"      : "{{Email variabele}}",
     };
    if ({{Newsletter checked}} === true) {
      data.newsletter = 'yes';
    }
   window._sqzl.push(data);
  }
</script>