Build Your Own Web Measurement Application: Commerce Data

Fundamental to online retailers successful with web measurement data is the ability to get non-traffic data into the analysis. In this hack, wel show you how to add the value of a transaction to the mix and tie it back to your referring sources.

In this hack, we’ll return to our sample program and demonstrate how to extend it to collect additional data. We’ll use the example of measuring revenue, but the same method could be used to collect other types of data. Any data you can access using JavaScript can be passed in the page tag, written to the logfile, and then analyzed by the logfile reader. For example, you could report visitors’ screen sizes or visitor segments by the same method.

When a visitor to the web site makes a purchase, we want to record that information. We do this by putting additional JavaScript on the page after the transaction is completed—normally the “thank you” page on the web site.

In this hack, we’ll assume that you have some way of accessing the revenue amount using JavaScript. How to do that is very dependent on the shopping cart software you use, and we won’t cover it in any detail here. Some shopping carts pass the amount back to you when the transaction is finished, whereas others seem to try and make it as hard as possible. As a last resort, you can approximate by using a fixed amount, such as the amount of the average transaction.

The Code: Page Tag and Tag Processor

Assuming that you somehow have ...

Get Web Site Measurement Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.