Reference > Analytics for IBM WebSphere Commerce > Integrate a store with an external analytics system (other than Coremetrics)
Create vendor-specific tag classes by extending the base tag classes
For each event that capture analytics data for, create a vendor-specific tag class that extends the base tag class. For example, to capture data about product view events, extend the ProductBaseTag class. Each base tag class generates standard data for its associated event; however, the base tag classes support optional parameters you can use to send additional information to the external analytics system, if necessary.
Before you begin
Review the following topic to familiarize yourself with the available base tags:Analytics tag library for IBM WebSphere Commerce
The vendor-specific tag class must:
- Extend the base tag class for the corresponding event
- Implement the logic to generate the vendor-specific JavaScript functions
- Write the generated JavaScript to the HTML output stream
Procedure
- Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
- Create a package for the vendor-specific tag classes:
- Navigate to WebSphereCommerceServerExtensionsLogic > src.
- Right-click the src folder; then click New > Package.
- In the Name field, type com.your_company_name.bi.taglib
- Ensure that WebSphereCommerceServerExtensionsLogic/src is specified in the Source Folder field.
- Click Finish.
- In the new package, create a new vendor-specific tag implementation class that extends from each base tag class that to use. The following list shows the tag names mapped to the base tag classes:
- Page view tag – CommonBaseTag
- Product tag – ProductBaseTag
- Shop cart tag – CartBaseTag
- Order tag – OrderBaseTag
- Registration tag – MembershipBaseTag
- Campaign URL tag – CampaignBaseTag
- Content URL tag – ContentBaseTag
Here is an example of a vendor-specific tag class that extends the CommonBaseTag class for page views:
public class MyPageViewTag extends CommonBaseTag { }
- In each vendor-specific tag class, implement the logic to send the analytics data to the external analytics system.
Here is sample code for a vendor-specific implementation of the page view tag. The external analytics vendor uses a JavaScript tagging function to capture the analytics data. For this vendor, the tag implementation class must write the JavaScript to the output stream. The vendor's JavaScript function for page view requires only the page name as a parameter:
public int doEndTag() throws JspTagException { final String METHODNAME = "doEndTag"; final String PAGEVIEW_TAG = "myPageViewTag"; if (getConfig().isEnabled(getCommandContext().getStoreId())) { try { HashMap paraMap = getParamMap(); if (paraMap != null) { StringBuffer tags = new StringBuffer(); ArrayList paramList = new ArrayList(); String pageName = (String) paraMap .get(TagConstants.PAGE_ID_KEY); String storeId = (String) paraMap .get(TagConstants.STORE_ID_KEY); Integer strId = Integer.parseInt(storeId); if (pageName == null || pageName.trim().length() == 0) { pageName = "\"'\" + document.title + \"'\""; } else { pageName ="\"" + UIUtil.toJavaScript(pageName)+ "\""; } tags.append(PAGEVIEW_TAG); tags.append("("); tags.append(pageName); tags.append(");"); // Get the analytics configuration registry instance to write any // vendor specific configuration part along with the tagging function. // The configuration will be defined in the biConfig.xml file StringBuffer out = new StringBuffer(getConfig() .getInstrumentation(strId)); out.append(getConfig().getHeader(strId)); out.append(tags.toString()); out.append(getConfig().getFooter(strId)); // Write the generated JavaScript tagging function to the // output stream pageContext.getOut().write(out.toString()); } } catch (Exception e) { if (ECTrace.traceEnabled(ECTraceIdentifiers.COMPONENT_BI)) { ECTrace.trace(ECTraceIdentifiers.COMPONENT_BI, CLASSNAME, METHODNAME, " Exception caught :" + e.getMessage()); throw new JspTagException(e.getMessage()); } } } return EVAL_PAGE; }
- Save the class file.
Next topic: Create a tag library definition file