Monday, July 16, 2007

How to Implement Google Analytics in a CONTENTdm System

I recently received a question regarding how to add Google Analytics code to CONTENTdm system web pages in response to a Library Insider article I wrote in February 2007, “Discovering More Information about Your CONTENTdm Users by Using W3C Format or Google Analytics” (v. 5, no. 2, page 2). In response to that question, and for the benefit of others who may be interested to know, I will elaborate here.

The fundamental question is, “Where do I plug in the Google Analytic code?” If you are familiar with CONTENTdm, you know that there are many PHP pages in the system so determining where to insert the Google code can be a challenge.
The following CONTENTdm pages are ones that I selected for Analytics code to be inserted:
• item_viewer.php
• document.php
• meta_viewer.php
• viewer.php
• page_text.php(optional)
• side_side.php(optional)
• any entry pages you desire(Optional)

If you are interested to know why I chose these pages, keep on reading. The item_viewer.php is required for viewing non-compound objects. There are also other PHP pages called when item_viewer.php is displayed, although we do not need to worry about them because they are all rendered into a single page, item_viewer.php.

The next three pages, document.php, meta_viewer.php, and page_text.php, are required to view compound objects in CONTENTdm. One might ask, “Isn’t document.php enough?” The answer is “No.”

Inserting the Analytics code in only the document.php page will result in untracked hits when someone is viewing the item description, side description, side and text, side by side, next page, and previous page assets associated with a compound object. Document.php consists of three frames. Two of the frames are static and will not be tracked when users are navigating using the functions I mentioned above. If you want to track which compound objects and their corresponding metadata are used, meta_viewer.php and viewer.php also need to be registered with Google Analytics.

Page_text.php is used to display the page and text of a compound object. Side_side.php is used to display two compound objects side by side. If you would like Google Analytics to tell you how often these two functionalities are used, you should insert the Analytics code in these two pages. These two are optional because ultimately, these two pages will use viewer.php and meta_viewer.php to display contents. Now that you know where to insert your Analytics code, the hardest part is done. Let us move on to actually inserting the code.

On its Google Analytics how-to page is an explanation of how to insert the code in a dynamic PHP page by writing a PHP script that produces Javascript code. You do not need to follow this step. You can just follow the instruction for static pages, which is to insert the Google code right before the closing body tag. Once you have completed these steps, Google will begin providing you with incredible information about usage of your CONTENTdm system.

For more information, contact P. Budi Wibowo, Ball State University Libraries’ Head of Digital Libraries and Web Services, BWibowo@bsu.edu, (765) 285-8032

Labels: , ,