A custom implementation of Google Analytics for CONTENTdm 6 users that enables recording metadata field values as GA events
Updated September 2014: set Version to 2.0 - improved jQuery integration for better cross-browser compatibility. It is very important to upgrade to this version to ensure events are tracked across all browsers. Previous code versions have been discovered to miss data in some browsers for recent versions of CONTENTdm.
This code evolved from our interest in tracking pageviews of specific items in our digital collections. We wanted a useful way to record metadata field values as part of the data. For example, in our state publications collections, we utilize an "Agency-Current" field which contains the name of the state agency that published the item. This code enables us to specify which fields we wanted to track, and they are recorded as events.
In this example, if I was tracking the "Agency-Current" field, when an item with that field was viewed, an event would be recorded:
By default, the event category will be "Pageview by metadata field". The field name will be recorded as the event action, and the field value as the event label.
To configure, edit the analyticsjs_cdm.js file
- Ensure that analytics is enabled in CONTENTdm's Website Configuration Tool
- Add the metadata field names you want to record usage of in the trackTheseFields array
To configure, edit the ga_cdm.js file
- Add the metadata field names you want to record usage of in the trackTheseFields array
- Edit gaAccount so that it contains your GA account number
- Edit digitalCollectionsDomain so that it contains your site's domain
- Optionally edit hostedAliasDomain if you have a hosted instance URL