Interacting with Web Services There are a number of web services available that we as developers can interact with to either help make tasks easier for us, or to help us to target new markets. Now, we will investigate a number of these web services and APIs. In this chapter, you will learn more about: Google products Google Analytics, and its benets for e-commerce sites Amazon web services eBay developer center Google products Google has a product search feature, which allows users to search specically for products using the Google search engine. Products can be added to this search engine using the Google merchant center. The Google merchant center is an area where online retailers can list (and manage these listings) their products for including in the Google product search. Google merchant center is a specialized section of Google base: a search area that was designed for allowing anything to be added to the Google index—documents, notes, products, events, and so on, essentially anything that generally wasn't in a web page. As this service grew, the products aspect was spun off into the merchant center. Apart from being able to manually add products, we can also add a feed of products. This feed of products would be tied directly to our store, updating in real time as we added new products, removed older ones, and updated details. By adding a feed, Google can keep an up-to-date copy of our product catalog for inclusion in its search results. • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Interacting with Web Services [ 304 ] To get started with the Google merchant center, we need to sign up, or sign in at http://www.google.com/base/. Adding the feed to the Google merchant center Within the merchant center, we can click on the Data feeds link on the left-hand side, and then on the New Data Feed button to create a new feed. Here we can set: The Target country to determine who would see results from our feed The Data feed type (googlebase) A name for the feed, that is, the Data feed lename (for example feed.xml) After adding the feed to the Google merchant center, we set an update schedule. Setting an update schedule The update schedule is where we actually tell the Google merchant center where our feed of products is, and how often it should be updated. When we have added our feed to the center, there is a link next to it under the Upload schedule column called Create. If we click on this, we will see the Scheduled Upload form. This form allows us to select: How frequently we wish to upload the feed: Daily/Monthly/Weekly When we want to update the feed (for example, day 15 of every month) Our time zone The URL of the feed Creating the feed To be able to actually create the update schedule we discussed, we need a product feed. We could use a tab-delimited feed, which would be easy to do using a spreadsheet program. If we did it this way, we would need to create and upload the feed manually—something we don't want to do. XML is a standard way of representing data, and is particularly useful when interacting with web services. • • • • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Appendix A [ 305 ] Product feed controller We could create a product feed controller, which generates the feed for us. One requirement for XML feeds in the Google merchant center, is that they end in .xml, so we would have the controller search the second bit of the URL (for example, productsfeed/latest.xml) split the string by the dot, and then depending on the rst word, here latest, display the relevant feed. The controller would build a query of products, cache the results, and store them as a template variable, which would go into the XML template for the data feed. <?xml version="1.0"?> <rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:c="http://base.google.com/cns/1.0"> <channel> <title>Juniper Theatricals Product Feed</title> <link>http://www.junipertheatricals.test</link> <description> Theatrical supplies, props and costumes </description> <! START items > <item> <title>{name}</title> <link> http://www.junipertheatricals.test/products/view/{path} </link> <description>{description}</description> <g:image_link>{image}</g:image_link> <g:price>{cost}</g:price> <g:condition>new</g:condition> <g:id>{ID}</g:id> <c:retail_price type="decimal">{cost}</c:retail_price> <c:promo_offer type="boolean">false</c:promo_offer> </item> <! END items > </channel> </rss> This is an XML feed showing some basic information for products. We can dene our own custom elements to this too if we wish, such as how the product could be customized, if it is a downloadable product, if we can upload an image, the delivery time, and so on. More information on this is available from Google at http://www. google.com/support/merchants/bin/answer.py?answer=160603&hl=en. This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Interacting with Web Services [ 306 ] Other useful link For information on data feed specications, visit http://www.google.com/support/merchants/bin/topic.py?topic=24946 Alternative—Google Base Data API In addition to adding feeds to the merchant center, we can also add products directly from our framework if we wish. We could do this using the Google Base Data API (http://code.google.com/apis/base/). Further details on inserting, updating, and deleting data items using this API are available at http://code.google.com/ apis/base/starting-out.html#insupdel. Others We've discussed Google quite a bit here; they are a very big player in this arena, being one of the most popular search engines around. There are some other options available, and these have their own specications for data feeds, which are also supported by the Google merchant services center. These feed types include: shopzilla shopping.com Google Analytics Another Google offering is Google Analytics, a useful web-based application for monitoring website analytics, such as visitor numbers, visitor lengths, popular pages, sources of trafc, and so on. One particularly useful feature within Google Analytics for us is its e-commerce functionality. At minimum, we could add some code to indicate an order has been placed; this would allow us to look at data such as how many visits it took to make a purchase. We can of course go into more detail, supplying other information such as how much the order was for, and so on. Google Analytics works by having a small piece of JavaScript inserted at the bottom of every page on our site. • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Appendix A [ 307 ] Signing up To sign up for Google Analytics, we simply need to: 1. Visit http://www.google.com/analytics/ and sign up. 2. Click on AddWebsiteProle». 3. Enter our web address. 4. Copy the tracking code generated, and put that into our website's footer. 5. View the proles list, and click on Edit for our website prole. 6. Under MainWebsiteProleInformation, click on Edit. 7. Select Yes, an e-commerce Site. We now have an account set up for e-commerce, and the tracking code is installed; next we need to track e-commerce transactions. Tracking e-commerce To track e-commerce sales in our store, we can record transaction details and item details, and then submit this information to Google Analytics. The information is all captured into a JavaScript function call, which sends the data to the Analytics' server. The following JavaScript needs to go after the pageTracker._trackPageview(); from our initial tracking code. Add transaction To add the transaction, we must at least store: The order ID The total cost of the order (excluding shipping) We can also record: Afliation or store name Tax costs Shipping costs Customer's city Customer's state or province Customer's country • • • • • • • • This material is copyright and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 . Site. We now have an account set up for e-commerce, and the tracking code is installed; next we need to track e-commerce transactions. Tracking e-commerce To track e-commerce sales in our store, we. our website's footer. 5. View the proles list, and click on Edit for our website prole. 6. Under MainWebsiteProleInformation, click on Edit. 7. Select Yes, an e-commerce Site. We now. and is licensed for the sole use by jackie tracey on 23rd February 2010 953 Quincy Drive, , Brick, , 08724 Appendix A [ 3 05 ] Product feed controller We could create a product feed controller,