Introduction
This document describes the steps needed to get Personalization and Profiling to work using Content Delivery Personalization and Profiling (formerly known as the Web Application Integration module or WAI). It assumes that you have read the sections about the Personalization and Profiling in the Installation Guide. The process is described globally in the Tridion R5 Installation Guide. It is described in more detail in the Content Delivery Installation Guide and the WAI Installation Guide. This article lists some of the pitfalls you can fall into before you get personalization up and running.
Prerequisites
The following things need to be done to get Personalization and Profiling to work:
1. Install Personalization and Profiling
2. Configure the Presentation Server
3. Modify Tridion templates
4. Create Target Groups and Tracked Categories in Tridion
5. Associate Target Groups with Component Presentations in Tridion
6. Publish the Page
1. Installing Personalization and Profiling
To install Personalization and Profiling on the Content Delivery environment see the Tridion R5 Installation Guide.
2. Configuring the Presentation Server
Basically follow the procedure described in the Installation Guide.
Make sure not to forget to configure the Personalization and Profiling bindings in the cd_broker_conf.xml (all the Binding elements should go inside the Bindings element). Make sure the web site is included in the hosts section of the cd_wai_conf.xml. If you try to access Personalization and Profiling code in a JSP, ASP or ASPX page, and the host is not listed in the cd_wai_conf.xml, the page is not rendered properly.
3. Modifying Tridion templates
First of all, open all page templates that publish JSP, ASP, ASPX pages, and include [% ActivateTracking True %]. This calls a function from the TCMScriptAssistant class that outputs the correct JSP, ASP, ASPX code needed to do tracking and personalization.
Make sure the target language of the publication target is set to JSP or ASP.
ActivateTracking writes out a lot of scripting code, but it leaves out one important line. So go to the bottom of the page template, and add <% waiPage.setTrackingKeys(trackingKeys) %>
Note: if you want to activate tracking and personalization for all types of component presentations, you must make some additional changes. See the notes bellow for details.
4. Create Target Groups and Tracked Categories in Tridion
If you create target groups based on customer characteristics, use the following approach:
- Create a profile.jsp / profile.asp page with a web form (see the attached Profile.jsp for details).
-
When the form is submitted, use the Personalization and Profiling API to set customer characteristics. Sample code can be found below.
-
Write down the names of the customer characteristics that are set in the profile (e.g. Name, Age, Sex, Hobbies, etc.)
-
Use these names in the target group definition.
Target groups based on tracking keys require no special action.
Open each Component Template that should lead to an increase of tracking keys, and make sure all relevant categories are tracked.
5. Associate Target Groups with Component Presentations in Tridion
- Open a page and go to the component presentations tab.
- Select a component presentation that you want to personalize, and click on the Target Groups tag in the right-hand frame.
- Select the target group(s) that you want to include or exclude.
6. Publish the pages
No special action required
7. Sample code: Component Template
In the source code below, you can find some sample template code. Be careful: the logic for retrieving personalized component presentations is not fully implemented. If a target group is EXCLUDED, the code will fail. However, this code is a good starter.
[%
Function IncrementTrackingKeys(Page)
' iterate over all component presentations, find out the tracked categories, get the values for the current component and construct the WAI code needed to increment the keys
' this is necessary if you want to track non-jsp/asp or static component presentations
Dim objCP strTrackingKeyCalls, objField, objCategories, objCategory, strTrackedCategories
strTrackingKeyCalls = ""
For Each objCP in Page.ComponentPresentations
Set objCategories = objCP.ComponentTemplate.TrackingCategories
For Each objCategory In objCategories
strTrackedCategories = strTrackedCategories & objCategory.Title & ","
Next
For Each objField In objCP.Component.Fields
If objField.FieldType = 9 Then ' 9 = keyword list
Set objCategory = objField.Definition.Category
If InStr (strTrackedCategories, objCategory.Title & ",") > 0 Then
For i = 1 To objField.Value.Count
strTrackingKeyCalls = strTrackingKeyCalls & "trackingKeys.incrementKey(""" & objField.Value(i) & """,""" & objCP.Component.ID & """);" & vbCrLf
Next
End If
End If
Next
Next
Set objCP = Nothing
Set objCategories = Nothing
Set objCategory = Nothing
Set objField = Nothing
IncrementTrackingKeys = strTrackingKeyCalls
End Function
Function GetPersonalizedComponentPresentation(strContent, objCP)
Dim i, arrTG, objTGConditions, objTG, domConditions, domCondition, strCondition, strKey, strOperator, strValue
Set domConditions = GetNewDomDocument()
Set objTGConditions = objCP.TargetGroupConditions
For i = 1 To objTGConditions.Count
arrTG = objTGConditions(i)
Set objTG = arrTG(0)
domConditions.loadXml objTG.Conditions
For Each domCondition In domConditions.SelectNodes("/tcm:Conditions/tcm:KeywordCondition")
strKey = domCondition.selectSingleNode("tcm:Keyword").getAttribute("xlink:title")
strOperator = domCondition.getAttribute ("Operator")
strValue = domCondition.selectSingleNode("tcm:Value").Text
If domCondition.getAttribute("Type") = "Include" Then
If strCondition <> "" Then
strCondition = strCondition & " && "
End If
strCondition = strCondition & "(trackingKeys.getKey(""" & strKey & """) " & strOperator & " " & strValue & ")"
End If
Next
Next
If strCondition <> "" Then
GetPersonalizedComponentPresentation = "<span class=""personalized""><% if (" & strCondition & ") { %>" & strContent & "<% } %></span>"
Else
GetPersonalizedComponentPresentation = strContent
End If
End Function
'activate profiling and personalization
ActivateTracking True
' write out tracking key calls
WriteOut IncrementTrackingKeys(Page)
%]
<html>
<body>
[%
Dim objCP
For Each objCP In Page.ComponentPresentations
writeOut GetPersonalizedComponentPresentation(objCP.Content, objCP)
Next
Set objCP = Nothing
%]
</body>
</html>
' add extra line of WAI code that is missing from the code generated by ActivateTracking
<% waiPage.setTrackingKeys(trackingKeys) %>
8. Sample code: Profile.jsp
<%@ page import="com.tridion.web.jsp.JSPPage,
com.tridion.personalization.TrackingKeys,
com.tridion.personalization.CustomerCharacteristics,
com.tridion.tracking.dispatcher.TrackDispatcher,
com.tridion.user.User"%>
<%
// create a wai page and use it to construct a customer characteristics object
JSPPage waiPage = new JSPPage(pageContext, "tcm:7-333-64");
CustomerCharacteristics customerCharacteristics = new CustomerCharacteristics(waiPage.getUser());
// set up some variables
boolean changed = false;
String message = "";
String name = "";
String age = "";
try {
// see if a 'name' was posted
if (request.getParameter("name")!=null) {
name = request.getParameter("name");
customerCharacteristics.setValue("name", name);
changed = true;
}
// see if an 'age' was posted
if (request.getParameter("age")!=null) {
age = request.getParameter("age");
customerCharacteristics.setValue("age", age);
}
// if anything was changed, set a message and update the customer characteristics
if (changed) {
message = "your profile has been updated<br/>"
customerCharacteristics.executeUpdate();
}
} catch (Exception e) {
e.printStackTrace();
}
%>
<b><%=message%></b>
<form action="<%=request.getRequestURL()%>" method="get">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="name" size="25" value="<%=name%>"/></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age" size="25" value="<%=age%>"/></td>
</tr>
</table>
<input type="submit" value="update profile"/>
</form>
Notes
Using Personalization and Profiling with all types of component presentation
Out of the box both personalization and profiling is only enabled for component presentations that:
- are published as a dynamic component
- are allowed on the page using dynamic assembly
- have asp vbscript, asp jscript or jsp as output format
If a component presentation does not comply with these conditions, the code to increment the tracking keys is NOT generated if you call ActivateTracking in your template.
This is an unfortunate limitation. If you look at the WAI code that is generated from the TCM, there is no reason why it should not work with static component presentations as well.
Using the TOM it is fairly easy to create template code that outputs WAI code directly. You can use this in addition to the 'ActivateTracking' call, that is still helpful because it creates (almost) all of the generic WAI code (like instantiating a wai-page object, a user, a tracking keys object, etc).