Book Image

PHP 5 E-commerce Development

By :
Book Image

PHP 5 E-commerce Development

By:

Overview of this book

<p>The popularity of online shopping has increased dramatically over the past few years. There are plenty of options available if you not are planning to build your own e-commerce solution but sometimes it's better to use your own solutions. It may be easy to find an e-commerce system but when it comes to extending it or using it you might come across a lot of difficulties.<br /><br />This book will show you how to create your own PHP framework that can be extended and used with ease, particularly for e-commerce sites. Using this framework you will be able to display and manage products, customize products, create wish-lists, make recommendations to customers based on previous purchases, send email notifications when certain products are in stock, rate the products online, and much more.<br /><br />This book helps you build a Model-View-Controller style framework, which is then used to put together an e-commerce application. The framework contains template management, database management, and user authentication management. With core functionality in place, e-commerce-focused features are gradually added to the framework including products, categories, customizable products with different variations and customer input, wish-lists, recommendations, the shopping basket, and a complete order process.<br />&nbsp;<br />At the end of the book, you will have an e-commerce architecture that will take you from viewing or searching for products, and adding them to your basket, through the checkout process and making payment for your order, to your order being dispatched. Focus is placed on flexibility, so that the framework can be extended as the needs of a particular store change, as illustrated by one of the appendices, which goes through the process of modifying the store to sell downloadable products, as well as physical ones.<br /><br />Supplementary information, such as how to market and promote an online store, as well as take regular backups and perform maintenance is also covered, ensuring you have every chance of success with you own e-commerce framework backed store.</p>
Table of Contents (23 chapters)
PHP 5 e-commerce Development
Credits
About the Author
About the Reviewers
Preface

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 traffic, 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.

Signing up

To sign up for Google Analytics, we simply need to:

  1. 1. Visit http://www.google.com/analytics/ and sign up.

  2. 2. Click on Add Website Profile".

  3. 3. Enter our web address.

  4. 4. Copy the tracking code generated, and put that into our website's footer.

  5. 5. View the profiles list, and click on Edit for our website profile.

  6. 6. Under Main Website Profile Information, click on Edit.

  7. 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:

  • Affiliation or store name

  • Tax costs

  • Shipping costs

  • Customer's city

  • Customer's state or province

  • Customer's country

This is reflected in the JavaScript as follows:

pageTracker._addTrans(
"111", // the order ID - this is a required field
"Props", // affiliation or store name
"10.50", // total - required
"0.00", // tax
"10.00", // shipping
"Newcastle", // city
"Tyne and Wear", // state or province
"UK" // country
);

Add item

For each item within the transaction, we must record:

  • The order ID

  • The product code or stock keeping unit(SKU)

  • The unit price for the item

  • The quantity of the item

We can also record:

  • The product name

  • The category or variation of the product

This is reflected in the JavaScript as follows:

pageTracker._addItem(
"111", // order ID - necessary to associate item with transaction
"P1", // SKU/code - required
"Fake Water Jug", // product name
"Large", // category or variation
"10.50", // unit price - required
"1" // quantity - required
);

Track transaction

Once the transaction, and all items within the transaction, have all been added, we track the transaction, by issuing the following JavaScript call:

pageTracker._trackTrans();

Further reading

Tracking number of sales (but nothing else) — Analytics Talk — http://www.epikone.com/blog/2008/06/25/google-analytics-e-commerce-tracking-pt-3-why-everyone-should-use-it/

  • Tracking lead generation forms (http://www.epikone.com/blog/2008/07/02/google-analytics-e-commerce-tracking-pt-4-tacking-lead-gen-forms/)

  • Tracking API: e-commerce (http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html)