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 <a> 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-Reviews-Kerala-India.html">Kerala</a>
    </li>
  </ul>
</div>
<script src="http://www.jscache.com/wejs?wtype=featuredgeo..."></script>

Note the <a> 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-Reviews-Kerala-India.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 &lt; 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-Reviews-Kerala-India.html
        rel="nofollow">Kerala</a></li>
      </ul>
    </div>
    <script>scrub_rel()</script>
    <script src="http://www.jscache.com/wejs?
wtype=featuredgeo&amp;uniq=490&amp;locationId=297631&amp;
lang=en_IN&amp;hotel=y"></script>
</body>
</html>

11 thoughts on “Beating the TripAdvisor Badge’s SEO Tactic

  1. I can’t thank you enough for posting this.. I tried adding rel=nofollow myself and had the same result.. this trick helps a ton.. thanks again!

  2. Hey Tahir,

    say I have 10 hotels listing pages on my site.. is there any easy way to insert one rule to rel=nofollow all the pages at once (rather than one by one)?

    many many thanks for this tutorial!

  3. Would it not be easier to just post an image of your badge? I mean it eliminates any java at all on your site?

  4. @Tony – using the Tripadvisor badge will be dynamically updating. Having a static image would have to be constantly updated, or just be a simple image of Trip Advisor, which would be dull.

    @86a71c5efced50db16b54803171f80f3:disqus  Great tip Tahir, thanks for sharing this info.  Trip Advisor should not be able to get away with underhand tactics like this.

  5. I don’t think this works. For one, nofollow needs to be set before the page loads. Adding this with JS after everything has been loaded doesn’t really do anything. Also, GoogleBot does not have JavaScript – therefore it will never set the nofollow attribute on the link as it crawls the site.

    1. I don’t think you followed the post correctly. The ‘nofollow’ attribute is set in source and removed via JavaScript, not the other way around.

  6. Found this thread and thought this was pretty smart. Can anyone tell me how to implement the widget into the text widget in WordPress to have the bade in the side bar while still allowing this setup to work?

  7. I’m curious how you know this actually has any effect on SEO? My understanding (albeit faint) is that Google does now interpret javascript on the pages it crawls.

    See http://googlewebmastercentral.blogspot.com/2014/05/understanding-web-pages-better.html

    One option might be to place the javascript that removes the rel attribute at a url that is blocked by robots.txt

    In any case, we will know for sure when Google releases the “tool for helping webmasters better understand how Google renders their site” (mentioned in the post above).

    1. You’re right, in that we need to figure out how Google will react to the attribute being added in JavaScript. It might even be better to block Trip Advisor’s script itself in robots.txt and let Google’s crawler focus more on the business’s own content.

      1. > It might even be better to block Trip Advisor’s script itself in robots.txt

        FYI: You cannot do this because the Trip Advisor script is not hosted on your domain. Robots.txt only lets you block root-relative urls on your own domain.

Comments are closed.