Set up custom unsubscribe page to trigger API call when a user Unsubscribes from Email

There are some cases when you want to notify your backend system when a user Unsubscribes from Email marketing. To do this, you can build a Custom Unsubscribe Page, which triggers an API call when this happens.

Procedure:

  1. Create a new Unsubscribe Page, following the guide in our documentation.
  2. In the <script> section, you can add a custom post action to trigger the API call: 
<script>
var fnSubmit = function(event) {
event.preventDefault();
$.post( $(this).attr("action"), $(this).serialize() )
.done(function() {
$("#statusOk").toggle();

// Add the API call to be executed on successful unsubscribe
$.post('https://example.com/unsubscribed-through-lp', {
user_email: '{{ user_email }}'
});
});
.fail(function() {
$("#statusFailed").toggle();
});
};
$("#unsubscribe_single").submit(fnSubmit);
$("#unsubscribe_all").submit(fnSubmit);
</script>

 


Was this article helpful?
Have more questions? Submit a request