Pay-Per-Click webService and client implementation






2.17/5 (5 votes)
Oct 14, 2003
6 min read

56564

295
Introduction into the world of pay-per-click webservices with sample web service and client application
Introduction
This articles demonstrates a sample client application and a web service that consumes data feed provided by FindWhat.com to their affiliate partners. You'll be able to learn about distribution and logging practices in the PPC world and to get access to your very own data feed with direct access to real time FindWhat.com data.
Using the code
FindWhat PPC (Pay-Per-Click) webservice and client implementation
PPC or (Pay-Per-Click) providers have been around for sometime now and they are recognized as one of the hottest segments in online marketing business. PPC engines were one of the first companies that have recognized opportunities presented with development of XML Web Services. They use XML and Web Services extensively to provide distribution of search results among their partners.
PPC Engine Definition: A search engine that allows webmasters to purchase their positions within the search results based on the amount of money they are willing to pay for each click thru their site's listing receives.
Developers can utilize wide range of tools and technologies to build applications that can interact with data providers and develop various client applications that consume web services maintained by PPC engines.
After reading this article you’ll be able to do the following:
- to download your very own web client application that queries FindWhat.com databse
- to learn about distribution and logging practices in the PPC world
- to get access to your very own data feed
Our company (http://www.automob.com/) is one of the partners with FindWhat.com and we had to go through a process of consuming XML data feeds ourselves. This article is a starting point for anyone interested to peek under the hood of PPC world.
Let’s start from description of our architecture that we are going to utilize.
One of the key requirements that we had to comply with was a license agreement that allowed us to distribute PPC links through a single gateway URL on our servers. We have several other websites (http://www.vbrelated.com/, http://www.asprelated.com/, http://www.xmlrelated.com/) where we would like to publish retrieved search results but for tracking purposes we have licensed single URL to simplify administration and maintenance. Naturally, for our own internal distribution of searches, Web Service implementation was the obvious choice. We have created a web service that we host ourselves and provide centralized distribution of search results among all our network websites.
Our main service is freely available at: http://ws.automob.com/ws/ppcfeed/ppcfeed.asmx
We have decided to build our own web service that will help us with logging and querying FindWhat.com database in real time and delivering results consistently across our range of websites that will consume this data. Our web service must be able to log searches and IP addresses into database for future analyzes and be very responsive under heavy load.
Our client application will be a simple ASP.NET form that allows us to post queries to our web service and consume returned datasets.
With this in mind let’s start with simple web service.
GetDataSet( )
Our main Web Service method will require 4 input variables. Our web service consumes raw XML data from FindWhat.com cluster and generates DataSet
that we use in our client applications. We have decided to use DataSet
s as our primary way of exchanging data to have capability to develop lightweight client applications that could directly bind to already structured and properly formatted data.
Description of parameters is quoted from FindWhat.com documentation.
[WebMethod]
public DataSet GetDataSet(string Query,
string IPAddress,
int BaseRecord,
int RecordCount)
Query - An HTML encoded text string representing what the user is searching for. It is important that the text string is encoded properly according to RFC1738. Specifically, non-alphanumeric characters must be encoded as per this excerpt from RFC1738:
“In addition, octets may be encoded by a character triplet consisting of the character "%" followed by the two hexadecimal digits (from "0123456789ABCDEF") which forming the hexadecimal value of the octet. (The characters "abcdef" may also be used in hexadecimal encodings.) Octets must be encoded if they have no corresponding graphic character within the US-ASCII coded character set, if the use of the corresponding character is unsafe, or if the corresponding character is reserved for some other interpretation within the particular URL scheme.”
A very common encoded octet is that of the space character in the US-ASCII set. A space is ASCII value 32 (decimal), 20 (hexadecimal). Therefore, to encode “free email” into the request URL to our servers, you would need to replace the space with “%20”, resulting in “free%20email” as your final encoded string.
IPAddress
– A text string representing the IP address of the user who initiated the search. THIS PARAMETER IS NOT THE IP ADDRESS OF YOUR SERVERS. This is extremely important to include to receive full credit for all searches and click-throughs.BaseRecord
- An integer value representing the first record to retrieve from FindWhat data cluster. For the initial request for any result set, this is always 0.RecordCount
- An integer value representing the document count, or number of documents to retrieve from FindWhat data cluster. The default is 25
Let’s take a look at what is going on inside the Web service. (Note: We can’t disclose complete source code due to restrictions posted by our license but we do provide complete code for the client application.)
We log all searches and IP addresses into MS SQL Server 2000 database for future analyzes by our marketing people by using Business component layer.
// Log Search Query and IPAddress into the database
RelatedObjects.Data.SearchLog.Insert(
ConfigurationSettings.AppSettings["ConnectionString"].ToString()
,Query
,BaseRecord
,RecordCount
,Int16.Parse(ConfigurationSettings.AppSettings["WebServiceId"])
,IPAddress);
// Load Xml data retrieved from FindWhat.com cluster into DataSet
DataSet ds = new DataSet();
XmlTextReader r = new XmlTextReader(
GetUrl(Query,IPAddress,BaseRecord,RecordCount));
ds.ReadXml(r);
Visual Studio Class View
GetUrl()
/// Builds well formatted URL based on requested parameters.
/// Method signature:
/// GetUrl(string Query,
/// string IPAddress,
/// int BaseRecord,
// int RecordCount)
private string GetUrl(string Query,
string IPAddress,
int BaseRecord,
int RecordCount)
This methods is used to build properly formatted URI string that we use to access remote data source. This URI includes assigned partner id and other information necessary to get access to FindWhat.com search cluster that services all web based requests.
GetDataSetDefault()
/// Public method returns default DataSet.
/// Method signature:
/// GetDataSetDefault()
/// Default dataset is used as a placeholder for cases
// when search results return "0"
/// records or when exception occurs
/// during execution of the request.
///
/// Default DataTable is constructed to provide links
/// to our own websites when search query returns
/// "0"records or in case of a default search.
[WebMethod]
public DataSet GetDataSetDefault()
GetDataSetDefault()
and GetDataSet()
are both exposed as public web methods to provide flexible way for client applications to access search results.
PPC Client Application
Now that we have an idea how simple the web service is we need to implement a simple client application. Our Web Service conveniently returns to us already formatted dataset that we can use to directly bind to ASP.NET Datagrid
control.
You can implement variety of applications based on the results returned from the web service. Keyword monitoring, positioning and keyword market assessment are just a few examples of applications that you can build. You can use this information to make smarter decisions about what keywords are in demand and look for niche keywords that cost significantly less but could provide more targeted traffic to your website.
Main method is listed below to give you an example on how to call web service from your source code.
private void SearchButton_Click(object sender, System.EventArgs e)
{
// Retrieve FindWhat result
com.automob.wsdemo.PPC ppc = new com.automob.wsdemo.PPC();
// Databind restrieved recordset
SearchResults.DataSource = ppc.GetDataSet(Request.Form["Query"]
,Request.ServerVariables["REMOTE_ADDR"],
0,
Int32.Parse(Request.Form["MaxRows"])).Tables[1];
SearchResults.DataBind();
}
If you download the sample client application and run it on your local host you’ll be able to see the following results from your browser.
Conclusion
In Pay-per-Click world keyword prices and URL positions change daily if not hourly. It would be almost impossible to maintain quality keywords on your list without researching keyword value and conversion rates for each individual keyword. Access to web services that provide you with raw data can give you information and real time statistic ultimately allowing you to better convert your generated clicks into qualified leads and your own customers.