Managing a site requires you to keep constant track of stuff. How many page visits are you getting on your landing pages? What’s the bounce rate? Is your site down? And many, many more parameters. These are relatively simple to track via analytics software, because they occur on your site. You can set up notifications and thresholds to get an email whenever you need.
But what about actions that happen outside your site? There’s no way for you to track those. And yet, we often need information about what happens offsite. To solve this, we use postback URLs.
3rd Party Notifications via E-mail
Let’s say you have an affiliate site that sends traffic to sellers like Amazon. When a visitor clicks one of your links, the seller places a cookie on their computer so that they’re able to credit you with the sale and give you your commission. Whether or not the sale happens, there’s no way for you to know about it, other than through the seller themselves.
Of course, the sale shows up in their standard reports, but you won’t get a notification in real time. Now the obvious solution is for the seller to send you an e-mail whenever you get credited for a sale, and indeed this is what a lot of them do.
The problem arises when it’s a massive seller that needs to send out thousands upon thousands of e-mails every day. Or worse, the sale might be credited through an affiliate network that aggregates thousands of sellers. For such a service to send an e-mail each time a sale occurs is unthinkable. They would have time to do nothing else!
And that’s where the postback URL comes into play.
What are Postback URLs?
A postback URL is nothing but a URL with a parameter attached to it. Whenever a conversion or a sale takes place, the 3rd party site simply pings a special URL that you specify with a bunch of parameters attached to it.
It’s your job to now intercept that URL, process it, and perhaps send an email to yourself or your clients, or whatever other tasks you need to perform. At its heart, that’s all it is – a special URL that you need to look out for, and which the seller pings whenever an action occurs on their site of which they need to inform you.
This saves them the trouble of sending out an e-mail, which is quite an expensive operation in terms of resources. It also relieves them of the headache of their e-mails going to spam etc.
Receiving a Postback URL and Sending an E-mail Address
Let’s say you have a website example.com. Whenever an event occurs off your site, you want a ping to be sent to:
example.com/?amount=something
We’d like to intercept this request and craft an e-mail ID telling us that something happened. To do this, paste the following code into your WordPress installation:
function get_notified() {
$varname = 'amount';
if( isset($_GET[$varname]) && '' != $_GET[$varname] ) {
mail('[email protected]', 'Sale Notification', "Sale!");
die();
}
}
add_action('init', 'get_notified');
If you don’t know how to do this, check out this tutorial on how to insert custom code snippets into WordPress.
Now you need to tell your seller or 3rd party provider that they have to ping this address whenever they want to notify you. And here’s the e-mail you get:
Pretty neat right?
Authenticating your E-mail
You should note that Gmail is quite strict these days about whom it receives mail from. So you might need to authenticate your domain with a DKIM key to ensure that Gmail accepts it. Other providers like Yahoo don’t seem to have any such problems. So use a solution that works for you!
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!
Jon says
What address would it ping to? I am trying to figure out the post back url for my site and followed your instructions but it doesn’t tell me what address I would put in the postback url field on my 3rd party site.
Bhagwad Park says
You can define your own postback URL. Just use the example in this article to get an idea of how it works!