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) || '';
}