Problem with Target Audiences and Profile Scripts | Community
Skip to main content
Level 2
March 30, 2026
Question

Problem with Target Audiences and Profile Scripts

  • March 30, 2026
  • 1 reply
  • 141 views

i need to create a profile script to identify the last visited bike pdp by a visitor in real time and using that create an audience accordingly for each bike models mutually exclusive

1 reply

Adobe Employee
March 30, 2026

You can do this with a single Target profile script that stores the last bike PDP model, then build one audience per model off that script so they’re mutually exclusive. Because profile scripts run on every Target call before audience evaluation, the audience qualifies in (near) real time as soon as the visitor hits a bike PDP (see Script profile attributes).

1. Profile script 

Create a new profile script in Target > Audiences > Profile Scripts called last_bike_model:

// PoC: store last visited bike PDP model
// Assumes bike PDPs contain "/bikes/" in the URL and send entity.id or bikeModel

if (mbox.name == "target-global-mbox" && page.url.indexOf("/bikes/") > -1) {
// Try standard product id first, then custom param as fallback
var model = mbox.param("entity.id") || mbox.param("bikeModel");

if (model) {
// Normalize a bit so audiences can match reliably
return model.toString().toLowerCase();
}
}

// No new bike PDP on this hit → keep the previous value
var existing = user.get("last_bike_model");
if (existing) {
return existing;
}

Adjust the PDP detection logic to match your site:

  • Replace "/bikes/" with your actual bike PDP path segment.
  • If you don’t have entity.id, pass a bikeModel mbox/Web SDK param and rely on that.

Target automatically exposes this script as user.last_bike_model in the audience builder (see Profile attributes).

2. Mutually exclusive audiences per bike model

Now create one audience per model, for example:

  • Audience “Last bike PDP = Panigale V4”

    • Rule: Visitor Profile → user.last_bike_model equals Panigale V4
  • Audience “Last bike PDP = S1000RR

    • Rule: Visitor Profile → user.last_bike_model equals S1000RR
  • …repeat for each model you care about.

Because the profile script holds a single “last model” value, these audiences are naturally mutually exclusive: at any given time a visitor can only qualify into one “last bike PDP” audience.

You can now use those audiences directly in XT/AB/Recs activities to trigger bike-specific personalization based on the most recently visited PDP.

AnishKoAuthor
Level 2
March 31, 2026

following is the profile script i’m using:
 

if (mbox.name == "target-global-mbox" && page.url) {
    var url = page.url.toLowerCase();

    if (url.indexOf("/motorcycles/") > -1) {
        var match = url.match(/\/motorcycles\/(?:\d{4}\/)?([^\/\?]+)\.html/);
        if (match && match[1]) {
            var model = match[1].replace('.html', '').toLowerCase();
            
            var clpPages = ["index", "A", "B", "C", "D", "E"];
            
            if (clpPages.indexOf(model) === -1) {
                return model;
            }
        }
    }

    var existing = user.get("last_bike_model");
    if (existing) {
        return existing;
    }
}


once sample audience i have created using script is follows:
 

(Visitor Profile: user.last_bike_model equals (case sensitive) xyz AND Site Pages: Current Page URL Does not contain xyz)


i try to test the working by visiting xyz bike pdp then navigate to imdex page to see whether the experience is displayed,but it is not displaying.

i need to display each bike widget in remaining bike pdp pages & index & clp pages

 

AnishKoAuthor
Level 2
March 31, 2026

@prateek2002 where to check profile.last_bike_model
response tokens are for fired activities, currently the experience are not displaying