{"id":112488,"date":"2023-07-10T11:41:55","date_gmt":"2023-07-10T15:41:55","guid":{"rendered":"https:\/\/optinmonster.com\/?post_type=optinmonster_docs&#038;p=111546"},"modified":"2025-08-21T04:07:34","modified_gmt":"2025-08-21T08:07:34","slug":"how-to-target-visitors-based-on-browser-cookies","status":"publish","type":"optinmonster_docs","link":"https:\/\/optinmonster.com\/docs\/how-to-target-visitors-based-on-browser-cookies\/","title":{"rendered":"How to Target Visitors Based on Browser Cookies"},"content":{"rendered":"\n<p>OptinMonster makes it easy to hide or show campaigns based on the cookies in your visitor&#8217;s browser.<\/p>\n\n\n\n<p>In this article, you&#8217;ll learn how to use OptinMonster&#8217;s Display Rules to hide or show a campaign based on cookies.<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column alert alert-info is-layout-flow wp-block-column-is-layout-flow\">\n<p><strong><em>Before you start<\/em><\/strong>, this feature is available with a <a href=\"https:\/\/optinmonster.com\/pricing\" target=\"_blank\" rel=\"noopener\" title=\"Pro and higher subscription\">Pro and higher subscription<\/a>.<\/p>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Configure Cookie Rule<\/h2>\n\n\n\n<p>When you&nbsp;<a href=\"https:\/\/optinmonster.com\/docs\/creating-your-first-optin\/\" target=\"_blank\" rel=\"noopener\" title=\"\">create a campaign<\/a> in OptinMonster you can configure it to be shown or hidden based on a visitor&#8217;s cookie.<\/p>\n\n\n\n<p>To configure the cookie rule, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Navigate to the <strong>Display Rules<\/strong> view in the campaign builder.<br><img decoding=\"async\" width=\"800\" height=\"560\" class=\"alignnone size-full wp-image-180093\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/06\/display-rules-view.jpg\" alt=\"Navigate to the Display Rules in the OptinMonster campaign builder.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/06\/display-rules-view.jpg 800w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/06\/display-rules-view-300x210.jpg 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/06\/display-rules-view-768x538.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li>\n\n\n\n<li>Next, when adding or editing a rule select <strong>Who (Personalization)<\/strong> from the left-hand list and select the <strong>Cookie Targeting<\/strong> option.<br><img decoding=\"async\" width=\"800\" height=\"564\" class=\"alignnone size-full wp-image-180392\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule.jpg\" alt=\"Cookie targeting in OptinMonster.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule.jpg 800w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule-300x212.jpg 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule-768x541.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li>\n\n\n\n<li>Configure the&nbsp;<strong>Key<\/strong> and&nbsp;<strong>Value<\/strong> operators and fields as you require.<br><img decoding=\"async\" width=\"816\" height=\"174\" class=\"alignnone size-full wp-image-180391\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule-options.jpg\" alt=\"Configure the Cookie targeting rule in OptinMonster.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule-options.jpg 816w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule-options-300x64.jpg 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/04\/cookie-rule-options-768x164.jpg 768w\" sizes=\"(max-width: 816px) 100vw, 816px\" \/><br>The following match options are available:\n<ul class=\"wp-block-list\">\n<li><strong>Key only:<\/strong>\n<ul class=\"wp-block-list\">\n<li>exists<\/li>\n\n\n\n<li>does not exist<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Value only:<\/strong>\n<ul class=\"wp-block-list\">\n<li>empty<\/li>\n\n\n\n<li>not empty<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Key and Value:<\/strong>\n<ul class=\"wp-block-list\">\n<li>exactly matches<\/li>\n\n\n\n<li>does not exactly match<\/li>\n\n\n\n<li>contains<\/li>\n\n\n\n<li>does not contain<\/li>\n\n\n\n<li>starts with<\/li>\n\n\n\n<li>does not start with<\/li>\n\n\n\n<li>ends with<\/li>\n\n\n\n<li>does not end with<\/li>\n\n\n\n<li>is empty<\/li>\n\n\n\n<li>is anything (if the key or value is irrelevant choose this option)<\/li>\n\n\n\n<li>matches the pattern<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>When you&#8217;re finished, <strong>Save<\/strong> the campaign.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"define\">Examples<\/h2>\n\n\n\n<p>The cookie detection rule allows you to add real-time onsite retargeting campaigns.<\/p>\n\n\n\n<p>For example, if you have an online store, your eCommerce software adds a cookie to every user who has purchased a product from you. When that customer returns to your website, you can use the cookie detection rule to show them a returning customer discount.<\/p>\n\n\n\n<p>The best part is that cookie detection is happening in real-time. Meaning if a user just purchased Product A, you can immediately show them an upsell or special promotion for Product B.<\/p>\n\n\n\n<p>Another use case would be for those who are using an advanced email marketing solution like Infusionsoft, ActiveCampaign, Pardot etc. to run a drip campaign. These solutions add subscriber-specific cookies to your users browser. You can use these to show personalized popups based on the stage the user is inside your marketing funnel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq\">FAQs<\/h2>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"cookie-definition\">What are cookies?<\/h5>\n\n\n\n<p>Cookies are little pieces of data in a web browser that is unique to each site. Each cookie contains only bits of text, nothing else. The text can be a user ID, session ID or any other text.<\/p>\n\n\n\n<p>Cookies are very common, it&#8217;s normal to have hundreds or even thousands stored in your browser at any given moment.<\/p>\n\n\n\n<p>For example, cookies help a website determine if you&#8217;ve logged into an account and keep you logged in while you continue browsing through the site. Clearing your cookies on that site would immediately log you out of your account.<\/p>\n\n\n\n<p>All cookies have a <strong>key<\/strong> and a <strong>value<\/strong>: <code>key=value<\/code>. For example, a cookie could be: <code>country=us<\/code><\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"how-to-set-a-cookie\">How do I set a cookie on my site?<\/h5>\n\n\n\n<p>This question is best answered by your web developer, as it depends on your site&#8217;s structure, coding language, and your goals.<\/p>\n\n\n\n<p>Here are a few articles to help you learn how to do this effectively:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Cookies\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">Cookie Definition and Code Overview<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document\/cookie\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">Get and set the cookies associated with the current document.<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Cookie\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">The Cookie HTTP request header contains stored HTTP cookies previously sent by the server with the Set-Cookie header.<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Set-Cookie\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">The Set-Cookie HTTP response header is used to send cookies from the server to the user agent.<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/78c837bd.aspx\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">How to Write a Cookie.<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Tools\/Storage_Inspector\" target=\"_blank\" rel=\"noopener nofollow\" title=\"\">Firefox Developer Tools to Inspect Cookies.<\/a><\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"other-campaigns\">How do I hide this campaign if the visitor has already seen one of my campaigns?<\/h5>\n\n\n\n<p>To hide or show a campaign based on the visitor seeing another specific campaign can be done using <a href=\"https:\/\/optinmonster.com\/docs\/how-to-use-monsterchains-to-display-your-campaigns-based-on-visitor-interaction\/\" target=\"_blank\" rel=\"noopener\" title=\"\">MonsterChains<\/a>.<\/p>\n\n\n\n<p>If you want to hide all campaigns on your site after the visitor has seen or subscribed to any of your campaigns, then you should <a href=\"https:\/\/optinmonster.com\/docs\/how-optin-cookies-and-the-global-cookie-work-in-optinmonster\/\" target=\"_blank\" rel=\"noopener noreferrer\" title=\"How Campaign Cookies and the Global Cookie Work in OptinMonster\">configure global cookies<\/a>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">How do I create a custom cookie based on UTM Parameters?<\/h5>\n\n\n\n<p>UTM parameters don&#8217;t follow in the URL as a user continues browsing through a site. If you&#8217;d like to target visitors as they continue browsing through your site based on the UTM parameters used when the visitor entered the site, then you will need to create a custom cookie to save the specific UTM parameter you are wanting to target. <br><br>Follow the below steps to create a custom cookie based on UTM parameters: <br><br>1) Add the below script to your website. Ensure to update the snippet to capture the UTM parameters you want to save as a cookie.<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/qor1vjv5.js\/\"><\/script>\n\n\n\n<p>2) Add a cookie targeting display rule to your campaign to check if the <code>omCustomCookie<\/code> exists and has a value. <br><img decoding=\"async\" width=\"850\" height=\"248\" class=\"wp-image-201723\" style=\"width: 850px;\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/07\/customCookie.png\" alt=\"\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/07\/customCookie.png 2268w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/07\/customCookie-300x88.png 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/07\/customCookie-1024x299.png 1024w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/07\/customCookie-768x224.png 768w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/07\/customCookie-1536x448.png 1536w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/07\/customCookie-2048x598.png 2048w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/p>\n\n\n\n<p>3) Save your changes. <\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>OptinMonster makes it easy to hide or show campaigns based on the cookies in your visitor&#8217;s browser. In this article, you&#8217;ll learn how to use OptinMonster&#8217;s Display Rules to hide or show a campaign based on cookies. Configure Cookie Rule When you&nbsp;create a campaign in OptinMonster you can configure it to be shown or hidden&nbsp;&hellip;<\/p>\n","protected":false},"author":4657,"comment_status":"open","ping_status":"closed","template":"","documentation\/categories":[28201],"documentation\/tags":[31399,31432,31498,31415,31856,31411,31455],"class_list":["post-112488","optinmonster_docs","type-optinmonster_docs","status-publish","hentry","categories-display-rules"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/112488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/types\/optinmonster_docs"}],"author":[{"embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/users\/4657"}],"replies":[{"embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/comments?post=112488"}],"version-history":[{"count":15,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/112488\/revisions"}],"predecessor-version":[{"id":201780,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/112488\/revisions\/201780"}],"wp:attachment":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/media?parent=112488"}],"wp:term":[{"taxonomy":"categories","embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/categories?post=112488"},{"taxonomy":"internal_tags","embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/tags?post=112488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}