Expand my Community achievements bar.

12 Adobe Target Profile Scripts (Ready to be copied)

Avatar

Community Advisor

5/15/23

Summary

 

Taken from the LinkedIn Post from Kasper Andersen who has given away 12 Adobe Target Profile Scripts ready for use. With his consent, posted them here so that they can reach as many as possible who are new to Adobe Target.

Thanks much, @Kasper Andersen for the consolidated scripts.

And, if there are any discrepancies in the scripts, please feel free to 'correct' them.

 

Profile Scripts

 

Profile Script 01 - Group Search Terms: Evaluate the search strings to match the specific categories/groups (here, keywords have been grouped under 'electronics').

 

Script Name: groupSearchTerms

 

if (page.query.match(/keywords\=/) != null) {

if (page.param('keywords').match(/tv|dvd|camera|video|laptop|computer|ipod|iphone/i)) {

return 'electronics'; } }

 

Profile Script 02 - 2nd Affinity Category: The 'user.categoryAffinity' will return the top category affinity for a visitor. This will return the 2nd-best category affinity. Using the array, we can return any position, top being 0, 2nd being 1, 3rd being 2, and so on.

 

Script Name: secondCategoryAffinity

 

return user.categoryAffinity[1];

 

Profile Script 03 - Isolated Groups: Split the traffic into isolated groups so that the testing doesn't overlap.

 

Script Name: twoGroups

 

if (!user.get('twoGroups')) {
var random_number = Math.floor(Math.random()*99);
if (random_number <= 49) {return 'GroupA';} else {return 'GroupB';}
}

 

Can be easily adapted to as many isolated groups i.e. 3, 4, and so on.

 

Profile Script 04 - Visit Number: To keep track of the visits/sessions for a unique visitor.

 

Script Name: visitNumber

 

if(user.sessionId!=user.getLocal('lastSessionId')) {
user.setLocal('lastSessionId', user.sessionId);
return (user.get('visitNumber') || 0) + 1;
}

 

Profile Script 05 - Purchase Frequency: Counter every time the 'orderConfirmPage' MBOX had an impression, which is typically on the Order Confirm Page. MBOX name can be anything or it can also be constricted based on the URL or parameter if Global MBOX is used.

 

Script Name: purchaseFrequency

 

if(mbox.name == 'OrderConfirmPage') {
return (user.get('purchaseFrequency') || 0) + 1;
}

 

Profile Script 06 - Purchase Amount: Sums up the total revenue per visitor over time.

 

Script Name: monetaryValue

 

var monetaryValue = user.get('monetaryValue') | 0;

if(mbox.name == 'OrderConfirmPage') {

return monetaryValue + parseInt(mbox.param('orderTotal'));
}

 

Profile Script 07 - Campaign Visitors: Validate the campaign parameter for the campaigns and group the visitors accordingly (here, cid and can be changed according to business requirements) .

 

Script Name: campaignVisitor

 

if (page.query.indexOf("cid") > -1) {return 'true';}

else {if (!user.get("campaignVisitor")) {return 'false';} }

 

The script can also be easily enhanced to group different campaigns i.e. 'cid=spring' to 'campaignSpring', 'cid=summer' to 'campaignSummar' etc.

 

Profile Script 08 - Visited a URL: Set the value to 'true' based on the URL of the page.

 

Script Name: urlVisit

 

if (page.query.indexOf("URL_TO_MATCH") > -1) {return 'true';}

else {if (!user.get("urlVisit")) {return 'false';} }

 

Profile Script 09 - Read a cookie: Read a cookie.

 

Script Name: readCookie

 

var cookies = user.header('cookie');

if (cookies.indexOf('YOUR_COOKIE_VAL') >= 0) {return "true";}

else {return "false";} }

 

Profile Script 10 - Visitors Landing Page URL: Stores the visitor's Landing Page URL, since the built-in landing.url profile gets wiped when crossing subdomains.

 

Script Name: landingPageURL

 

if (user.sessionId != user.getLocal("sessionId")) {

user.setLocal("sessionId", user.sessionId);

return page.url; }

 

Profile Script 11 - Customer Attributes in Profile Scripts: Customer Attributes can be referenced in profile scripts using the below format.

 

Script Name: customerAttributes

 

crs.get("<DATASOURCE NAME>.<ATTRIBUTE NAME>");

 

Profile Script 12 - IP Address: The IP Address associated with the profiles can be retrieved.

 

Script Name: ipAddress

 

user.header(‘x-cluster-client-ip’);

 

Final Thoughts

 

After the exclusive utilization of Adobe Launch (Data Collection Tags), I have stopped using profile scripts to an extent due to their limitations in debugging, scalability, JavaScript/JQuery acceptance, and so on. However, having a piece of knowledge about profile scripts and using them according to the use case will add value as always.