Tutorials > Management Center > Track and displaying the most viewed recipes
Create a new command to capture the recipe view statistics
In this lesson, we will implement the task command which was specified in the callCmdOnMatch parameter in the Behavior Rule XML definition. This task command is called to perform custom processing of the event. The specified task command must implement BehaviorRuleTaskCmd.
Procedure
- Start WebSphere Commerce Developer.
- Open the Enterprise Explorer view from the Java EE perspective.
- In the Enterprise Explorer view, right-click the WebSphereCommerceServerExtensionsLogic project
- Click New > Package, enter com.mycompany.commerce.project.marketing as the package name and click Finish.
- Expand WebSphereCommerceServerExtensionsLogic > src.
- Right-click the com.mycompany.commerce.project.marketing package and select Import. Expand General and select File system.
- Click Next, then click Browse and navigate to RecipeTopBrowsedSource\WebSphereCommerceServerExtensionsLogic\src\com\mycompany\commerce\project\marketing, where RecipeTopBrowsedSource is the location where you extracted the tutorial sample source code. Select the RecipeTopViewedCmd.java and RecipeTopViewedCmdImpl.java files. Click Finish to import the files.
- Open RecipeTopViewedCmd.java. Note the following code:
package com.mycompany.commerce.project.marketing; import com.ibm.commerce.marketing.commands.elements.BehaviorRuleTaskCmd; public interface RecipeTopViewedCmd extends BehaviorRuleTaskCmd { String defaultCommandClassName = "com.mycompany.commerce.project.marketing.RecipeTopViewedCmdImpl"; }
This task command must implement BehaviorRuleTaskCmd. The defaultCommandClassName field specifies the implement class of this task command interface.
- Open RecipeTopViewedCmdImpl.Java. Note the following code:
package com.mycompany.commerce.project.marketing; import java.util.Map; import com.ibm.commerce.marketing.commands.elements.BehaviorRuleTaskCmdImpl; import com.ibm.commerce.marketing.runtime.engine.MarketingEngineCache; public class RecipeTopViewedCmdImpl extends BehaviorRuleTaskCmdImpl implements RecipeTopViewedCmd { @Override public void performExecute() { Map param = getTriggerParameters(); Short RANKING_MY_BUSINESS_OBJECT = new Short("2"); Long objectId = Long.parseLong(param.get("project").toString()); String groupId = param.get("collectionId").toString(); Short objectType = RANKING_MY_BUSINESS_OBJECT; Integer storeId = Integer.parseInt(param.get("storeId").toString()); Integer elementId = getUserBehaviorRule().getElementId(); //Amount is 1 when customer is browsing Double amount = new Double("1"); MarketingEngineCache.singleton().putRankingStatistic(objectId,groupId,objectType,storeId,elementId,amount); } }
In the implementation, the performExecute() method is invoked when the event specified in the behavior rule definition occurs. You must put the recipe information into the statistic table by calling MarketingEngineCache.singleton().putRankingStatistic().
The RecipeTopViewedCmdImpl class is the implementation of RecipeTopViewedCmd interface. It is called when a customer browses a recipe under the specified recipe collection associated with a Display Recipe Top Browsed campaign element. It calls the MarketingEngineCache.singleton().putRankingStatistic method to persist the data to the DMRANKINGSTAT database table. Subsequently, the GenerateRankingPolicyCmd command uses these statistics to generate the Top Browsed ranking list.
The putRankingStatistic method sets up a ranking statistic entry to be persisted to the database. The entry is placed in a queue, and is persisted when the Process MarketingTrigger SaveStatistics command is called, or when the queue size reaches the size specified in the userBehaviorBatchUpdateCacheSize parameter in the wc-admin-component.xml configuration file:
- objectId
- The unique ID representing the object. For recipe most browsed, it is the recipe ID.
- groupId
- The group ID associated with the object. For recipe most browsed, it is the recipe collection ID.
- objectType
- The type of the statistic. A value of 0 represents a purchased product, and a value of 1 represents a browsed product. In this case, you are collecting data for a new object type, browsed recipes, and assigning it a new identifier, such as 2.
GenerateRankingPolicyCmd can generate the recipe ranking data according to the new identifier. GenerateRankingPolicyCmd is explained in more detail in the next lesson.
- storeId
- The store ID.
- elementId
- The ID of the ranking campaign element.
- amount
- The amount related to the statistic. For example, the number of times browsed, or the number of times purchased. If the customer's action is purchased, we must get specific numbers from the storefront. In this tutorial, the action is simply browsed, so we specify it as 1.
Related concepts
Rank list framework for marketing actions