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

      10 Top Node.js Development Companies for Enterprise-Scale Projects (2025-2026 Ranked & Reviewed)

      July 4, 2025

      12 Must-Know Cost Factors When Hiring Node.js Developers for Your Enterprise

      July 4, 2025

      Mirantis reveals Lens Prism, an AI copilot for operating Kubernetes clusters

      July 3, 2025

      Avoid these common platform engineering mistakes

      July 3, 2025

      RIP, Perfect Dark — Xbox leadership canceled my most-anticipated game, and the developers deserved better

      July 6, 2025

      I keep seeing people at events taking notes on E-Ink tablets — so I tried one to see what all the fuss is about

      July 6, 2025

      “A fantastic device for creative users” — this $550 discount on ASUS’s 3K OLED creator laptop disappears before Prime Day

      July 5, 2025

      Distribution Release: Rhino Linux 2025.3

      July 5, 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

      Token System using PHP and MySQL

      July 6, 2025
      Recent

      Token System using PHP and MySQL

      July 6, 2025

      Create React UI component with uncontrollable

      July 6, 2025

      Flaget – new small 5kB CLI argument parser

      July 5, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      RIP, Perfect Dark — Xbox leadership canceled my most-anticipated game, and the developers deserved better

      July 6, 2025
      Recent

      RIP, Perfect Dark — Xbox leadership canceled my most-anticipated game, and the developers deserved better

      July 6, 2025

      I keep seeing people at events taking notes on E-Ink tablets — so I tried one to see what all the fuss is about

      July 6, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 27/2025

      July 6, 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

    Artificial Intelligence

    Experiment with Gemini 2.0 Flash native image generation

    July 6, 2025
    Artificial Intelligence

    Introducing Gemma 3

    July 6, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Design system annotations, part 2: Advanced methods of annotating components

    News & Updates

    This hidden Chrome feature is my secret productivity trick – here’s my favorite way to use it

    News & Updates

    CVE-2025-4526 – Dígitro NGC Explorer Password Field Masking Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-3319 – IBM Spectrum Protect Server Authentication Bypass Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Development

    AWS Default IAM Roles Found to Enable Lateral Movement and Cross-Service Exploitation

    May 20, 2025

    Cybersecurity researchers have discovered risky default identity and access management (IAM) roles impacting Amazon Web…

    HCL Commerce V9.1 – The Power of the Next.js Ruby Storefront

    May 8, 2025

    Polar adds personalized fitness subscription to its smartwatch app, like Garmin’s

    April 10, 2025

    CVE-2025-37779 – “ERofs Linux Kernel Folio UAF Vulnerability”

    May 1, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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