Sub topic 9
Frequency caps and targeting
This chapter assumes you can read basic HTML and JavaScript, know what an email service provider does, and have already built a pop-up with a trigger, as in the previous chapter. It covers how often a visitor sees a prompt and which visitors see it at all.
Why caps and targeting matter
A pop-up that fires on every page view turns a good offer into a nuisance. Visitors who have already subscribed, or who have already said no, see the same prompt again and again. Some leave, and some stop trusting the site.
Two controls prevent this:
- A frequency cap limits how often one visitor sees a prompt.
- Targeting decides which visitors are eligible to see it.
Both run in the visitor's browser or in your pop-up tool. Both need a way to remember who the visitor is and what they have already done.
Frequency caps
A frequency cap is a rule such as "show at most once every seven days" or "never show again after a successful sign-up". Most tools combine three kinds of rule.
| Rule | What it remembers | Typical value |
|---|---|---|
| Cooldown after dismissal | Time of the last close | 7 to 30 days |
| Permanent suppression after sign-up | A "subscribed" flag | Forever |
| Session or page-view limit | Count of prompts shown | 1 per session |
The cooldown after dismissal is the most important. A visitor who clicked "No thanks" has given you an answer. Asking again tomorrow ignores it.
Remember the visitor with localStorage
The previous chapter's script stored the time of the last close. The version below also records sign-ups, caps prompts per session, and survives storage failures.
const DISMISS_KEY = 'signupDismissedAt';
const SUBSCRIBED_KEY = 'signupSubscribed';
const SESSION_KEY = 'signupShownThisSession';
const COOLDOWN_MS = 7 * 24 * 60 * 60 * 1000;
function read(store, key) {
try {
return store.getItem(key);
} catch (err) {
return null; // Storage blocked, for example in private mode.
}
}
function write(store, key, value) {
try {
store.setItem(key, value);
} catch (err) {
// Ignore: the cap simply will not persist.
}
}
function mayShowPrompt() {
if (read(localStorage, SUBSCRIBED_KEY) === 'yes') return false;
if (read(sessionStorage, SESSION_KEY) === 'yes') return false;
const dismissedAt = Number(read(localStorage, DISMISS_KEY));
if (dismissedAt > 0 && Date.now() - dismissedAt < COOLDOWN_MS) return false;
return true;
}
function markShown() {
write(sessionStorage, SESSION_KEY, 'yes');
}
function markDismissed() {
write(localStorage, DISMISS_KEY, String(Date.now()));
}
function markSubscribed() {
write(localStorage, SUBSCRIBED_KEY, 'yes');
}Call mayShowPrompt() before you register the trigger. Call markShown() when the dialog opens, markDismissed() from the dialog's close event, and markSubscribed() when the sign-up succeeds.
Limits of browser storage
localStorage is simple, but it has gaps you should know about.
- It is per browser and per device. A visitor who dismissed the pop-up on a laptop will see it on a phone.
- Clearing site data, private browsing, or some privacy settings erase it.
- It is per origin.
www.example.comandshop.example.comdo not share it. - Anything you store to recognise a returning visitor may count as access to information on the user's device. Under rules such as the EU ePrivacy Directive, that can need consent unless it is strictly necessary. Check with whoever handles privacy for your site. A dismissal timestamp is low risk, but you should still list it in your privacy documentation.
If you need a cap that follows the person across devices, you need a signed-in account or a server-side record. For most newsletters, a per-browser cap is enough.
Choosing a cooldown
There is no universal number. Use these starting points and adjust with data from the measurement chapter.
- 7 days for a pop-up on a site people visit weekly.
- 30 days for a site people visit rarely, since each visitor is a scarce chance.
- A shorter cooldown, such as 1 to 3 days, only for a different offer, not the same one repeated.
When someone closes the pop-up without subscribing, a longer cooldown tends to protect goodwill. When someone closes it by accident, such as a mistaken tap, you lose a chance. A visible "No thanks" button reduces accidents because the visitor knows what they chose.
Targeting
Targeting narrows who sees a prompt. Good targeting does two things: it hides prompts from people who cannot use them, and it matches the offer to the reader's interest.
Common targeting signals
| Signal | Example rule | Notes |
|---|---|---|
| Page or section | Show the "SEO checklist" offer only on `/blog/seo/` | Strongest signal, because the page shows intent |
| Visit count | Wait until the second visit | Needs storage, so it has the same limits as caps |
| Traffic source | Show a welcome offer to search visitors, not to people already on your list from email | Use the `utm_source` query parameter |
| Device type | Use a bar on mobile, a dialog on desktop | Ties into the next chapter |
| Subscriber status | Hide for known subscribers | Needs a flag or a cookie set at sign-up |
| Geography | Show consent wording that fits the visitor's region | Done by the server or tool, not by your page script |
Match the offer to the page
Page-level targeting is usually the best return for the least work. A reader of an article about sourdough bread will respond to a sourdough starter guide. They are less likely to respond to a generic "Join our newsletter" prompt. Keep a small mapping from URL path to offer.
const OFFERS = [
{ prefix: '/blog/seo/', title: 'Get the SEO checklist', list: 'seo-checklist' },
{ prefix: '/blog/email/', title: 'Get the email subject line swipe file', list: 'subject-lines' },
];
const DEFAULT_OFFER = { title: 'Get the weekly newsletter', list: 'weekly' };
function pickOffer(pathname) {
return OFFERS.find((o) => pathname.startsWith(o.prefix)) || DEFAULT_OFFER;
}
const offer = pickOffer(window.location.pathname);
document.querySelector('#signup-title').textContent = offer.title;
document.querySelector('#popup-list').value = offer.list;This script expects a hidden field named popup-list inside the dialog form, which sends the chosen list to your server. Treat that value as untrusted on the server, and accept only list names you know.
Exclude people who should not see it
Exclusions matter as much as inclusions. Suppress the prompt for:
- Existing subscribers, once you can identify them.
- Visitors on checkout, account, and legal pages, where a pop-up interrupts a task.
- Visitors who arrived from your own email campaigns. The
utm_source=newsletterparameter on your links lets you detect this. - Visitors who just submitted any form on your site.
function fromOwnNewsletter() {
const params = new URLSearchParams(window.location.search);
return params.get('utm_source') === 'newsletter';
}
function onExcludedPage(pathname) {
return ['/checkout', '/account', '/privacy'].some((p) => pathname.startsWith(p));
}
function eligible() {
return mayShowPrompt()
&& !fromOwnNewsletter()
&& !onExcludedPage(window.location.pathname);
}Use eligible() as the gate before you register the scroll trigger from the previous chapter.
How the decision flows
The checks run in a fixed order, cheapest first, and any failure ends the process without showing anything.
Common errors
- Setting the cap only on "close". If the visitor navigates away with the dialog open, the
closeevent never fires and no cooldown is saved. CallmarkShown()when you open the dialog, and treat the session limit as a backup. - Forgetting the sign-up flag. A subscriber who sees the pop-up the day after joining feels ignored. Set the flag in the success handler, and also after a double opt-in confirmation page loads.
- Resetting the cap on every deploy. If you rename the storage key, every visitor becomes new. Version keys on purpose, such as when you launch a different offer.
- Targeting too narrowly. Many tiny segments each get too little traffic to measure. Start with page group and device, then split further when you have the volume.
- Stacking prompts. A pop-up, a sticky bar, and an inline form can all open at once. Let one component own the decision, or have each one check a shared session flag.
Summary of decisions
- Cap by sign-up, by dismissal cooldown, and by session.
- Store the state in the browser, and handle storage that is blocked.
- Target by page first, then by source and device.
- Exclude task pages, existing subscribers, and visitors from your own email.
- Let one component decide, and check in a fixed order.
Exercise
A visitor closes your pop-up on Monday and sees it again on Wednesday, although your cooldown is seven days. The code stores the time in localStorage inside the close event handler. Give two likely causes and how you would check each.
Show answer
First, the close event may not have fired. If the visitor left the page or the dialog was removed without closing, no timestamp was saved. Check by opening the browser's storage inspector after closing and looking for the signupDismissedAt key. Second, the storage may not persist or may differ between visits: private browsing, cleared site data, or a different origin such as www versus the bare domain. Check by repeating the test in a normal window on the same hostname, and compare the origin shown in the storage inspector on both days. A third possibility is a renamed storage key after a deploy.
Exercise
Your site has a blog about running and a shop. Write the targeting rules, in plain words, that you would set for a "marathon training plan" pop-up.
Show answer
Show it only on blog pages about running, such as paths starting with /blog/running/. Hide it for existing subscribers, for visitors who came from your own newsletter links, and on shop checkout and account pages. Cap it at once per session, with a 7 to 30 day cooldown after a dismissal and permanent suppression after sign-up.