Tracking phone calls generated from your website is an important metric. How else will you learn how effective your ads are in leading to phone calls from your website that ultimately lead to conversions? Granted, not every call that comes from a website is the result of an ad. Many calls are organic, meaning they've been driven by the site itself and the content you publish. Regardless of the vehicles that lead to a phone call, it's still nice to know how many of those calls result from a click through on your website.
With the addition of Google AdWords Call tracking to your site, you can track calls that originate from your site or mobile devices. The instructions for adding the Google AdWords tracking code to your site are pretty straightforward. Straightforward, that is, if you have a plain vanilla, generic type of website. If you are using a professional developers' tool like the Genesis Framework, Google's instructions may not apply to you. We've written this article to help you install the Google AdWords call tracking code into your Genesis based child theme.
First Method—Don't Try This at Home
One way of attempting to add the code is with the genesis_attr_body filter:
As simple as it is, the problem with the above code is that it doesn't work. When passed through the filter, it does indeed add the AdWords function to the <body> tag. However, it also sanitizes the code and converts the required single quotes within the function into their respective HTML entities (&039). So the resulting HTML looks like this:
It's not very pretty. It definitely won't work. And we haven't been able to find a work-around.
Second Method—JavaScript
While we're not going to repeat anything you can already learn from the Google AdWords Call Tracking site, one thing their site omits is the fact that you can install their function with a JavaScript snippet. The function below is added to your site's header area. In Genesis you can do this in several ways. You can navigate to the Genesis/Theme Settings admin page and copy the code into the header script meta box. You can also add the code through the Genesis Simple Hooks plugin. Or last, you can create code to add the script through your functions.php file.
Third Time's the Charm
The third method, and the one that we prefer, is to add the code directly to header.php. Genesis child themes typically do not have a custom header.php. Header.php is found in the Genesis directory. Since this is core code, you must not under any circumstances edit this file directly. Doing so will create a multitude of problems for you when the Genesis Framework is updated. You can, however, copy header.php into the root folder of your child theme and then edit that file. The code below is an edited header.php from Genesis Version 2.2.3 that you can copy and paste into the child theme directory. Lines 21 and 22 show the modifications. Change the number to your own.
These guys found a way to escape the characters to get method 1 to work
http://digitalessence.net/how-to-add-onload-to-the-body-using-genesis-add_filter/
I personally think method 2 is the best however I have a question about testing. Do you have to find an adwords ad and click it for the onload to appear? or should it appear on every refresh?
Thanks
I don’t know about the testing. I don’t use AdWords. I wrote this after someone asked for help.
Thanks Victor, quick question – why don’t you like method 2? It’s easier to edit the head from the Genesis theme settings in the WordPress backend rather than copying over the header.php file to the child theme because then you don’t have to worry about manually updating the child header.php when there are future updates to the parent header.php. Just wonderin’. Cheers, Phil
Hi Phil,
You are right of course. The second method provides longevity, but I never said that I didn’t like preference 2. The goal of the article is to provide a method to accomplish what Google is asking us to do. That is, add the tag to the body markup. If you want it in the body tag, create a custom header.php. Thank you for your insight.