Sitemap Submit – Magento Extension to Submit your Google Sitemap

I’ve made a new Magento extension for submitting your store sitemap to Google, Yahoo, Ask and Bing. My new extension can submit automatically whenever the sitemap is regenerated, or on-demand from the admin UI. More about how I made it and how it works below, but first a little background.

How Sitemap Submit came to be

As of last week I have been taking a train to work in a far off land called Pukekohe a couple of times per week. Pukekohe itself is not traditionally known as a high-tech startup hub – but in 2010 the number of small high-tech software engineering companies has grown considerably (probably at least 200%).

What all this means is I get a couple of hours a day, two times a week where I’m literally stuck in front of my laptop as the train I’m on rocks and weaves it’s way across country to WWA HQ. This new Magento extension I have made is the first of hopefully many what I’ll now call Public-Transport-Projects. The extension will manually or automatically submit your Google sitemap file from your Magento store to several major search engines (Google, Yahoo, Bing and Ask).

How to use Sitemap Submit

To start with, you’ll need to install it – head over to the Sitemap Submit extension page on Magento connect to get started with that.

Once installed, It’s dead easy to use – basically you generate your sitemaps the usual way using Magento’s built in functionality – to do this go to the Catalog -> Google Sitemap section of the admin interface as shown in the screenshot below.

Sitemap Submit  found in the Magento Sitemap admin menu option

Sitemap Submit found in the Magento Sitemap admin menu option

Once you have your sitemap.xml generated you can click on it and view the details. One this edit screen you will see the new Submit button, which when clicked, my extension will submit your sitemap to Google, Yahoo, Ask and Bing. You can see in the screenshot below where the button should be.

The Sitemap Submit submit button on the sitemap edit screen of Magento Admin

The Sitemap Submit submit button on the sitemap edit screen of Magento Admin

There is also a configuration option for automatic submission (In System->Config->Catalog->Google Sitemap). What this means is that whenever your sitemap is generated or regenerated (by you or by cron if you have it configured to do so) then the sitemap will also be submitted to the search engines.

The Sitemap Submit Configuration options - an option to enable automatic submission each time the sitemap is generated, and also the yahoo App Id required for yahoo submission.

The Sitemap Submit Configuration options - an option to enable automatic submission each time the sitemap is generated, and also the yahoo App Id required for yahoo submission. Find them in System->Config->Catalog->Google Sitemap

The only other configuration to be aware of is the yahoo app id, to use the api you need to add an app id – read all about the Yahoo API and the app id. If you omit an ID, the extension will just skip notifying Yahoo, no big deal.

How Sitemap Submit works

I won’t bore you with too many details, basically it’s made up of an observer that watches out for the regeneration and a service object that actually does it (plus the usual various Magento extension things, like a controller and a helper.

The only tricky thing was the core Sitemap.php object didn’t fire a generating event, which if you read my explanation of Magento events and observers you’ll know is quite important. I override and slightly alter the default Magento sitemap as shown below:

 public function generateAction() {
    	parent::generateAction();
    	Mage::dispatchEvent('sitemap_sitemap_generate', array('sitemap'=>$this));
    }

That fires the event which is then picked up by my observer and in turn my submission service kicks off. It basically runs through each search engine and submits the sitemap using the required URL’s like so :

         	//ping google
        	if($this->_pingGoogle($url)) {
        		$msg = $msg . "Pinged Google successfully<br/>";
        	} else {
        		$msg = $msg . "Failed to ping Google.<br/>";
        	}

… and then I actually make the request like this:

 
	protected function _makeRequest($ping) {
 
		$curl = new Varien_Http_Adapter_Curl();
        $curl->setConfig(array(
            'timeout'   => 20
        ));
 
        $curl->write(Zend_Http_Client::GET, $ping, '1.1');
        $data = $curl->read();
 
        if ($data === false) {
            return false;
        }
 
        if ($curl->getInfo(CURLINFO_HTTP_CODE) == 200) {
	        // Mage::log($data); // uncomment to debug raw submission response
	        return $data;
        } else {
	        Mage::log("Submission to: " . $ping . " failed, HTTP response code was not 200");
	        return false;
        }
 
        //TODO: handle timeout?
 
	}

And that’s about it, you can read the full story in the open-source PHP code, in fact I’d invite you to do so, and give me some feedback on it!

The Sitemap Submit Feature Roadmap

I’ll be looking to extend the extension further over the next month or so in two ways. One is to add many more search engines that have an open sitemap submit function. The second is I want to enable more SEO capability and allow store submission to the many Magento store directories and Magento showcases like Magento Parade. I’m also, as always, really keen to hear feedback on fixes and features that you would like to see in the product.

You might also be interested in:

  1. Making a sitemap.xml for Magento
  2. Magento, Google XML Sitemaps and my Magento Speed Test
  3. Magento contact form error: Unable to submit your request
  4. New feature for Magento Gmail or Google Apps Email Extension
  5. Sneak Peek at the New Magento Gmail/Google Apps and SMTP extension

36 Responses to “Sitemap Submit – Magento Extension to Submit your Google Sitemap”

  1. Chris February 3, 2010 at 6:41 am #

    When signing up for the Yahoo API what url should be used for the application entrypoint? Just the root website or is something more specific required?

  2. Scott February 18, 2010 at 9:15 am #

    Would be nice if you could also build in sitemap splitting support for websites with more than Google’s 50K URL / 10MB limit.

    Like this:
    http://www.offshoresoftwaredevelopmentindia.com/blog/2009/06/13/magento-extension-google-xml-sitemap-split-module/

    Not sure if these two extensions would work together or not.

  3. Paul February 20, 2010 at 10:55 am #

    Not able to get 0.2.1 to show up in admin. (?)

  4. Ashley February 20, 2010 at 12:57 pm #

    Can you confirm the files are installed in app/code/community/Aschroder? Also you have cleared your cache?

  5. Paul February 23, 2010 at 10:24 pm #

    Got it…Cache. Thanks

  6. jerry March 8, 2010 at 4:38 am #

    How to work in multi websites ? generate it , always main site url.

  7. Ashley March 8, 2010 at 6:08 pm #

    Good question – thanks to Filipe my extension will submit the correct Magento store URL to Google, Yahoo, Bing etc however it looks like a display bug in the Magento Core renderer (Mage_Adminhtml_Block_Sitemap_Grid_Renderer_Link) that causes it to use this:

    $this->htmlEscape(Mage::getBaseUrl('web') . $fileName);

    when it should probably use:

    Mage::app()->getStore($sitemap->getStoreId())
    ->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK) . $fileName;

    The htmlescape() I’m not sure about – can any URL characters actually mess with HTML? I guess there could be spaces etc in the url path, perhaps I should escape my url too – anyone confirm this?

  8. Ken April 7, 2010 at 11:17 am #

    Hi Ashley,
    I’m having a minor issue with your Sitemap extension and was hoping you could help. When the sitemap is submitted to Google, Yahoo, etc. it’s being submitted as DOMAIN/index.php/sitemap.xml when the actual address is just DOMAIN/sitemap.xml – is there a simple way I can remove the “index.php” bit so that the various search engines can fine my sitemap rather than a 404 error? Thanks!!

  9. Ashley April 7, 2010 at 1:20 pm #

    Hi, Please check the base url in your system configuration settings – perhaps the index.php is coming from there? Let me know.

  10. Ken April 7, 2010 at 1:25 pm #

    No, nothing in there. I know I’m stuck with the index.php for most of my URLs until I can get the Base Rewrite to work correctly, but that’s not the case with the sitemap. Anyway, I’ll fiddle around and figure it out eventually, just thought you might have an idea. Thanks!

  11. Ashley April 7, 2010 at 1:35 pm #

    oh – it might be a bug then – If url rewrites are off then I need to return the base URL without index.php, I’ll look into it when I get a moment. Thanks for the heads up.

  12. Ken April 7, 2010 at 1:39 pm #

    Anytime. Keep up the great work!

  13. Ken April 12, 2010 at 2:27 pm #

    Finally managed to get my rewrites working properly, so the sitemap extension is behaving just as it should for me now. Good luck w/ the potential bug fix & thanks again for a great addon!

  14. Gary April 13, 2010 at 3:46 am #

    Hi Ashley,

    I have tried the plugin on Magento 1.2.x, but cant see the set-up forms etc. Does it work on this platform?

    Thanks,
    Gary

  15. Gary April 13, 2010 at 4:28 am #

    I should have mentioned that the specific issue is that I can enter the Yahoo API code etc under the configuration part, but that when I run the Submit option for the sitemap, I get the following error.

    Fatal error: Call to undefined method Varien_Http_Adapter_Curl::getInfo() in /home1/myweb/public_html/mywebsite/app/code/community/Aschroder/SitemapSubmit/Model/Submit.php on line 126

    However, manual generation does work as expected.

    Gary

  16. Ken May 8, 2010 at 12:43 pm #

    Hi Ashley,

    I’ve just recovered from having my site hacked (grr, PHP code injection) & am concentrating on hardening security wherever I can. I noticed last night that the sitemap.xml file generated by your extension always sets itself to 666 permissions, meaning that it’s world writable. It’s easy enough for me to change the perms, but a bit of a headache to have to remember to redo it every time it gets generated. Is there something in the code I could change to make the file always generate with 644 permissions?

    Thanks!!
    - Ken

  17. Ashley May 8, 2010 at 2:56 pm #

    Sorry to hear about your hack – was it a vulnerability in Magento or some other PHP script? God suggestion to limit the sitemap permissions.The sitemap.xml is actually generated by the built in Magento code, I just took a look though and I think I could add something to my extension to tweak the permissions. I’ll add it to the list of features for the extension, and update it when I’m next on the train.

  18. Ken May 8, 2010 at 7:02 pm #

    Hi Ashley,

    Thanks ;) It was a nightmare to cleanup, but I think we’re more solid than ever now, so I ‘spose it was for the best. It was actually vulnerabilities in an old WordPress installation I hadn’t updated or removed & wasn’t using – laziness on my part pure and simple.

    I’ll keep my eyes here for updates & will just alter perms manually in the meantime.

    Thanks again!
    - Ken

  19. jlapitan May 29, 2010 at 1:08 am #

    i cant find the configuration option for automatic submission

  20. Ashley May 29, 2010 at 2:27 pm #

    It’s in System->Config->Catalog->Google Sitemap – I should make that clear in the blog post, thanks for the heads up.

  21. Mike Reid August 4, 2010 at 5:14 am #

    Hi
    I just installed this on 1.4.1.1 and it’s not showing up in the admin.
    Is it not compatible with that version?

  22. T-Shirt Printing October 27, 2010 at 6:27 am #

    I see the Yahoo Notification API is being shut down in Dec 2010. Is there are plan to support the new Update Notification service?
    http://developer.yahoo.com/search/siteexplorer/V1/updateNotification.html

  23. iain November 24, 2010 at 7:35 am #

    Hi Ashley, I tried to install the extension using Connect but got this error..

    “Invalid package identifier provided: http://connect20.magentocommerce.com/community/ASchroder_SitemapSubmit

    any suggestions..?

    thanks

  24. Ashley November 24, 2010 at 11:33 am #

    Um I think you’re trying to use connect20 – but that’s for Magento 1.4.2 right? I haven’t tested the extension with that version of Magento, it probably doesn’t get put on connect20 until marked as compatible (I’m guessing…)

  25. lexd1 December 29, 2010 at 12:09 pm #

    Yahoo API Key #We’re shutting down this service in December 2010. For further details, please see the Deprecated Services blog post.#
    And Now??
    Thanks a lot for your the great work

  26. Valentín February 5, 2011 at 7:38 pm #

    Thanks for this great extension.
    I note that this extension don´t generate sitemap for AW-Blog contents. I think that this is very important.

  27. Todd March 16, 2011 at 3:22 pm #

    Hey Andy,

    Trying to get your extension installed for toggle.co.nz.

    Mage Connect keeps falling over. Can you flick me through the source to info@toggle.co.nz

    Cheers bud.
    Todd

  28. Todd March 16, 2011 at 3:23 pm #

    Make that Ashley…

  29. HobbyID April 2, 2011 at 12:48 pm #

    Great extension Ashley! Is there anyway to confirm that the sitemaps are submitted? Mine are being regenerated by Mage’s cron daily, but I’m not certain if they are successfully being submitted to Google etc…

  30. Rose April 20, 2011 at 10:46 am #

    Is this compatible with Magento CE 1.5?

  31. Ashley April 20, 2011 at 2:04 pm #

    Hi, Rose – I haven’t tested it on a 1.5 site yet, you could give it a go and let us all know?

  32. Bart May 26, 2011 at 10:43 pm #

    Rose,
    Did you test this on 1.5+ yet?
    Does it work on CE 1.5?

  33. Joel June 3, 2011 at 6:30 am #

    This extension looks to be a great time-saver. Much appreciated. Are there any plans for a new version incorporating the new method Yahoo is using or site maps?

  34. Rose September 5, 2011 at 6:32 pm #

    Hi,
    I sort of got sidetracked in my attempt to upgrade to 1.5, I was setting up to upgrade and was checking all the extensions I have installed. If you check over at magento connect it seems many people are having difficulty installing this with 1.5. Maybe you can take a look and see if you can help us out and get it to work in 1.5. It is a great extension and I think we would all apreciate if we could continue to have this great functionality in 1.5.
    In advance, Thanks so much for all you have done in Magento. I just tried your speedtest very nice. Thanks

  35. emil November 4, 2011 at 5:16 am #

    My question is like “Rose”. If you can update your extension with 1.5 or even 1.6. thanks

  36. lena w January 1, 2012 at 8:29 am #

    example of a sitemap http://www.postpot.com/sitemap/sitemap.php

Leave a Reply:

Gravatar Image