Attribution is absolutely vital for good PPC. Imagine if you set up a campaign through Google AdWords and in your reports there were fields for impressions, clicks, and cost, yet no way to view your conversions. What if when visitors converted on your site, you had no way to tell whether they were a direct visit, from another referring site, organic searchers, or pay-per-click visitors? You’d be dumping money into AdWords without any metrics to measure your ROI. That’s just not smart.
Thankfully, it’s easy to set up conversion tracking for Google AdWords. Just tag your conversion event and you’re set (I’ve over simplified this, admittedly). However, what if your business relies partially (or completely) on phone calls as the conversion event? You can’t put a conversion code on your website’s phone number and expect PPC visitors to click it. For the same reason, you can’t put messages on your landing pages telling visitors, “if you clicked on an ad to get here and need more information, call…” some PPC-dedicated phone number. Well, turns out you can; I’ve seen it done. When you really think about it, a phone number makes PPC attribution about as clumsy and random as a blaster.
Well, here’s a more elegant solution for a more civilized age: dynamic website headers. One of the most common locations for a website’s phone number is in its global header (the footer’s less common, so we’ll stick with the header).
Functionality that changes the global header based on the visitor’s source would be all you needed to attribute phone calls to PPC; just make sure you have one dedicated phone line for PPC so you know which source leads come from.
So we know the solution is dynamic headers, but how do we get there? PHP! If you’re website’s server is set up with PHP, you’re in luck. If not, the theory behind this method can be used with any server-side language. Here’s how we do it.
Break Out Your Global Header
If your website is built using static HTML, you’ll have some adjustments to make. You need to break out your global header from the rest of the page. Doing this is actually one of the great things you can use PHP for. While your page content changes page-to-page (if it doesn’t change, you have an extremely boring site), certain elements always the same: the navigation, the footer, and especially the header. While I don’t have the time or space to get into a full PHP lesson here, what you’ll essentially need to do is call in your global header using the “includes” PHP function instead of embedding the HTML on the page.
The file for the header (header.php) can live in an “includes” directory on your server. The file itself can just be the raw HTML that was once in embedded on every page of your site. A nice side benefit is that if you want to change anything in your header in the future, you only need to do it in one place. Neat, huh?
Fortunately, many sites already use this functionality. WordPress does it right out of the box. If you’re site doesn’t have this set up already, it’ll take a little bit of work, but it’ll be worth it in the long run.
Create a PPC Global Header
We want the same header with the same phone number to be displayed everywhere on the site, except when a visitor comes from PPC; in that case, we want them to see the PPC-dedicated phone number only. To do that, we first need to create another header file in the “includes” directory that uses the PPC-dedicated phone number instead of the normal one. Just copy your header.php, rename it ppcheader.php and update the phone number. That’s all we need to do for now. We’ll build out some neat code to call that in at the appropriate time later on.
Use a Query String Parameter
Before we get into actually calling the special PPC header we just made, let’s figure out how we are going to send the message to the site that a visitor actually came from PPC. A simple way is to use a query string parameter. You’ve no doubt seen these in use before. They look something like this:
At this point, all you need to do is decide on your parameter name and the value. Later on, we’ll check to make sure the parameter exists and matches the correct value before returning the PPC header.
For simplicity, I like to set the parameter as PPC and the value as TRUE.
Check for the Parameter and Set a Cookie
Ready for the code-heavy section? Like I said previously, this can’t be a full on PHP lesson, but I’ll try to explain the theory behind each piece of code.
To keep things organized, the code we build out in the following steps should live as its own file in the “includes” directory. Let’s name the whole thing campaignTracking.php. I’ll explain how and where to call this code into your page later on.
The first thing we’ll want to do is check if the PPC parameter equals TRUE.
if($_GET[“ppc”] == “true”)
This snippet uses the $_GET super global (you don’t need to know what a super global is) to grab the PPC parameter and check if it is equal to “true”. If it that checks out, then we want to tell our website that, “yes, this person came from PPC”. That’s where the cookie comes in. A cookie is a bit of info stored in a visitor’s browser that we can reference to call the appropriate header. This also lets us display the PPC header on every page they visit throughout the site since it’s stored in their browser and essentially follows them around.
The value of the cookie we set is arbitrary, but let’s make in easy to understand and make it equal to “sourcePPC” so we know that the “source is PPC”.
$cookieValue = “sourcePPC”;
After we define the cookie’s value, we can use PHP’s “setcookie” function to set a cookie in the visitor’s browser.
setcookie(“SwellPathCampaignTracking”, $cookieValue, time()+60*60*24*90);
The line above sets a cookie named “SwellPathCampaignTracking” equal to our specified cookie value and makes it last for the next 90 days. The setting the expiration date 90 days in the future, we can display our PPC header for that same visitor even if they leave and come back. Essentially, we want to account for people discovering the site through PPC, leaving, and then coming back to convert via phone.
Finally, we want to set something that’s easy to use when we want to call in our PPC header. We’ll call our variable “cookie” and make it equal the same thing as “cookieValue” (which is “sourcePPC”).
$cookie = $cookieValue;
Remember that we only want everything above to happen if our PPC parameter is TRUE. So, we’ll wrap that all up within an ‘if’ statement.
if($_GET[“ppc”] == “true”)
$cookieValue = “sourcePPC”;
setcookie(“ReboundCampaignTracking”, $cookieValue, time()+60*60*24*90);
$cookie = $cookieValue;
The last thing to address, before we move on, is to allow the cookie variable to be set regardless of what page the visitor navigates to (provided they came from PPC).
$cookie = $_COOKIE[“SwellPathCampaignTracking”];
The statement above sets the cookie variable to whatever is stored in the visitor’s browser as SwellPathCampaignTracking. If they’ve visited the site before via PPC, they’ll have that cookie set and the cookie variable will be set correctly. If it’s a visitor from direct, referral, or organic sources, they won’t have a CampaignTracking cookie stored in their browser and the cookie variable will be empty.
Now that we have all that deep coding out of the way, we can do the actual fun part and write our code that will switchup the header. We’ll do this based on the value of the cookie variable.
Remember when we broke out our global header into header.php and ppcheader.php? This section would suck without it. Basically, if the cookie variable equals “sourcePPC” we use ppcheader.php when PHP builds the page. If it doesn’t equal that or isn’t set, we use the standard header.php. Again, for organization, keep this code in the “includes” directory as its own file. Call it switchup.php
Putting it all Together Like A Boss
Now that you’ve built out all your code (like a boss), it’s time to put it all together to make a page.
Note that in order for this whole thing to work, campaignTracking.php needs to fire before anything else. If you don’t check for the parameter and set the cookie before PHP builds the rest of the page, it’ll be too late and you won’t get to pull in the cool PPC header. TL;DR: make sure to include campaignTracking.php before the first tag.
Finally, make sure that you use this layout on every page of your site that you want to enable the PPC-dedicated phone number on. It’s not uncommon to have a different PHP template for your custom PPC landing pages than the one used on the rest of your site. If you have a blog, it likely has it’s own PHP template as well that’ll need to be updated.
Making it Work with Your PPC Campaign
You barely need to change anything in your PPC campaigns to make this work. Simply append “?ppc=true” to your landing page URLs when you build your ads. (If you already use query string parameters, just add &ppc=true).
When a PPC visitor clicks through on one of your ads, all of our awesome PHP code with execute and return the PPC header with the PPC-dedicated phone number. Since we set a persistent cookie, the PPC header will be displayed on every page they visit and not just the first landing page they hit.
Bam! Enhanced PPC Attribution with PHP, or EPPCAwPHP, if you want to be cool.
Follow Mike Arnesen on Google+