Can You Track A Conversion Outside Of WordPress? Even If It’s On Another Domain?

Knowledge Base > Premium > Can You Track A Conversion Outside Of WordPress? Even If It’s On Another Domain?

in Premium

The Premium version of Simple Page Tester allows you to easily track conversions. In some cases though, you may wish to track a conversion from outside your WordPress installation.

In short, yes you can track conversions outside of WordPress for your Simple Page Tester split test, bBut in some cases you may come up against cross-site scripting restrictions within browsers so you have to be careful about how you do it.

This tutorial assumes you have some knowledge of PHP and Javascript coding. If you don’t, please point your web developer at this page for instructions.

On The Same Domain

If the page you wish to track conversions from resides on the same domain then you can implement a simple javascript call to the WordPress AJAX service.

Put the following code where you wish to track the conversion:

<script type="text/javascript">jQuery.post("http://urltoyoursite.com/wp-admin/admin-ajax.php",{action: "sptAjaxRecordConversion",sptID: 123});</script>

Where 123 is the ID of your Simple Page Tester split test. Don’t forget to change the URL as well.

On Different Domain Or Sub-domain

If the page you wish to track conversions from resides on a different domain (even a different sub domain) you need to do a work around so that it doesn’t come up against cross-site scripting restrictions in browsers.

This will work on most servers, but we caution that it may have restrictions as well based on your server setup. Give it a go and see if it works in your scenario.

Put the following code where you wish to track the conversion:

<script type="text/javascript">
var iframe = document.createElement("iframe");
var uniqueString = "sptThankYouFrame";
document.body.appendChild(iframe);
iframe.style.display = "none";
iframe.contentWindow.name = uniqueString;
var form = document.createElement("form");
form.target = uniqueString;
form.action = "http://urltoyoursite.com/wp-admin/admin-ajax.php?action=sptAjaxRecordConversion";
form.method = "POST";
var input = document.createElement("input");
input.type = "hidden";
input.name = "sptID";
input.value = "123";
form.appendChild(input);
document.body.appendChild(form);
form.submit();
</script>

Change the URL and input.value = “123”; lines to your values.

This code needs to be placed within the <body> tags, as it won’t work inside the <head> tags because it essentially creates an invisible iframe to trigger the conversion on the main site.

0