Category Archives: Magento

How To Set Up Google Content Experiments in Magento 1.7

I spent a lot of time looking around for a way to conduct Google Analytics Content Experiments in Magento with very little success. I did find this post in Finnish that detailed one approach and I adapted his findings (with the help of Google Translate) in to the following solution.

Step 1 – Set up your Content Experiment code block
In CMS > Static Blocks add a new static block with an easy to identify name such as “Google Content Experiments Code” and an identifier such as “google_code_block”. Paste the Content Experiments code in to the wysiwyg editor by pressing the HTML button and pasting the code in to the pop up window. Click “update” and the window will close but you won’t see anything appear in the wysiwyg window. This is normal.Make sure you enable the code block and save it.

Step 2 – Alter your template to write the code block
In your appdesignfrontenddefaultyourtemplatetemplatepagehtmlhead.phtml file add the following code right at the top after meta charset="UTF-8"

<?php  $routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
if($routeName == 'cms' && $identifier == 'home') {
echo $this->getLayout()->createBlock('cms/block')->setBlockId('google_code_block')->toHtml();
} else {

}?>

If you are performing an experiment on a page other the home page you will need to change the $identifier string to match your page identifier which is your URL key. You will also need to change the Block ID if you have called your code block something different.

Step 3 – Disable the code block on your variation pages
Set up the variations of your CMS page and in the Layout Update XML part of the Design tab paste the following XML code:
<reference name="head">
<remove name="google_code" />
</reference>

This will stop the code block from loading on the variation pages as per Google’s instructions.

Step 4 – Verify it all works in Google Analytics!
Check it all works in GA and start your experiment.

I’ve yet to work out a way to perform experiments on category pages without creating a brand new category containing the same products.

Quickly Add Open Graph tags to Magento

A client of mine recently shared the site report for her site from Silktide with me and it showed a few things needed improving, particularly the Open Graph integration. Her site is a new Magento store, built on Magento Community Edition 1.7.02 and whilst I’d added share buttons to the product pages via the ShareThis widget I hadn’t added in any Open Graph tags to optimize the sharing process. The Silktide report spurred me in to action and I thought I’d share my code to quickly add the OG tags to your magento pages.

First you’ll need to edit your theme’s head file at “app/design/frontend/YOURTHEME/default/template/page/html/head.phtml” and add the following lines of code:


<meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getGroup()->getName(); ?>" />
<meta property="og:description" content="<?php echo strip_tags(htmlspecialchars($this->getDescription())) ?>" />
 
<?php if (!in_array(Mage::app()->getFrontController()->getAction()->getFullActionName(), array('cms_index_noRoute', 'cms_index_defaultNoRoute'))) {
    $currentUrl = Mage::helper('core/url')->getCurrentUrl();
}?> 
<meta property="og:url" content="<?php echo $currentUrl ?>" />
 
<?php if (Mage::registry('current_product')) : ?>
<?php if (Mage::registry('current_product')->getMetaTitle() == "") {
  $ogTitle = Mage::registry('current_product')->getName();
} else {
  $ogTitle = Mage::registry('current_product')->getMetaTitle();
}
?> <meta property="og:title" content="<?php echo $ogTitle ?>" />  

<meta property="og:image" content="<?php echo Mage::helper('catalog/image')->init(Mage::registry('current_product'), 'small_image')->resize(200,200);?>" />
<?php endif;?> 

This code is mainly aimed at product pages and sharing them on Facebook so it renders the product’s title, description and a thumbnail image of the product, resized to the recommended size of 200 pixels square. Any HTML in the description is stripped out leaving the plain text. The code also adds the current store view’s name (you may need to edit this in Configuration > Manage Stores) and the URL of the current page. Finally the code checks if the product has a Meta Title set and if not it displays the name of the product instead. Upload the altered file, clear your Magento cache and away you go. You can check your integration with the Facebook debugger tool.

UPDATE
The code below checks if we’re on a product or category page and pulls the relevant image and sets the correct og:title for the category or product page.


<?php if (Mage::registry('current_category')) : ?>
<?php $ogTitle = Mage::registry('current_category')->getName();?>
<?php
$_category  = Mage::registry('current_category');
$cur_category = Mage::getModel('catalog/category')->load($_category->getId());
$imageUrl = $cur_category->getImageUrl();
?>
<meta property="og:image" content="<?php echo $imageUrl;?>" />
<?php endif;?>
<?php if (Mage::registry('current_product')) : ?>
<meta property="og:image" content="<?php echo Mage::helper('catalog/image')->init(Mage::registry('current_product'), 'small_image')->resize(200,200);?>" />
<?php endif;?>
<meta property="og:title" content="<?php echo $ogTitle ?>" />

I still haven’t found a way to get all the product images but it will be necessary to loop throught the product image array and write out an og:image tag for each image.

5 Essential Magento extensions for UK shopping sites.

I’ve been spreading my wings lately and offering low cost e-commerce solutions using Magento Community as the base for websites. Magento Community is a fine piece of software with a mind-boggling array of features and options but it does lack certain abilities that make it a truly great product. Thankfully due to the open-source nature of Magento there are plenty of extensions available to make Magento do what you want it to do.

Yoast MetaRobots
This exension by the respected Yoast (known for his excellent WordPress SEO extension) allows you to control the Meta Robots tags quickly and easily on a variety of pages on your Magento site to help direct the flow of “link juice” around the site and prevent pages from being indexed. Yoast MetaRobots allows you to set pages such as Send to a Friend, Customer Account pages, Tags and Checkout as “noindex, follow” from a simple panel in the System > Configuration  > Web section of Magento’s administration area.

MSemantic
Now that Google (and Bing to a lesser extent) are really pushing Rich Snippets as an important part of your site’s content it is imperative that your Magento site implements semantic markup for Rich Snippets for Google and Bing. The MSemantic extension takes away all the pain of marking up your site with a simple to install extension. Once installed your products and reviews contain the correct markup for Rich Snippets integration which will help with your rankings and visibility in Google, Google Shopping and of course Bing.

Google Content API for Shopping
The only way to get your products listed on Google Shopping if you use Magento. Simply install the extension, add your Account ID, Google Account Email Address and Password and then upload your selected products to Google. You can configure the extension to automatically update the product listing on Google if you change the product in any way and it’s easy to see what products you have listed and what needs adding. The extension also supports custom attributes and the full range of Google Shopping taxonomies.

Meanbee Royal Mail Domestic and International Shipping
This simple to use extension adds the current Royal Mail shipping costs to your Magento store and works out the correct postage cost based on location and weight. My 2 qualms with this extension are you can’t add the cost of your packaging materials to the shipping rates so you would have to add a bit extra on to each product’s cost or define a shopping cart rule to get a more accurate cost and the extension does not take the packet’s dimensions in to account as it’s based purely on weight. Otherwise this extension is fantastic and a really simple way to set up Shipping Table Rates in Magento for UK users.

Clever CMS
Magento’s Content Management System is a bit… well, basic to polite, but Magento is primarily an e-commerce solution not a fully featured CMS. Clever CMS extends the basic Magento CMS with some great additions that I feel are essential to any good CMS. Clever CMS allows you to assign permissions to your pages so you can decide who sees your pages (logged in customers, not logged in customers, etc.) and more importantly creates a tree structure for your pages similar to Magento’s category tree structure so you can create sub pages and rearrange your menus at will and each store view can have it’s own “tree”. You can define your own URLs and if you change them at a later date then Clever CMS will set up a 301 redirect from the old URL to the new one.