Setting up two activities
To sort visitors into groups that each see a different activity, you must create a profile attribute. A profile attribute can sort a visitor into one of two or more groups. To set up a profile attribute called “twogroups,” create the following script:
if (!user.get('twogroups')) {
var ran_number = Math.floor(Math.random() * 100);
if (ran_number <= 49) {
return 'GroupA';
} else {
return 'GroupB';
}
}
-
if (!user.get('twogroups'))
determines whether the twogroups profile attribute is set for the current visitor. If they do, no further action is required. -
var ran_number=Math.floor(Math.random() *100)
declares a new variable called ran_number, sets its value to a random decimal between 0 and 1, then multiplies it by 100 and rounds it down to create a range of 100 (0-100), useful for specifying a percentage of visitors who see the activity. -
if (ran_number <= 49)
begins a routine that determines which group the visitor belongs to. If the number returned is 0-49, the visitor is assigned to GroupA. If the number is 50-100, the visitor is assigned to GroupB. The group determines which activity the visitor sees.
After you create the profile attribute, set up the first activity to target the desired population by requiring that the user profile parameter user.twogroups
matches the value specified for GroupA.
Set up the second campaign so the user profile parameter user.twogroups
matches the value specified for GroupB.