Skip to main content

How to Keep Parameters After a Popup Redirects your Visitors?

Updated over 9 months ago

If your URL contains any parameters (Ex.: utm parameters) before the popup redirects you to another page and if you want to keep these parameters after the popup redirection, just insert the following code snippet into the JavaScript editor of the popup:

<script type="text/javascript">
$(document).ready( function() {
      $(function () {
          var $redirectButton = $('.OM-conversion-action');
          var originalRedirectUrl = $redirectButton.data('redirecturl');
          var parentUrl = OptiMonk.Vars.parentUrl;
 
          var aTag = document.createElement('a');
          aTag.href = parentUrl;
          var urlParams = aTag.search.substr(1, aTag.search.length);
 
          var baseATag = document.createElement('a');
          baseATag.href = originalRedirectUrl;
          var firstCharAfterUrl = baseATag.search ? "&" : "?";
          var newRedirectUrl = originalRedirectUrl + firstCharAfterUrl + urlParams;
          $redirectButton.attr('data-redirecturl', newRedirectUrl);
      });
  });
</script>

Did this answer your question?