Profile script to return true on the third page view of a specific group of urls | Community
Skip to main content
December 17, 2024
Solved

Profile script to return true on the third page view of a specific group of urls

  • December 17, 2024
  • 1 reply
  • 1188 views

Hi Experience League,

 

I want to create a Profile script to allocate a return true on a visitor's 3rd page view of a specific group of URLs. 

e.g.

Specific page URLs = URL 1 to 10

 

Visitor 1:

Page view 1 - views URL 1

Page view 2 - views URL 4

Page view 3 - views URL 7

In this case, on their view of URL 7, the script returns true.

 

Visitor 2:

Page view 1 - views URL 3

Page view 2 - views URL 1

Page view 3 - views URL 10

In this case, on their view of URL 10, the script returns true.

 

Then I'll create an audience based off of those returning true for the profile script.

 

HAs anyone got experience creating a profile script like this before?

 

Cheers,

 

Sam

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Matthew_Ravlich_ACG

Hello @samb2024,

Below is a profile script that increments a counter each time a visitor views one of the specific pages (you can add more as needed), and returns true on the 3rd page view within that set. You can then create an audience in Adobe Target using this profile script’s return value.

Instructions:

  • Replace the targetUrls array with the URLs or patterns you want to track.
  • Run this profile script on a global mbox (e.g., target-global-mbox) so it executes on every page load.
  • On the visitor’s 3rd page view from the specified URLs, the script will return true.
  • On other pages or before the 3rd qualifying view, it will return false.

 

// Define the specific pages you want to track. // Replace the URLs below with the actual page URLs or partial matches. var targetUrls = [ "https://albertacg.com/openai-o1-adobe-analytics-sdr/", "https://albertacg.com/how-to-prepare-for-black-friday-2024/", "https://albertacg.com/creating-a-dynamic-data-feed-for-adobe-target-recommendations/", "https://albertacg.com/how-to-drive-personalized-content-with-adobe-target-recommendations/", "https://albertacg.com/mastering-ai-integration-how-to-use-chatgpt-and-adobe-target-together-for-optimal-results/", "https://albertacg.com/mastering-data-insights-how-to-use-chatgpt-and-adobe-analytics-together-for-unmatched-results/", "https://albertacg.com/seamless-migration-transitioning-from-adobe-appmeasurement-to-web-sdk-for-enhanced-analytics/", "https://albertacg.com/unlocking-the-future-of-digital-marketing-with-adobe-experience-platform-trends-and-insights/", "https://albertacg.com/adobe-analytics-vs-customer-journey-analytics-unveiling-the-best-tool-for-insightful-data/", "https://albertacg.com/10-shocking-adobe-target-features-you-arent-using-but-should/" ]; // Get the current page URL var currentPage = page.url || ""; // Retrieve the stored count of how many times the user has visited one of these URLs. var count = user.getLocal('pageViewCountForGroup') || 0; // Check if the current page is within our target set of URLs for (var i = 0; i < targetUrls.length; i++) { if (currentPage.indexOf(targetUrls[i]) > -1) { // Increment the count since the user is viewing one of our target pages count = count + 1; // Update the stored count user.setLocal('pageViewCountForGroup', count); // Break out of the loop since we found a match break; } } // Return true on the visitor's 3rd qualifying page view, otherwise false return (count === 3);

 


Once you have created the profile script and activated it, you can then create an audience that looks something like this:

 

 

Use that audience to deliver targeted experiences or offers to users who have viewed three different URLs in your specified set.

 

This approach allows you to easily track when a user hits a certain threshold of page views on a defined group of pages and then act on that information within Adobe Target.

I hope this helps.

Matthew Ravlich | Adobe Certified Expert | ACG Digital

 

1 reply

Matthew_Ravlich_ACG
Community Advisor
Matthew_Ravlich_ACGCommunity AdvisorAccepted solution
Community Advisor
December 17, 2024

Hello @samb2024,

Below is a profile script that increments a counter each time a visitor views one of the specific pages (you can add more as needed), and returns true on the 3rd page view within that set. You can then create an audience in Adobe Target using this profile script’s return value.

Instructions:

  • Replace the targetUrls array with the URLs or patterns you want to track.
  • Run this profile script on a global mbox (e.g., target-global-mbox) so it executes on every page load.
  • On the visitor’s 3rd page view from the specified URLs, the script will return true.
  • On other pages or before the 3rd qualifying view, it will return false.

 

// Define the specific pages you want to track. // Replace the URLs below with the actual page URLs or partial matches. var targetUrls = [ "https://albertacg.com/openai-o1-adobe-analytics-sdr/", "https://albertacg.com/how-to-prepare-for-black-friday-2024/", "https://albertacg.com/creating-a-dynamic-data-feed-for-adobe-target-recommendations/", "https://albertacg.com/how-to-drive-personalized-content-with-adobe-target-recommendations/", "https://albertacg.com/mastering-ai-integration-how-to-use-chatgpt-and-adobe-target-together-for-optimal-results/", "https://albertacg.com/mastering-data-insights-how-to-use-chatgpt-and-adobe-analytics-together-for-unmatched-results/", "https://albertacg.com/seamless-migration-transitioning-from-adobe-appmeasurement-to-web-sdk-for-enhanced-analytics/", "https://albertacg.com/unlocking-the-future-of-digital-marketing-with-adobe-experience-platform-trends-and-insights/", "https://albertacg.com/adobe-analytics-vs-customer-journey-analytics-unveiling-the-best-tool-for-insightful-data/", "https://albertacg.com/10-shocking-adobe-target-features-you-arent-using-but-should/" ]; // Get the current page URL var currentPage = page.url || ""; // Retrieve the stored count of how many times the user has visited one of these URLs. var count = user.getLocal('pageViewCountForGroup') || 0; // Check if the current page is within our target set of URLs for (var i = 0; i < targetUrls.length; i++) { if (currentPage.indexOf(targetUrls[i]) > -1) { // Increment the count since the user is viewing one of our target pages count = count + 1; // Update the stored count user.setLocal('pageViewCountForGroup', count); // Break out of the loop since we found a match break; } } // Return true on the visitor's 3rd qualifying page view, otherwise false return (count === 3);

 


Once you have created the profile script and activated it, you can then create an audience that looks something like this:

 

 

Use that audience to deliver targeted experiences or offers to users who have viewed three different URLs in your specified set.

 

This approach allows you to easily track when a user hits a certain threshold of page views on a defined group of pages and then act on that information within Adobe Target.

I hope this helps.

Matthew Ravlich | Adobe Certified Expert | ACG Digital

 

SamB2024Author
December 18, 2024

Thanks heaps Matthew. That is superb! We have created the script and actioned as outlined and it's firing correctly in terms of counts and returning the true value! Very exciting.

 

To take it one step further. Is there a way we can refresh the count each time they visit the website? This is so that a visitor doesn't visit 2 pages in one visit and then is hit immediately with an experience on the first page of their return visit?

Matthew_Ravlich_ACG
Community Advisor
Community Advisor
December 21, 2024

@samb2024 - You can detect a new session in Adobe Target by comparing the current sessionId (via user.sessionId) to a stored value from a previous page load. If they differ, it indicates that the visitor has started a new session. At that point, you can reset any stored counters for page views or other metrics, ensuring that each session starts fresh.