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
  • 61 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

 

Adobe Employee
March 31, 2026

A few things in the script and audience setup explain why the experience isn't showing on index/CLP pages.

 1. Script logic

You're lowercasing the model:

```js
var model = match[1].replace('.html', '').toLowerCase();
```

but the CLP list is mixed case:

```js
var clpPages = ["index", "A", "B", "C", "D", "E"];
```

For `/motorcycles/A.html`, `model` becomes `"a"`, which is not in that array, so the script treats it as a PDP and overwrites `last_bike_model` with `"a"` instead of preserving the last real bike PDP.

A safer version is to normalize everything to lowercase and only update on non‑CLP pages:

```js
// Profile script name: last_bike_model

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].toLowerCase();

            // CLP / index slugs (all lowercase)
            var clpPages = ["index", "a", "b", "c", "d", "e"];

            // Only treat as a PDP if not CLP/index
            if (clpPages.indexOf(model) === -1) {
                return model; // last_bike_model
            }
        }
    }

    // Not on a PDP (or on CLP/index) → keep previous value
    var existing = user.get("last_bike_model");
    if (existing) {
        return existing;
    }
}

return user.get("last_bike_model");
```

This way, PDPs update `last_bike_model`; index/CLP reuse the last value instead of overwriting it.

2. Audience definition

The audience is:

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

The script stores the model in lowercase, so the profile value will be `"xyz"`. With a case-sensitive operator, any value like `XYZ` or `Xyz` in the audience will not match.

I'd either:

- Use `xyz` (lowercase) as the audience value, or  
- Change to a case‑insensitive equals operator.

If the requirement is "show the xyz widget on all other bike PDPs + index + CLP, but not on the xyz PDP itself", a more precise audience for `xyz` is:

- Visitor Profile: `last_bike_model` equals `xyz` (preferably case-insensitive), and  
- Current Page URL contains `/motorcycles/`, and  
- Current Page URL does not contain `/motorcycles/xyz.html`

That keeps the widget off its own PDP but allows it on all remaining motorcycle pages where the last visited PDP is `xyz`.

3. Suggested check

To confirm the behavior end‑to‑end, it's worth using Target QA/response tokens to verify:

- After visiting the `xyz` bike PDP, `profile.last_bike_model` is `xyz`.  
- After navigating to index/CLP, `profile.last_bike_model` still shows `xyz`.

You can achieve 

If that's true with the updated script and audience, the widgets should be mutually exclusive per model and visible on the remaining PDPs + index + CLP as intended.