Customize WebSphere Commerce JSTL for Coremetrics

Pass custom data to Coremetrics accounts

As part of its out-of-box integration between IBM® WebSphere® Commerce store and IBM Coremetrics®, IBM WebSphere Commerce Version 7 provides a custom JSTL that acts as a wrapper for generating Coremetrics analytics JavaScript tags. In most cases, the default library satisfies your needs; however, sometimes you want to pass custom data to Coremetrics accounts. This article explains how to extend the JSTL in order to pass custom data to Coremetrics.

Priyajith Chembakassery (priyajith@in.ibm.com), Senior Staff Software Engineer, IBM

Priyajith Chembakassery is a Senior Staff Software Engineer with the IBM India Software Labs, Bangalore. He has over 5 years of experience with IBM WebSphere Commerce and works for the Analytics, Marketing and Promotion components in WebSphere Commerce.



28 August 2012

Also available in Spanish

Introduction

IBM WebSphere Commerce Version 7 provides an out-of-box integration between the WebSphere Commerce store and IBM Coremetrics, the preferred cross-channel analytics service provider for WebSphere Commerce. The integration provides the following features:

  • A custom JSTL for WebSphere Commerce, which acts as a wrapper for generating the Coremetrics analytics JavaScript tags
  • A Dojo-based analytics store tagging framework for the Web 2.0 store, where Coremetrics tags are triggered based on asynchronous events
  • A JavaScript library to support the display of dynamic Intelligent Offer recommendations from Coremetrics
  • Integration of the Coremetrics dashboard and reports with the IBM WebSphere Commerce Management Center UI using single sign-on

Frequently used abbreviations

  • JSTL: JavaServer Pages Standard Tag Library
  • SDO: Service Data Objects

This article explains how to pass custom data to Coremetrics accounts by customizing the out-of-box JSTL.

Coremetrics for WebSphere Commerce provides a custom JSTL for generating the Coremetrics JavaScript tags. These JSTL tags are placed in the respective store pages to generate the Coremetrics tagging required for the page. For more information about the JSTL tags for Coremetrics integration, go to "Analytics tag library for IBM WebSphere Commerce" in the WebSphere Commerce Version 7.0 Knowledge Center (see Resources).

The data generated out of the box by these tags usually satisfies your needs. In some cases, you might want to pass values for one or more parameters that are different from the default values. For example, the Coremetrics JSTL cart tag and order tag pass the discounted price of a product in the unit price parameter of the Coremetrics cmCreateShopAction5Tag() tag and the cmCreateShopAction9Tag() tag, by default. If you want to pass the nondiscounted price in these parameters instead of the default discounted price, you can customize the WebSphere Commerce JSTL for Coremetrics.


Customizing the tag library

The WebSphere Commerce JSTL for Coremetrics acts as a wrapper for the Coremetrics JavaScript tags. These JSTL tags generally take the ID of an object, a databean, or a SDO object as input and generate the appropriate Coremetrics JavaScript tags. Every JSTL tag class for Coremetrics integration has a generic base tag class and an implementation class. The generic base tag class gathers the data that is needed to generate the Coremetrics JavaScript tag. The implementation tag class extends the generic base tag class and formats the data based on the analytics vendor's requirements. These tag classes use the data to generate the Coremetrics JavaScript tags and write those generated tags to the HTML output stream.

Table 1 shows the WebSphere Commerce analytics tags and the corresponding Coremetrics implementation tag classes. The table also shows the methods that must be overwritten to customize the analytics data that is passed to Coremetrics.

Table 1. WebSphere Commerce analytics tags and the corresponding Coremetrics implementation tag classes
Analytics Tag Generic Base Tag Class Coremetrics Implementation Class Method(s) to overwrite
pageview com.ibm.commerce.bi.taglib.
CommonBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.CommonTag
public HashMap<String,
Object> getParamMap()
registration com.ibm.commerce.bi.taglib.
MembershipBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.RegistrationTag
public HashMap<String,
Object> getParamMap()
element com.ibm.commerce.bi.taglib.
ElementBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.ElementTag
public HashMap<String,
Object> getParamMap()
conversion com.ibm.commerce.bi.taglib.
ConversionBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.ConversionTag
public HashMap<String,
Object> getParamMap()
product com.ibm.commerce.bi.taglib.
ProductBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.ProductTag
public Vector<HashMap
<String, Object>> getParamVector()
order com.ibm.commerce.bi.taglib.
OrderBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.OrderTag
  • public Vector<HashMap
    <String,Object>> getOrderItems
    ParamVector()
  • public HashMap<String,
    Object> getOrderParamMap()
cart com.ibm.commerce.bi.taglib.
CartBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.CartTag
public Vector<HashMap<String,
Object>> getParamVector()
campurl com.ibm.commerce.bi.taglib.
CampaignBaseTag

com.ibm.commerce.bi.taglib.
coremetrics.CampaignURLTag
public HashMap<String,
Object> getParamMap()

The abstract base tag class stores the data in either a java.util.HashMap object or in a java.util.Vector object. For example, because the pageview tag requires a minimal amount of data, the CommonBaseTag class stores the data for analytics in a HashMap object. However, the CartBaseTag class must pass data on all order items in the shopping cart. For this reason, the CartBaseTag class uses a Vector to store the analytics data. The individual cart item details are inside a HashMap. The details of the structure of the HashMap object and the keys used in the map are listed in the javadoc for each base tag class.


Example: Customize the order tag to pass nondiscounted price to Coremetrics

This example shows how to pass the nondiscounted price of a product in the shopping cart to Coremetrics. Out-of-the-box, the order tag uses the discounted price of a product when generating the individual cmCreateShopAction9Tag(...) tags for each item in the shopping cart. The order tag also uses the discounted product price to calculate the order subtotal for the entire order when generating the cmCreateOrderTag(...) function. To pass the nondiscounted price, you must extend the data used to generate both JavaScript tags.

To customize the data, perform these tasks:

  1. Create a new custom JSTL tag class that extends the com.ibm.commerce.bi.taglib.coremetrics.OrderTag class. See Listing 1 for a sample of the Skeleton class code.

    Listing 1. Skeleton class

    packagecom.ibm.mycompany.bi.taglib.coremetrics;
    importcom.ibm.commerce.bi.taglib.coremetrics.OrderTag;
    publicclassExtOrderTagextendsOrderTag {
    }
  2. Overwrite the two methods that generate data for cmCreateOrderTag(...) and cmCreateShopAction9Tag(...).The getOrderParamMap() method generates data for cmCreateOrderTag(...) and the getOrderItemsParamVector() method generates data for cmCreateShopAction9Tag(...). See Listing 2 for a sample of the extended OrderTag class code.

    Listing 2. Extended OrderTag class

    package com.ibm.mycompany.bi.taglib.coremetrics; import java.util.HashMap; import java.util.Vector; import com.ibm.commerce.bi.taglib.coremetrics.OrderTag; import com.ibm.commerce.bi.taglib.TagConstants; public class ExtOrderTag extends OrderTag { /** * Override the default implementation to use the non discounted * product price values for base price and order total */ public Vector<HashMap<String, Object>> getOrderItemsParamVector() { Vector<HashMap<String, Object>> oiVector = super .getOrderItemsParamVector(); String orderId = null; for (HashMap<String, Object> itemMap : oiVector) { orderId = (String) itemMap.get(TagConstants.ORDER_ID_KEY); String partNumber = (String) itemMap .get(TagConstants.PART_NUMBER_KEY); String nonDiscountedPriceForThisItem = getNonDiscountedItemPrice(partNumber); itemMap.put(TagConstants.BASE_PRICE_KEY, nonDiscountedPriceForThisItem); String orderSubTotalWithOutDiscounts = getNonDiscountedOrderTotal(orderId); itemMap.put(TagConstants.SUBTOTAL_KEY, orderSubTotalWithOutDiscounts); } return oiVector; } /** * Override the default implementation to use the non discounted * product price values order total */ public HashMap<String, Object> getOrderParamMap() { HashMap<String, Object> oMap = super.getOrderParamMap(); String orderId = (String) oMap.get(TagConstants.ORDER_ID_KEY); String orderSubTotalWithOutDiscounts = getNonDiscountedOrderTotal(orderId); oMap.put(TagConstants.SUBTOTAL_KEY, orderSubTotalWithOutDiscounts); return oMap; } /** * A helper method that returns the non discounted price of an item */ private String getNonDiscountedItemPrice(String partNumber) { // TODO Implement this method return null; } /** * A helper method that returns the non discounted total price of an order */ private String getNonDiscountedOrderTotal(String orderId) { // TODO Implement this method return null; } }
  3. Create a new tag library descriptor for the custom tag and tag class. Ensure that the descriptor contains the new custom tag name and the tag class mapping. See Listing 3 for a sample of the a tag library descriptor code.

    Listing 3. Tag library descriptor 

    <taglib> <tlib-version>1.0</tlib-version> <jsp-version>1.2</jsp-version> <short-name>cm-ext</short-name> <uri>http://commerce.ibm.com/coremetrics-ext</uri> <display-name>Custom tag library for Coremetrics enablement</display-name> <description>Custom tag library for Coremetrics enablement</description> <tag> <name>order</name> <tag-class>com.ibm.mycompany.bi.taglib.coremetrics.ExtOrderTag</tag-class> <body-content>empty</body-content> <description>Sets ShopAction9 and Order tags for order confirmation pages.</description> .............. </tag> </taglib>

    To get the attribute list for the out-of-the-box order tag, refer to the coremetrics.tld file inside the Stores.war/WEB-INF directory.

  4. Update the store page to use the custom descriptor and the custom order tag.
    Refer the custom tag library descriptor, as shown here:
    <%@ taglib uri="http://commerce.ibm.com/coremetrics-ext" prefix="cm-ext" %>.
    Update the tagging for order to use the custom order tag, as shown here:
    <cm-ext:order orderType="..." />

Conclusion

You can pass custom analytics data to Coremetrics by overwriting the default methods that are provided by WebSphere Commerce JSTL.

Resources

Learn

Get products and technologies

  • Evaluate IBM products in the way that suits you best: Download a product trial, try a product online, use a product in a cloud environment, or spend a few hours in the SOA Sandbox learning how to implement Service Oriented Architecture efficiently.

Discuss

  • Get involved in the My developerWorks community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis.

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Commerce on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Commerce, Business analytics
ArticleID=834839
ArticleTitle=Customize WebSphere Commerce JSTL for Coremetrics
publish-date=08282012