Beating the TripAdvisor Badge’s SEO Tactic

The Problem

Recently, I got a reference to this article from my Product Manager, regarding TripAdvisor badges and how they boost SEO. Their secret is a simple link that links deep into TripAdvisor website and makes your site a donor of link love to TripAdvisor. This is somewhat bad for hotel owners who might find that TripAdvisor trumps the search ranking for their brand name.

The easy solution to prevent that from happening would be to slightly edit TA widget and use a rel="nofollow" attribute in the anchor that links to TripAdvisor. The clever guys at TA, though, have a JavaScript check that disables the widget if you try to do this. Well, how about we turn their own trick on to them?

Fooling the TripAdvisor ‘rel’ check

Let’s look at the anatomy of a TripAdvisor badge, as it would have to be embedded on our site. Here’s a sample badge (some element IDs have been munged):

<div id="TA_featuredgeo490" class="TA_featuredgeo">
  <ul id="Cgaw" class="TA_links sx5tpn4arx">
    <li id="CrCRPg" class="E4yIRnh9y">
      <a 
      href="http://www.tripadvisor.in/Hotel_Review-g293860-d297631.html">Kerala</a>
    </li>
  </ul>
</div>
<script src="http://www.jscache.com/wejs?wtype=featuredgeo..."></script>

Note the link in line #04. We want to adorn it with a rel="nofollow" attribute but TripAdvisor’s JS doesn’t allow us to do so. Rather, it disables the badge if we do so. The solution for getting the nofollow attribute in there is:

  1. Paste in the widget and set rel="nofollow" in the widget’s anchor tag
  2. Write a JS function to locate the anchor and call .removeAttribute('rel') on it
  3. Before the widget code calls any of its own JS, make sure that you call your function to scrub the rel attribute

The function to scrub the rel attribute looks like this:

scrub_rel = function() {
  var container = document.getElementById("CrCRPg");
  var anchor = container.childNodes[0];
  anchor.removeAttribute('rel');
}

The widget HTML then looks like this:

<div id="TA_featuredgeo490" class="TA_featuredgeo">
  <ul id="Cgaw" class="TA_links sx5tpn4arx">
    <li id="CrCRPg" class="E4yIRnh9y">
      <a href="http://www.tripadvisor.in/Hotel_Review-g293860-d297631.html"
            rel="nofollow">Kerala</a>
    </li>
  </ul>
</div>
<script>scrub_rel()</script>
<script src="http://www.jscache.com/wejs?wtype=featuredgeo..."></script>

Note the rel="nofollow" attribute in line #05 and the extra script tag calling our scrub_rel() function in line #08. Voila! You’ve stopped yourself from leaking SEO Karma to TripAdvisor!

Following is the complete HTML, so that you get the picture. I’ve also changed the logic to search for tripadvisor anchor tags to a more portable but less efficient implementation. You can choose this or the one above, based on whether you know how to locate the anchor tag for your widget manually.

<html>
<head>
<title>TripAdvisor Badge Demo</title>
<script type="text/javascript">
scrub_rel = function() {
  var links = document.getElementsByTagName("a");
  for (var i = 0; i < links.length; i++) {
    var anchor = links[i];
    if (anchor.href.search(/(tripadvisor)/) != -1) {
      anchor.removeAttribute('rel');
    }
  }
}
</script>
</head>
<body>
    <div id="TA_featuredgeo490" class="TA_featuredgeo">
      <ul id="Cgaw" class="TA_links sx5tpn4arx">
        <li id="CrCRPg"
        class="E4yIRnh9y"><a href="http://www.tripadvisor.in/Hotel_Review-
g293860-d297631.html"
        rel="nofollow">Kerala</a></li>
      </ul>
    </div>
    <script>scrub_rel()</script>
    <script src="http://www.jscache.com/wejs?
wtype=featuredgeo&uniq=490&locationId=297631&
lang=en_IN&hotel=y"></script>
</body>
</html>

Previous Post:
Capturing Rain

Next Post:
Creating Hand-held HDRs

Articles

Tahir Hashmi