Expand my Community achievements bar.

Join us for an upcoming in-person Adobe Target Skill Builders event ~~> We're hosting these live learning opportunities to equip you with the knowledge and skills to leverage Target successfully. Learn more to see if we'll be coming to a city near you!
SOLVED

Profile Script - invalid user input

Avatar

Level 2

I'd like to create an audience of users that have previous searched 'engineering' on a search engine using profile script. The script I entered had no warnings, but when I went to click 'done', I received an 'invalid user input'. 

 

// Define the profile script function
function searchEngineAudience(profile, searchQuery) {
// Check if the user's search query contains the term "engineering"
if (searchQuery && searchQuery.toLowerCase().indexOf('engineering') !== -1) {
// Add the user to the "Engineering Search Audience" profile
profile.attributes.push('Engineering Search Audience');
}
}

// Define the audience name to be used in Adobe Target
var audienceName = 'Engineering Search Audience';

// Get the search query from the user's browser or search engine parameter ('q' for Google, Yahoo, Bing)
var searchQuery = getSearchQueryFromURL('q');

// Get the current user's profile in Adobe Target
var profile = mbox.getProfile();

// Check if the user has a profile
if (profile) {
// Call the function to check if the user has searched for "engineering"
searchEngineAudience(profile, searchQuery);

// Save the updated profile
mbox.updateProfile(profile);
} else {
// If the user does not have a profile, create a new one and add the audience attribute if applicable
profile = {
attributes: []
};

searchEngineAudience(profile, searchQuery);

// Save the new profile
mbox.createProfile(profile);
}

// Function to extract the search query from the URL parameters
function getSearchQueryFromURL(paramName) {
var urlParams = new URLSearchParams(window.location.search);
return urlParams.get(paramName) || '';
}

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @KatherineKe ,

 

Profile script does not support some javascript functions/methods. for example - window.location.search

Instead of creating a profile script you can directly pass a profile parameter from launch into target page load call and make use of that to create the audience

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

Hi @KatherineKe ,

 

Profile script does not support some javascript functions/methods. for example - window.location.search

Instead of creating a profile script you can directly pass a profile parameter from launch into target page load call and make use of that to create the audience