30%off
Cyber Monday Sale

How can I track conversions occurring in third-party websites?

Nelio A/B Testing is a plugin specifically designed for WordPress. Its aim is to make A/B Testing in WordPress extremely easy. However, this entails some limitations: as soon as one of your visitors leaves WordPress and accesses an external page, Nelio A/B Testing can no longer track her activity.

Even though usually this is not a problem as all events tend to occur in WordPress, there are some scenarios in which the conversion occurs outside. One typical example is an e-commerce system, where the checkout process is performed outside WordPress. Let’s see a few solutions to this problem.

Method 1. Using “External Page” Conversion Actions

If you’re interested in tracking the fact that a user visited an external page, the easiest way to do so is by using External Page conversion actions. Using this conversion action, you can specify the URL that should trigger a conversion.

However, there’s a catch: the conversion action doesn’t actually test “a visit to the external page”, but rather the fact that “the user click on a link that will take her to that external page.” As a result, this conversion action will only work if there’s a direct link from your WordPress site to the external page and might not be exactly measuring what you want (but it’s close enough).

Method 2. Redirecting your visitor back to WordPress

The easiest solution to overcome the fact that a user “left” your WordPress site and, therefore, you cannot track whether she fulfilled your conversion action or not is to redirect her back to WordPress once she’s converted. For instance, consider the following scenario:

  1. A visitor decides to buy a product or service you’re offering in your WordPress site.
  2. She then clicks on Buy and she goes to an external page called http://external.com/checkout/, where she’ll have to fill a form with some payment details.
  3. Once she’s completed the form, she checks-out and the purchase is completed. The user is now in http://external.com/purchase-completed/.

In order to know that the purchase has been successful, we could add a redirection in http://external.com/purchase-completed/ page and send the user back to your WordPress site. You might be able to do this using the External website setup options or, if you have access to its source code, by adding a simple JavaScript such as:

<script type="text/javascript">
window.location = 'https://your-wordpress-site.com/thank-you/';
</script>

which redirects the user to a Thank You page in your WordPress site.

If you now use this Thank You page in your test (using a Page View conversion action), you’ll be able to track a conversion that occurred outside WordPress.

Please note this Thank You page can be an already existing page or a page you specifically created for tracking that conversion.

Please also note that the page should not be accessible from anywhere else, or you’d be counting conversions that could have never occurred.

Method 3. Using custom JavaScript events

As you may already know, when a visitor lands on a tested page, Nelio A/B Testing will randomly assign a variant to said visitor. That is, they’ll either see version A or version B. We store this value in a cookie. This cookie is useful in two ways: on the one hand, it guarantees that the visitor will always see the same variant when reloading the tested page. On the other hand, it tells our plugin which variant “triggered” a conversion. That is, if the visitor saw variant B and then there’s a conversion, we know that this conversion occurred “thanks to variant B.”

When it comes to cross-domain conversion events we face certain limitations. Most browsers currently limit access to third-party domain cookies, which means that, while on a third-party page, we can’t tell if a conversion event originated after the user saw variant A or variant B (because we can’t look at the cookie we just mentioned).

But we implemented a workaround. Nelio A/B Testing comes with a “custom JavaScript” conversion action that lets you trigger a conversion programmatically from any page:

Conversion action with a customized JavaScript event
Conversion action with a customized JavaScript event

If you include the tracking script (https://your-wordpress-site.com/wp-json/nab/v1/external.js) in a third-party page, the script will add a tiny, hidden iframe in your target page. This iframe will load the actual tracking script and it’ll behave like a “window” to your actual domain. The script also exposes a couple of functions (nab.convert and nab.trigger), that lets you trigger the conversion event from the “parent window,” even though the event itself will be actually triggered within the iframe. All you have to do is call the appropriate function as described in the conversion action.