Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 21, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 21, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 21, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 21, 2025

      Google DeepMind’s CEO says Gemini’s upgrades could lead to AGI — but he still thinks society isn’t “ready for it”

      May 21, 2025

      Windows 11 is getting AI Actions in File Explorer — here’s how to try them right now

      May 21, 2025

      Is The Alters on Game Pass?

      May 21, 2025

      I asked Copilot’s AI to predict the outcome of the Europa League final, and now I’m just sad

      May 21, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Celebrating GAAD by Committing to Universal Design: Equitable Use

      May 21, 2025
      Recent

      Celebrating GAAD by Committing to Universal Design: Equitable Use

      May 21, 2025

      GAAD and Universal Design in Healthcare – A Deeper Look

      May 21, 2025

      GAAD and Universal Design in Pharmacy – A Deeper Look

      May 21, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Google DeepMind’s CEO says Gemini’s upgrades could lead to AGI — but he still thinks society isn’t “ready for it”

      May 21, 2025
      Recent

      Google DeepMind’s CEO says Gemini’s upgrades could lead to AGI — but he still thinks society isn’t “ready for it”

      May 21, 2025

      Windows 11 is getting AI Actions in File Explorer — here’s how to try them right now

      May 21, 2025

      Is The Alters on Game Pass?

      May 21, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Sitecore Personalize: Advanced Page Targeting

    Sitecore Personalize: Advanced Page Targeting

    May 21, 2025

    In my previous blog https://blogs.perficient.com/2024/07/01/sitecore-personalize-close-event-logic/, I shared a method for using cookies to enable the user to dismiss an alert banner.  This process involved writing the cookie when the user clicks the close icon and checking for the cookie when the experience is displayed.  This approach worked well because the entirety of the javascript code could be stored in the web template.  This ensures the code to check for the cookie can’t be missed or forgotten when the template was used.  Unfortunately, this had an unintended side effect.  Personalize still executed the experience and counted it in the analytics and performance metrics even though the javascript never added the elements to the screen.  This lead to overinflated metrics and the inability to use the data for accurate forecasting.  This problem can be overcome with advanced page targeting.

    Advanced Page Targeting

    Advanced page targeting allows you to run client side javascript to decide if an experience should execute.  Since the javascript runs client side, you can read the url and query string parameters, you can access the console to log messages, you can access the document object to query selectors on the page, and of course read cookies.  Advanced page targeting javascript runs after the page loads, but before the experience loads which allows us to prevent the experience from executing and overinflating analytics.  Be sure to keep your script as lean and performant as possible to reduce the possible screen flicker of loading the experience after the page has loaded.

    Checking Cookies with Advanced Page Targeting

    In order to use advanced page targeting, you must select the “specific pages” setting under “Page Targeting”.

    Pers Apt Enable

    Enable page targeting on specific pages to enable advanced page targeting

    In the flyout window for page targeting, add any filters for pages where you want the experience to display.  If you want the experience to display on all pages, simply use the contains “/” rule.  In the advanced targeting section, click the “add script” button.

    Pers Apt Configure

    Configure advanced page targeting

    In the advanced targeting code editor, enter the following code.

    (function() {
       // console.log(new Error().stack);
    
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = cookies[i].trim();
            if (cookie.indexOf('pers-' + selectedVariant.ref + '=clicked') === 0) {
                return false;
            }
        }
    
        targetingPassed();
    })();

     

    In my previous blog, I created the cookie using the variant.ref as part of the cookie name.  This adds the guid of the current experience id to the name of the cookie making it unique even when the web template was reused.  Advanced targeting does not have access to the variant.ref property.  So it doesn’t work with the close event logic idea I came up with before.  However, there is a selectedVariant.ref property that you can use.  Using selectedVariant.ref works for both experiences and experiments as it can dynamically get the correct guid of the current variant at run time.

    When personalize evaluates this block of javascript code, it only continues processing the flow of execution for the experience if the “targetingPassed()” function is called.  If you want to stop the flow of execution, return false.  In our case, we want to stop the flow of execution if the cookie is found.  Otherwise we can call the targetingPassed() function and allow the experience to display to the user.

    Once you have added advanced targeting javascript, you can edit the script by clicking the pencil icon.

    Pers Apt Edit

    Edit advanced page targeting settings

     

    Pers Apt Editscript

    Edit advanced page targeting script

    Things to Know About Advanced Page Targeting

    As mentioned, this solution solves the problem of overinflating analytics.  The downside is the advanced page targeting settings and code cannot be saved with the web template.  So the marketer or content author must remember to enable this setting and add the javascript code to the experience.  If the code is not added, the user will be able to close the experience, but it will display on the next page load since the code to check for the cookie is missing.  One other thing to note, if you change your page targeting settings back to “all pages”, the advanced targeting script is deleted from the experience.  In both cases, ensure that it is easy for content authors to find and reuse.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleReimagining Find Care: How AI is Transforming the Digital Healthcare Experience [Webinar]
    Next Article Perficient Named 2025 Gold Globee® Winner for Best Artificial Intelligence Service Provider

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 22, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-9544 – MapSVG WordPress Stored Cross-Site Scripting Vulnerability

    May 22, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Stanikmas, Lynn. (2024). Angular Studies | Advanced Components. GitHub.

    Development

    CVE-2025-46433 – JetBrains TeamCity Path Traversal Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    New UEFI Secure Boot Vulnerability Could Allow Attackers to Load Malicious Bootkits

    Development

    Scalable Reinforcement Learning with Verifiable Rewards: Generative Reward Modeling for Unstructured, Multi-Domain Tasks

    Machine Learning

    Highlights

    Development

    A Comparative Look at Cybersecurity Regulations Across the META Region

    June 2, 2024

    The META region (Middle-East, Turkey, and Africa) is experiencing a digital surge, with interconnectedness weaving…

    5 Best Salary Benchmarking Tools for Competitive Pay Analysis

    November 11, 2024

    Microsoft backtracks DALL-E 3 AI’s ‘PR16’ upgrade after backlash as Grok gets an Unhinged Mode: “Bing has become useless”

    January 9, 2025

    DOOM: The Dark Ages Collector’s Edition is now available to buy—here’s what you get in the Standard, Premium, and Collector’s editions

    January 24, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.