Need to show banner/teaser once per session using Profile script in Adobe Target. | Community
Skip to main content
Level 2
October 29, 2024
Solved

Need to show banner/teaser once per session using Profile script in Adobe Target.

  • October 29, 2024
  • 1 reply
  • 1976 views

Hi Team,

 

I have a requirement to display a banner/teaser once per session using a Profile Script in Adobe Target. This functionality is needed for multiple use cases.

Could you please provide guidance on how to implement this across the various use cases?

Thank you!

 

Best regards,
Devakrishna R S V

Best answer by kandersen-1

@devakrishnara2  Sorry, try this instead - i was a bit too quick on the previous one:

// Profile script to control session-only display of a banner if (user.sessionId != user.getLocal('sessionIdBannerShown')) { // First time in this session, allow the banner to display user.setLocal('sessionIdBannerShown', user.sessionId); return false; // Indicates banner can be shown } else { // Banner has been shown already in this session return true; // Indicates banner should not be shown again }


Here's a quick demo of it in action: https://www.loom.com/share/db450c90641c4e8fa940b535b28a87f1?sid=32e84a1b-1beb-498e-a929-b3c33e06ed30 

1 reply

kandersen-1
Community Advisor
Community Advisor
October 29, 2024

Hi @devakrishnara2 

 

I think it should something like this:

// Profile script to control session-only display of a banner if (user.sessionId !== profile.sessionIdBannerShown) { // First time in this session, allow the banner to display profile.sessionIdBannerShown = user.sessionId; return false; // Indicates banner can be shown } else { // Banner has been shown already in this session return true; // Indicates banner should not be shown again }

Please note, that i haven't tested it. 

In order to implement it, step 1) is to create the profile script. Step 2) is to create an audience which looks at the profile script (find it under visitor profile) and set it to contain/equal false. Step 3) apply this audience to your activity.

An alternative approach could be controlling it inside the experience by using a script and sessionStorage. You would apply this as custom code in the experience and you would then have to inject the banner as part of the script:

// Custom script to run in Adobe Target if (!sessionStorage.getItem("bannerShown")) { // Display the banner and set a flag document.getElementById("your-banner-id").style.display = "block"; sessionStorage.setItem("bannerShown", "true"); } else { // Hide the banner if already shown document.getElementById("your-banner-id").style.display = "none"; }

 

Probably not optimal as you won't be able to exclude on audience level, but wanted to mention it anyway.

Level 2
October 30, 2024

Thank you @kandersen-1 ,

 

I tried the above code but it's not working any other suggestions, for implementing the scenario using profile scripts?

 

Note: we have integrated Target using WebSDK.

 

Regards,

Devakrishna R S V

 

kandersen-1
Community Advisor
Community Advisor
October 20, 2025

HI @kandersen-1 ,

I had a follow-up question about how to modify it.

I need this profile script to activate only when a specific banner actually appears on the page, and ensure that banner shows only once per session (not again when the user refreshes or navigates within the same session, but available again next session).

Could you please advise- Whether any change is required within this code itself?


Hi @gauravdu1 

In order to do that, you need to know the activity/experience id/name, which you can get through reponse tokens. However, since profile scripts are running prior to the activity you won't be able to do this without some sort of work-around.

An option could be that you include a Target request inside the activity where you pass details to Target which you can reference in your profile script.

Another option could be to have a custom script in your activity set a cookie set to expire on visit and then create a segment based on the cookie to ensure the activity isn't shown until next visit.

However, the solution really also depends on your reporting needs, because as long as you have logic in side your activity, then even if nothing is shown, it will still count visitors. So this is something to keep in mind.