Skip to main content
All CollectionsAdvancedJavascript
After-tracked-click Event
After-tracked-click Event
Updated over 2 months ago

Introduction

The after-tracked-click event is a powerful feature in Wisepops' JS callbacks system. It fires after the conversion of a popup, allowing you to execute custom actions or modify behavior after a user interacts with specific elements.

Event Trigger Conditions

The after-tracked-click event is triggered when a user clicks on the following elements (if the "track click" option is enabled):

  1. Call-to-action (CTA)

  2. Multiple Calls-to-action

  3. Image

  4. Link in a text block

  5. Links in HTML blocks with the class wisepops-track-click

Note: Signup forms do not trigger this event. For form submissions, refer to the after-form-submit event.

Basic Usage

Here's a basic example of how to listen for the after-tracked-click event:

javascriptCopywisepops('listen', 'after-tracked-click', function(event) { // Your custom code here });

Preventing Default Action

You can prevent the default action (e.g., loading a new page, scrolling to an anchor, closing the popup) by calling preventDefault() on the event:

javascriptCopywisepops('listen', 'after-tracked-click', function(event) { event.preventDefault(); // Your custom code here });

Important: Preventing this event will only cancel the final action. The popup will still be considered as converted. To prevent the whole conversion, use the before-tracked-click event instead.

Accessing the Event Target

The event.target represents the clicked element, which is the same as the native click event target:

javascriptCopywisepops('listen', 'after-tracked-click', function(event) { var clickedElement = event.target; // Use clickedElement as needed });

Use Cases

1. Dynamically Add a Custom Parameter to a Redirect URL

This example demonstrates how to add a dynamic parameter (current year) to the CTA's redirect URL:

javascriptCopywisepops('listen', 'after-tracked-click', function(event) { // Polyfill for IE11 (if needed) if (!Element.prototype.matches) { Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector; } if (!Element.prototype.closest) { Element.prototype.closest = function(s) { var el = this; do { if (Element.prototype.matches.call(el, s)) return el; el = el.parentElement || el.parentNode; } while (el !== null && el.nodeType === 1); return null; }; } // Add the current year as CTA URL parameter var year = (new Date()).getFullYear(); var link = event.target.closest('a'); if (link) { link.href += (link.href.indexOf('?') === -1 ? '?' : '&') + 'year=' + encodeURIComponent(year); } });

2. Forward Current URL Parameters

This example shows how to copy specific parameters from the current URL to the CTA's destination URL:

javascriptCopywisepops('listen', 'after-tracked-click', function(event) { // List of parameters to forward var parametersToForward = ['utm_source', 'utm_content']; // Parse URL var vars = document.location.search.substr(1).split("&"); var queryString = {}; for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); try { queryString[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); } catch (error) { console.warn('Failed to parse parameter ' + pair[0]); } } // Polyfill for IE11 (if needed) // ... (same as in previous example) // Update the CTA link with current params to forward var params = []; parametersToForward.forEach(function (paramName) { if (typeof queryString[paramName] !== 'undefined') { params.push(encodeURIComponent(paramName) + '=' + encodeURIComponent(queryString[paramName])); } }); var link = event.target.closest('a'); if (params.length && link) { link.href += (link.href.indexOf('?') === -1 ? '?' : '&') + params.join('&'); } });

Best Practices

  1. Always test your callbacks thoroughly to ensure they work as expected across different browsers and scenarios.

  2. Consider performance implications when adding complex logic to your callbacks.

  3. Use error handling to prevent potential issues from breaking your popup's functionality.

  4. When possible, add your custom JS callbacks directly on your website instead of using the Wisepops interface. This allows for better version control and the ability to use backend variables.

Conclusion

The after-tracked-click event provides a powerful way to customize user experiences and track interactions with your Wisepops popups. By leveraging this event, you can create more dynamic and personalized popup behaviors, enhancing the overall effectiveness of your marketing campaigns.

Did this answer your question?