For each event that you must capture analytics data for,
create a vendor-specific tag class that extends the base tag class.
For example, if you want 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.
About this task
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 your vendor-specific tag classes:
- Navigate to .
- Right-click the src folder; then
click .
- 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 you want to use.
The following list shows the tag names mapped to the base tag classes:
- Page view tag – com.ibm.commerce.bi.taglib.CommonBaseTag
- Product tag – com.ibm.commerce.bi.taglib.ProductBaseTag
- Shopping cart tag – com.ibm.commerce.bi.taglib.CartBaseTag
- Order tag – com.ibm.commerce.bi.taglib.OrderBaseTag
- Registration tag – com.ibm.commerce.bi.taglib.MembershipBaseTag
- Campaign URL tag – com.ibm.commerce.bi.taglib.CampaignBaseTag
- Content URL tag – com.ibm.commerce.bi.taglib.BaseTag
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.