Hack 84 Track Google Referrals

figs/expert.gif figs/hack84.gif

Use Google's AdWord Conversion Tracking system and PayPal's IPN system to track sales made from Google advertising.

Google has emerged from the search engine wars as the clear winner to date. Its fast, accurate search results are presented in a way that enables users to get search results quickly without the tool getting in the way, unlike many other search engine portals. It is the most widely used search engine on the Internet, and its builders continue to innovate.

Among those innovations is a self-service advertising system that enables small merchants to get wide exposure in a cost-effective, pay-per-click arrangement. When a web surfer looking for an item?a widget, say?goes to Google and types the name of the product into the search box, not only are the search results from the Google Page Ranking system displayed, but so are small, text-based ads related to widgets. As a widget vendor, you can target your AdWords ads to be displayed when a surfer enters certain widget-centric combinations of keywords. However, Google charges you only when a person actually clicks on your ad.

In the field of marketing, the effectiveness of an advertising effort is measured by its conversion rate. The conversion rate can be measured in a variety of ways, but generally it is the sales generated by advertising, divided by the number of impressions (times a consumer sees the ad). For AdWords, Google defines a conversion as "when a click on your ad leads directly to user behavior you deem valuable, such as a purchase, signup, page view, or lead." This corresponds to the marketing industry's response to purchase conversion rate: the number of purchases divided by the number of clicks-through. Understanding the conversion rate of a given ad can help you refine your AdWords ad copy and decide if the campaign is bringing the return on investment you expect.

Google provides a mechanism to help you tally purchases that come from customers clicking AdWords ads. This mechanism is triggered by a small piece of code you place in your transaction processing system. This hack shows how to enable a Google AdWords ad in your PayPal eCommerce system and track sales from that ad's referrals. The system consists of three parts:

  • A tracking-enabled Google AdWords placement

  • A PayPal-enabled selling page

  • An IPN page with the Conversion Tracking Code

7.24.1 Modifying Your Google AdWord Placement

You need to have one or more Google AdWord placements that refer people to your PayPal selling page. You can have as many ad placements as you like.

Log into the Google AdWord system (http://adwords.google.com), go to your campaign summary, and click the Conversion Tracking tab to display the screen in Figure 7-2.

Figure 7-2. Obtaining the AdWord code from Google's Conversion Tracking page
figs/pph_0702.gif


You will see an option to select Basic Tracking or Customized Tracking; select the Customized Tracking option. Select the Purchase/Sale option from the tracking options, which brings you to a page that has a generated a snippet of tracking code. Copy and paste the code into a text editor. It should look something like this:

<!-- Google Conversion Code -->

<script language="JavaScript">

<!--

google_conversion_id = 1234567890;

google_conversion_language = "en_US";

if (1) {

 google_conversion_value = 1;

}

google_conversion_label = "Purchase";

-->

</script>

<script language="JavaScript" src=

                "https://www.googleadservices.com/pagead/conversion.js">

</script>

<noscript>

<a href="https://services.google.com/sitestats/en_US.html" target=_blank>

<img height=27 width=135 src=

                "https://www.googleadservices.com/pagead/conversion/1234567890/?value=1&

label=Purchase&hl=en">

</a>

</noscript>

You'll place this code in your IPN processing page. But first, copy the Google conversion ID from this code (on the fourth line, in this example) for use in your AdWord placement. Use the Edit function from the Ad Group detail page to change the Destination URL. This URL is not displayed to the visitor, but when the ad is clicked, this is the URL to which visitors are sent. Visitors are directed to the PayPal-enabled sales page named widget.asp, and the URL includes a parameter, convid, set to the value of your Google conversion ID:

http://www.yoursite.com/widget.asp?convid=1234567890

7.24.2 Setting up Your Selling Page

To enable the selling page widget.asp to track ad referrals, it needs to include a PayPal button that passes the conversion ID provided by Google to the PayPal system. Do this by putting a standard Buy Now button on the widget.asp page, then adding the PayPal-defined custom variable to the button code. This tag should be added between the opening and closing <form> tags. The custom variable will be hidden from the site visitor and will be populated with the convid variable that was passed as a querystring. Populating the custom variable with this value can be done in a variety of ways, including with JavaScript, but since this example uses ASP for the IPN processing anyway, put it to use here as well:

<input type="hidden" name="custom" value="<%=Request.QueryString("convid")%>">

Now, the PayPal button is able to pass on the Google conversion ID to PayPal. When the transaction is processed, PayPal sends the conversion ID on to your IPN processing page.

7.24.3 Creating Your IPN Processing Page

The IPN page finishes the job of tracking conversions. Take the code you copied from Google in the preceding section and paste it into your IPN page after the standard IPN processing chores (the section that begins with process payment in PayPal's example scripts). Since the code is meant for client-side interpretation, you need to temporarily interrupt the server-side code processing by escaping the processor and adding your script. In ASP, stop the server-side processing with a %> tag and start it again with a <% tag:

'process payment

'stop server-side processing scripts and add conv code

%>

<!-- Google Conversion Code -->

<script language="JavaScript">

<!--

google_conversion_id = <%=Request.Form("custom")%>;

google_conversion_language = "en_US";

if (1) {

 google_conversion_value = 1;

}

google_conversion_label = "Purchase";

-->

</script>

<script language="JavaScript" src=

                "https://www.googleadservices.com/pagead/conversion.js">

</script>

<noscript>

<a href="https://services.google.com/sitestats/en_US.html" target=_blank>

<img height=27 width=135 src=

                "https://www.googleadservices.com/pagead/conversion/<%=

                Request.Form("custom")%>/?value=1&label=Purchase&hl=en">

</a>

</noscript>

<%

'continue processing server-side processing scripts

When an order is placed at your web site from a Google AdWord referral, the Google Conversion tracking system is activated. You can log into your Google AdWords account and evaluate your campaign's effectiveness in Google's conversion tracking system, as shown in Figure 7-3.

Figure 7-3. Measuring your campaign's effectiveness with Google's conversion tracking system
figs/pph_0703.gif


7.24.4 See Also

  • For practical ways to calculate and use conversion rates in your marketing campaigns, see Strategic Database Marketing : The Master Plan for Starting and Managing a Profitable, Customer-Based Marketing Program by Arthur M. Hughes (McGraw-Hill).

  • For the nitty-gritty details on AdWords and conversion tracking, see Chapter 9, "Making Money with Google," of Google: The Missing Manual by Sarah Milstein and Rael Dornfest (O'Reilly).