Vanity for AB testing

I’ve recently come across Vanity an A/B testing plugin/framework for rails. It looks great and I’m keen to give it a try on my next project.

Also, I’ve switched this blog from Mephisto to jekyll. For a content management system, Jekyll makes it very easy to make SEO friendly sites. Of course it’s not your normal CMS as it is a static site generator, but it does help you manage your content just like a CMS.

The SEO impact of Rails 3

Rails 3 is currently in beta, and I’ve had a look through the changes to see what impact, if any they will have on SEO. One change is that ajax helpers now work unobtrusively which will help to clean up the code, resulting in smaller page sizes. This probably won’t have any effect, but it is an improvement.

The other thing is Rails 3 will be faster. Faster render times means that the google bot can index your site quicker and more often. The google bot detects load on the web server by its page render time. I wonder if it things RoR sites are always overloaded?!

Rails SEO starter guide

Google has released their official webmaster SEO starter guide (download pdf, which is worth a look.

Some of these reccomentations have been “rails-ified” and are blogged as a rails seo starter guide There are some nice tips in the post, so check it out.

Rails SEO Around the web

While Ruby on Rails specific SEO is a pretty small subject, compared to the larger world of SEO, it still requires some thought.

Over at http://www.bingocardcreator.com/rails-seo-tips.htm is a very large article on Rails-specific optimizations you can do to improve search engine rankings.

It includes:

  • The Case Study: Daily Bingo Cards
  • On-page Optimization
  • Sexy URLs, or, Default Routes Considered Harmful
  • Taming Your Title Tags (And Other Metadata)
  • Don’t Repeat Yourself… In Your Content
  • Off-page Optimization
  • acts_as_linkbait: making it easy to link to you
  • Bookmarks, Chicklets, and Permalinks, Oh My!

Some of the topics have been covered here at SEOonRails.com but it’s always nice to get another angle on it as there is always more than one way to do something when it comes to programming.

On DZONE you can find a ruby pagerank checker

Over at rubyplus.org are 2 relevant videos. The first is a video describing how to make Google Sitemaps with rails and also on the site is SEO for Rails app using Acts as Taggable on Steroids and Meta Tags Plugins **note a free signup is required to view videos

If you have posted about Rails+SEO or have any suggestions for this blog, please email me at questions @ this domain.com

SEO friendly Ajax

Ajax, one of Web2.0’s core technologies, is based on Javascript which can pose a problem if you want your website to be search engine friendly. Fortunately with Ruby on Rails it’s not too hard to make your Ajax SEO friendly.

I will walk you through the process of making a page with Ajax search engine friendly, using my web design company’s portfolio page as an example.

The basic idea with the page is for portfolio items to display below the list using ajax, and to view on their own page if javascript is disabled.

I will walk you through how I created my SEO friendly portfolio page in 4 easy steps:

  • Creating the content using partials
  • Linking to RJS files using link_to_remote in a search engine optimised way
  • The RJS file
  • Tracking Ajax calls with google analytics

Creating the content using partials

For each portfolio item, I have a partial, app/view/portfolio/_portfolio.html.erb

This partial has all the information I want to display about each portfolio item, and is what will be used in the ajax calls to update the page.

The view file for a single portfolio item, only used when javascript is not available simply renders the _portfolio partial and adds a “back” link. The back link isn’t needed for the javascript-called page so is left out of the partial.



<%= render :partial => 'portfolio', :locals => {:portfolio => @portfolio} %>

<p><%= link_to "&laquo; Back to Portfolio", :action => 'index' %></p>

Linking to RJS files using link_to_remote in a search engine optimised way

In the index action ( app/views/portfolio/index.html.erb ) I need to link to each portfolio item.

Usually you would use link_to, but because we’re doing ajax, we use link_to_remote

Usually when using link_to_remote, the link is to #, as in a href=“#”. But we can specify a url, and that url is used when javascript is disabled.



<%= link_to_remote "More Info", 
:url => {:action => "view", :id => portfolio.id, :format => 'js'}, 
:html => {:href => url_for(:action => "view", :id => portfolio.id)}%>

Now the above code includes :format => ‘html’ and :format => ‘js’ because I am using urls ending in .html, for example, /portfolio/view/xxxx.html rather than /portfolio/view/xxxx. You can probably exclude the format parameters if you are not.

The first paramater of link_to_remote is the link text, the 2nd is the javascript url, and the 3rd is the html url as you can see in the example above.

The RJS file.

Our controller’s view action is pretty simple.



def view

  @portfolio = Portfolio.find(params[:id])

   respond_to do |format|

      format.html

      format.js

    end

end

Rails’s “respond_to” function takes care of separating out the html and ajax requests.

The view.html.erb is already mentioned above, and just renders the _portfolio partial with an added back link.

view.rjs on the other hand contains this:



page.replace "portfolio", :partial => 'portfolio', :object => @portfolio

page.visual_effect :highlight, "portfolio", :startcolor => '#333333', :endcolor => '#000000', :duration => 0.5

There is a blank div with an id of portfolio in the index page, and this gets replaced with the contents of the partial. The partial also has a div called portfolio, this way when someone clicks on another portfolio item, the old gets replaced with the new.

Tracking Ajax calls with google analytics

One final piece of the puzzle is tracking ajax calls with google analytics.

At the bottom of view.rjs is the line



page << "urchinTracker('#{url_for(:id => @portfolio, :action => 'view')}');"

“page <<”:http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods/%3C%3C is the method to send raw javascript in an rjs file. The urchinTracker call tells google to track a page view, and the url given is the non-javascript url of the page.

I hope this has been a useful tutorial, any questions please post a comment.

SEO friendly title tag plugin

I’ve come across a small, but very useful plugin for Ruby on Rails applications.
It was designed with SEO in mind, and it makes keeping your meta title tags, and your <h1> tags in sync easy.

The plugin is hosted at (the very awesome) GitHub : http://github.com/DefV/title_helper/tree/master

Here’s how it works.

In your application layout you call the plugin, passing in your overall site title.


<title><%= title :site_name => "The SEO on Rails Blog" %></title>

If you do nothing else, all pages on your site will have the title “Seo on Rails”.

In your view templates, say app/views/blogpost/view.html.erb you could have this:


<%= title "SEO plugins for Ruby on Rails" %>

This will print out a H1 tag:

SEO plugins for Ruby on Rails



At the same time, the plugin will remember the title and insert it into the layout’s <title> tag before your :site_name.
In our example that would result in :

SEO plugins for Ruby on Rails – The SEO on Rails Blog

Keeping your <H1> tags and your <title> tags in sync is a good thing, and this plugin helps make it very easy.

Screen scraping update ( Already! )

Wow the ruby/rails community works fast. Igvita has an article explaining how to use hpricot with the magic of firefox’s firebug pluign. And scRUBYt has been released, which is a billed as WWW::Mechanize and Hpricot on Steroids

301 Redirects in Rails

A 301 redirect is a permanent redirect, which tells the search engines to index the redirected to URL rather than the current URL.

You can use this when migrating from legacy content management systems, or to make sure that you only have 1 URL per page.

With the folloing code in your controller, Rails makes it easy :


      headers["Status"] = "301 Moved Permanently"
      redirect_to "http://someurl/"

RoR image_tag harmful for SEO?

We all know image_tag, but is it harmful for SEO? By default, it will add an alt tag consisting of the filename, without the extension, and capitalised.

How could this be bad? Well, the question comes down to : is an irelevent alt tag worse than a blank one?

The code in question is one line of the image_tag method in asset_tag_helper.rb.


  options[:alt] ||= File.basename(options[:src], '.*').split('.').first.capitalize

To answer this question, it depends. If your image names are not related to your content then it could be.

To be safe, always pass :alt => with your image_tag.

Update:
I asked Matt Cutts his thoughts about this and here is the reply

If you have a picture of a monkey with filename like apple.jpg or dsc00001.jpg, you shouldn’t have any issues if the alt title is “apple” or “dsc00001”. However, if the image filename is cheap-viagra-debt-mortgages.jpg, then you could run into problems for sure. I’d look at image filenames to make sure that they couldn’t be viewed as keyword-stuffing or spammy. And it doesn’t hurt to preserve the extension (.jpg) in the alt title just so that people realize that the alt title comes from the image filename.

Getting your meta tags on track

Sick of the lame Rails puns in the headlines yet? Great!

Ok, so this post is a kind of ‘Ask the community’ post. How do you deal with meta tags including page titles? We should all know the ideal for titles is to be unique for each page on the site , but how do you go about this the rails way?

Here’s what I do (and it’s just one way of many) :

In my layout/application.rhtml


<title><%= @meta_title %> My Site Name</title>
<meta name="keywords" content="<%= @meta_keywords %>" />
<meta name="description" content="<%= @meta_description %>" />

In my application controller:


  before_filter :meta_defaults
  private

 def meta_defaults
    @meta_title = "Welcome to"
    @meta_keywords = "my keywords"
    @meta_description = "my meta description"
  end

and then in individual actions in my controllers I override the defaults


def view
    @article = Article.find(params[:id])
    @meta_title = "#{@article.name} - "
    @meta_description = @article.short_description
end

I’ve also seen suggestions for using yield and content_for, but to me that is a bit heavy-weight for simple strings.
So, what do you do?