All Collections
Integrations
Klaviyo
Suppress contacts with Klaviyo popups or forms
Suppress contacts with Klaviyo popups or forms
Updated over a week ago

If you use Klaviyo popups or forms, you can prevent collection of contacts who opt in via your popup or form. This can be done using Klaviyo's Event Listener.

General Structure of the klaviyoForms Event

Klaviyo forms send an event called klaviyoForms to the window each time a form is shown, closed, or submitted. You add one listener to your page for all Klaviyo form events. Below is the structure of the Klaviyo form event:

<script>
  window.addEventListener("klaviyoForms", function (e) {
    if (e.detail.type == "submit") {
      geq.suppress();
    }
  });
</script>

So the full script would look like this (NOTE this is not a script you can use/copy because the collection script is not specific to your account):

<script type="text/javascript">
  !(function () {
    var geq = (window.geq = window.geq || []);
    if (geq.initialize) return;
    if (geq.invoked) {
      if (window.console && console.error) {
        console.error("GetEmails snippet included twice.");
      }
      return;
    }
    geq.invoked = true;
    geq.methods = ["page", "suppress", "trackOrder", "identify", "addToCart"];
    geq.factory = function (method) {
      return function () {
        var args = Array.prototype.slice.call(arguments);
        args.unshift(method);
        geq.push(args);
        return geq;
      };
    };
    for (var i = 0; i < geq.methods.length; i++) {
      var key = geq.methods[i];
      geq[key] = geq.factory(key);
    }
    geq.load = function (key) {
      var script = document.createElement("script");
      script.type = "text/javascript";
      script.async = true;
      script.src = "https://s3-us-west-2.amazonaws.com/storejs/a/" + key + "/ge.js";
      var first = document.getElementsByTagName("script")[0];
      first.parentNode.insertBefore(script, first);
    };
    geq.SNIPPET_VERSION = "1.5.0";
    geq.load("XXXXXXX");
  })();
</script>
<script>
  geq.page();
</script>
<script>
  window.addEventListener("klaviyoForms", function (e) {
    if (e.detail.type == "submit") {
      geq.suppress();
    }
  });
</script>

More details on adding Custom JavaScript Events to Forms can be found here.

Did this answer your question?