Expand my Community achievements bar.

SOLVED

Creating a Profile Script to Return True After visiting specific pages using the page name parameter

Avatar

Level 1

Hi there Adobe Target Experts,

 

I'm looking to create a Profile Script that will return a value of 'true' if a visitor has visited any pages from a group of specific page names.

 

Has anyone done this before at all?

 

Cheers.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @SamB2024 , 

I am assuming you're using the at.js configuration approach of Adobe Target. I think the code given below will work for you.

 

var flag=user.get('YourProfileScriptName')||'False';
var Pages = ['HomePage', 'CategoryPage', 'ProductPage']; 
if (Pages.includes(mbox.param('page_name'))) { 
    flag = 'True'; 
}
return flag;

 

 
Please let me know in case you're using a webSdk approach, I'll share an updated code then.

Hope it helps. 

Best Regards, 
Vaibhav Mathur

Views

 

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

Hi @SamB2024 , 

I am assuming you're using the at.js configuration approach of Adobe Target. I think the code given below will work for you.

 

var flag=user.get('YourProfileScriptName')||'False';
var Pages = ['HomePage', 'CategoryPage', 'ProductPage']; 
if (Pages.includes(mbox.param('page_name'))) { 
    flag = 'True'; 
}
return flag;

 

 
Please let me know in case you're using a webSdk approach, I'll share an updated code then.

Hope it helps. 

Best Regards, 
Vaibhav Mathur

Views

 

Avatar

Community Advisor and Adobe Champion

I think we need to add

user.set('YourProfileScriptName','True') as well in Profile snippet above to keep profile script value intact.

Avatar

Community Advisor

Hi @abhinavpuri , 

Thanks for your response.

We can add user.set('YourProfileScriptName', 'True') additionally here, but it works even if we don’t set it explicitly. .

When a profile script returns a value, that value is automatically stored in the corresponding profile attribute for the user.

In this case, once the script returns 'True', it is saved in the profile attribute 'YourProfileScriptName' for that user, ensuring persistence across visits. The next time the script runs, user.get('YourProfileScriptName') will retrieve the saved value.

Hope it helps. 

Best Regards, 
Vaibhav Mathur

Avatar

Level 10

but how to pass first this parameters to global mbox using at.js?

var flag=user.get('YourProfileScriptName')||'False';
var Pages = ['HomePage', 'CategoryPage', 'ProductPage'];
if (Pages.includes(mbox.param('page_name'))) {
flag = 'True';
}
return flag;

 

I assume that these parameters needs to be passed first to at.js in order to filter them in the future?

Avatar

Level 2

Hi @Michael_Soprano ,

 

That is correct understanding, In above example profile script will look for mbox.page_name parameter in order to set flag as expected.

 

The mbox.page_name paramter will need to be passed from client side (using at.js)

Avatar

Level 10

It should be send like this?

 

 

  <script>
    targetPageParams = function() {
      return {
        // Property token
        "at_property": "5a0fd9bb-67de-4b5a-0fd7-9cc09f50a58d",
        // Mbox parameters
        "pageName": "product detail"
      };
    };
  </script>

 

 

 

Do I have to put in the bottom something like this?

    <script src="mbox.js" type="text/javascript"></script>

 

This documentation is spectatuliary poor ......

https://experienceleague.adobe.com/en/docs/target-dev/developer/client-side/global-mbox/pass-paramet...

Avatar

Community Advisor and Adobe Champion

Hi @Michael_Soprano ,

The syntax for mbox parmater as shared below is correct -

  <script>
    targetPageParams = function() {
      return {
        // Property token
        "at_property": "5a0fd9bb-67de-4b5a-0fd7-9cc09f50a58d",
        // Mbox parameters
        "pageName": "product detail"
      };
    };
  </script>

 

For the second part of adding (Implementing) Adobe Target on Webpage - Assuming you have downloaded "at.js" and have included in same directory as your web-page the self hosted apporach below should work. (If mbox.js is in the same directory as your HTML file)

 <script src="mbox.js" type="text/javascript"></script>