Thursday, June 17, 2010

Organic Search | identify source page details

Problem :
 
We had a requirement to personalize a landing page based on what search term the user used when they performed a search on an organic search site (e.g. Google, Yahoo, Bing etc).
 
Here’s the detailed scenario:
1.      User goes to google and enters a search term
2.      Google shows the result set based on the search term
3.      Somewhere in the results will be a link (not sponsored link) to our client’s website
4.      The user clicks the link and comes to our site, at this point we want to know what search term the user used
5.      Based on the search term we would like to target specific content to the user on that page
 
What we want to know is outside of sponsored links, is it possible to identify what search term was used to perform the search. Will it be available in the HTTP header or some other means to get it.
 
 
Solution : [C#]
 
You can use "Referral URL" to extract search term, like with Google, referral URL for "test" (searched test in google.com) will something be like given below (q=test), by parsing the URL you can extract the search term.
In general Your web site visitors could come from different sources, like search engines, blogs, banner ads, affiliates, web directories etc.
To find out which page is generated request to your page, use this code:
 
string MyReferrer = Request.UrlReferrer.ToString();
 
Here is the code for paring the source url:
 
    private String findSearchText(String referrerURL, List paramList) throws UnsupportedEncodingException {
        int queryStringIndex = referrerURL.indexOf("?");
        if (queryStringIndex < 0 || queryStringIndex >= referrerURL.length() - 2) {
            return null;
        }
        referrerURL = referrerURL.substring(queryStringIndex + 1);
        String[] paramSplits = referrerURL.split("&");
        for (int i = 0; i < paramSplits.length; i++) {
            String[] paramValueSplits = paramSplits[i].split("=");
            if (paramValueSplits.length != 2) {
                continue;
            }
            if (paramList.contains(paramValueSplits[0])) {
                return URLDecoder.decode(paramValueSplits[1], UTF_8_ENCODING);
            }
        }
        return null;
    }
 
The List paramlist is the following list:
 
 
 

No comments: