We can add custom parameters on the fly to a redirect URL through the WisePops' JS Callbacks feature.

Let's say we want to redirect our visitors that click on a CTA to https://example.com/ with a dynamic GET parameter year. For example, during the year 2020, the CTA should redirect to https://example.com/?year=2020.

Popup Creation

We will start by creating a CTA block into our popup:

Note that we have chosen to close the popup when the CTA is clicked instead of redirecting to a URL. This is because we are going to handle the redirection by ourselves. To avoid confusion, we want the built-in redirect config to be hidden since it won't be used.

Also, note that the "Track clicks" option is checked. This is important for our custom behavior to be enabled.

After-tracked-click Callback

Now, let's write a callback that is triggered on the After tracked click event:

// Custom redirection with dynamic param
var year = (new Date).getFullYear();
window.location.href = 'https://example.com/?year='
  + encodeURIComponent(year);

First, we prevent the default click action (so the popup does not get closed when clicking on the CTA). Then, we redirect the page to the dynamically generated URL.

Here we used the WisePops interface to add the JS callbacks. You might want to write this code on your own website instead (to make it work on multiple popups or to inject back-end variables). Please refer to this article to learn how to do so.

Did this answer your question?