Skip to content

Document how to target a feature flag to a URL - #22594

Merged
haacked merged 3 commits into
masterfrom
haacked/flag-url-targeting-docs
Nov 21, 2026
Merged

haacked merged 3 commits into
masterfrom
haacked/flag-url-targeting-docs

Conversation

@haacked

@haacked haacked commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Changes

Feature flags don't have a setting that limits a flag to one page. People ask for this in PostHog/posthog#32777. This PR documents the methods that work now.

The new "Targeting a specific URL" section in feature-flags/property-overrides lists the methods. It gives details for three of them. You can check the URL in your code, send the URL with setPersonPropertiesForFlags(), or send the URL to a server-side SDK as a person property. The other two pages link to this section and don't repeat it.

The new section in experiments/exposures says to use a $pageview exposure event with a filter on the page. It also says not to filter $feature_flag_called by URL. The web SDK sends that event one time for each flag value. A user who first read the flag on a different page doesn't send it from the target page.

The new use case in feature-flags/evaluation-contexts sets an evaluation context from the page path. It works only on sites where each page is a full page load.

I loaded the three pages with pnpm start. The console didn't show any new errors, and each new anchor link goes to its heading. pnpm format doesn't process .mdx files. The markdownlint pre-commit hook passed.

Checklist

  • I've read the docs and/or content style guides.
  • Words are spelled using American English
  • Use relative URLs for internal links
  • I've checked the pages added or changed in the Vercel preview build
  • If I moved a page, I added a redirect in vercel.json

https://claude.ai/code/session_01AovXvZeS9zrgxHYRjJ7dwM

@github-actions github-actions Bot added the content PR only touches files under contents/ label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Deploy preview

Status Details Updated (UTC)
🟢 Ready View preview Nov 21, 2026 12:32AM

Changed pages

Page Source
Exposures contents/docs/experiments/exposures.mdx
Evaluation contexts contents/docs/feature-flags/evaluation-contexts.mdx
Property overrides for flag evaluation contents/docs/feature-flags/property-overrides.mdx

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Vale prose linter → found 0 errors, 37 warnings, 6 suggestions in your markdown

Full report → Copy the linter results into an LLM to batch-fix issues.

Linter being weird? Update the rules!

contents/docs/experiments/exposures.mdx — 0 errors, 17 warnings, 2 suggestions
Line Severity Message Rule
11:234 warning Capitalize 'Experiments' for PostHog's product. Use 'experiments' for the general industry concept. PostHogBase.ProductNames
17:45 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
21:63 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
38:170 suggestion Address the reader directly. Use 'you' instead of 'the user'. PostHogDocs.DirectAddress
70:63 warning Capitalize 'Experiments' for PostHog's product. Use 'experiments' for the general industry concept. PostHogBase.ProductNames
75:30 warning Capitalize 'Experiments' for PostHog's product. Use 'experiments' for the general industry concept. PostHogBase.ProductNames
76:19 warning Capitalize 'Experiments' for PostHog's product. Use 'experiments' for the general industry concept. PostHogBase.ProductNames
76:49 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
82:107 warning Capitalize 'Experiments' for PostHog's product. Use 'experiments' for the general industry concept. PostHogBase.ProductNames
84:32 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
96:36 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
113:147 suggestion Address the reader directly. Use 'you' instead of 'the user'. PostHogDocs.DirectAddress
139:64 warning 'dedup' is a possible misspelling. PostHogBase.Spelling
139:99 warning 'localStorage' is a possible misspelling. PostHogBase.Spelling
139:134 warning 'dedup' is a possible misspelling. PostHogBase.Spelling
145:5 warning 'Why SRM matters' heading should be in sentence case, and product names should be capitalized. PostHogBase.SentenceCase
176:5 warning 'What to do if SRM is detected' heading should be in sentence case, and product names should be capitalized. PostHogBase.SentenceCase
182:267 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
207:38 warning Capitalize 'Experiments' for PostHog's product. Use 'experiments' for the general industry concept. PostHogBase.ProductNames
contents/docs/feature-flags/evaluation-contexts.mdx — 0 errors, 10 warnings, 0 suggestions
Line Severity Message Rule
13:75 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
28:9 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
42:69 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
43:21 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
44:13 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
44:37 warning Use 'API' instead of 'api'. Vale.Terms
45:17 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
60:64 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
161:237 warning Use the Oxford comma before 'and' or 'or' in a list of three or more items. PostHogBase.OxfordComma
167:16 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
contents/docs/feature-flags/property-overrides.mdx — 0 errors, 10 warnings, 4 suggestions
Line Severity Message Rule
152:63 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
284:30 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
286:34 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
312:28 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
312:35 warning Use 'PostHog' instead of 'posthog'. Vale.Terms
312:43 warning Use 'iOS' instead of 'ios'. Vale.Terms
386:85 warning Capitalize 'Feature Flags' for PostHog's product. Use 'feature flags' for the general industry concept. PostHogBase.ProductNames
567:55 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
571:62 suggestion Address the reader directly. Use 'you' instead of 'the user'. PostHogDocs.DirectAddress
584:59 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
586:61 warning Don't put a comma after 'e.g.,'. Write 'i.e.' or 'e.g.' with no comma after it. PostHogBase.LatinAbbreviationComma
730:69 suggestion Address the reader directly. Use 'you' instead of 'the user'. PostHogDocs.DirectAddress
734:60 suggestion Address the reader directly. Use 'you' instead of 'the user'. PostHogDocs.DirectAddress
815:191 suggestion Address the reader directly. Use 'you' instead of 'the user'. PostHogDocs.DirectAddress

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Bundle report

Total JS (gzip)

12.22 MiB (+5.4 KiB / +0.0%)

Largest changed named chunks
Chunk Gzip Δ vs master
490bc41e476e65d6e70047bd978778ccbdbc6b56.js 453.3 KiB +3.1 KiB / +0.7%
2461c6025d2bedd130ec0d6eb3c75cde5c20a8d5.js 131.3 KiB +1.1 KiB / +0.9%

Eager graph (modules shipped in each entrypoint's initial chunks)

Entrypoint Eager size Budget Modules
✅ app 11.16 MiB (+1.7 KiB / +0.0%) report-only 1117
Largest modules in the app closure
Module Size
css ./node_modules/.pnpm/css-loader@5.2.7_webpack@5.101.3/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[8].oneOf[1].use[1]!./node_modules/.pnpm/postcss-loader@4.3.0_postcss@8.5.6_webpack@5.101.3/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[8].oneOf[1].use[2]!./src/styles/global.css 1023.8 KiB
./src/components/Stickers/Stickers.tsx 696.4 KiB
./node_modules/.pnpm/@posthog+brand@0.13.0_react@18.3.1/node_modules/@posthog/brand/dist/generated/hoggies/svg/puzzle.mjs 388.5 KiB
./node_modules/.pnpm/@posthog+icons@0.36.6_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@posthog/icons/dist/posthog-icons.es.js 354.8 KiB
./node_modules/.pnpm/react-markdown@8.0.7_@types+react@16.14.66_react@18.3.1/node_modules/react-markdown/lib/react-markdown.js + 88 modules 351.4 KiB
./node_modules/.pnpm/@posthog+brand@0.13.0_react@18.3.1/node_modules/@posthog/brand/dist/generated/hoggies/svg/basketball-coach.mjs 337.4 KiB
./node_modules/.pnpm/framer-motion@14.0.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/framer-motion/dist/es/render/components/motion/proxy.mjs + 126 modules 287.2 KiB
./node_modules/.pnpm/cloudinary-core@2.14.0_lodash@4.17.21/node_modules/cloudinary-core/cloudinary-core.js 281.9 KiB
./src/components/SearchUI/index.tsx + 87 modules 273.1 KiB
./gatsby-browser.tsx + 60 modules 259.6 KiB
./node_modules/.pnpm/@posthog+brand@0.13.0_react@18.3.1/node_modules/@posthog/brand/dist/generated/hoggies/svg/construction-1.mjs 248.5 KiB
./src/components/Pricing/PricingSlider/Slider.tsx + 87 modules 240.2 KiB
./node_modules/.pnpm/@posthog+brand@0.13.0_react@18.3.1/node_modules/@posthog/brand/dist/generated/hoggies/svg/construction-2.mjs 228.2 KiB
./node_modules/.pnpm/@posthog+brand@0.13.0_react@18.3.1/node_modules/@posthog/brand/dist/generated/hoggies/svg/magnifying-glass.mjs 221.7 KiB
./src/hooks/useProduct.ts + 18 modules 164.9 KiB

Eager-graph budgets are report-only until a baseline is established. Sizes are gzip of public/**/*.js; eager size is webpack module source bytes for the modules actually shipped in the entrypoint's initial chunks (post-tree-shake).

@haacked
haacked marked this pull request as ready for review November 19, 2026 23:35
@haacked
haacked requested review from a team November 19, 2026 23:35

@posthog posthog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PostHog Review · Standard · reviewed 1826d88: 2 Should fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

@rubychilds rubychilds left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good. Not many suggestions!


## Targeting a specific URL

Feature flags don't have a setting that limits them to a page. PostHog evaluates flags when the SDK requests them, not when the user opens a page. To make a flag apply only on a specific page, use one of these options:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little weird here to use 'Feature flags' then 'Posthog' like they are two separate entities.

"Feature flags do not have a setting that limits them to a page. Flags are evaluated when the SDK makes a request, not when the user opens up a page."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I reworded it to your suggestion: "Flags are evaluated when the SDK makes a request, not when the user opens a page, so they don't have a setting that limits them to a page." Fixed in 9523bca.

"$pathname": pathname,
},
)
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are showing the passing here, but do we want to additionally add the getFlag functions here too? It's focused which is fine, but then it shows the full flow - as we mention passing in the next paragraph.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the examples now read the flag after evaluating it (getFlag in Node.js, get_flag in Python). Fixed in 9523bca.

### Exposing users on a specific page

To include only users who visit a specific page, set the exposure event to `$pageview` and add a property filter on `$pathname` (for example, `$pathname` equals `/pricing`) or `$current_url`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default exposure already works if you only read the flag on that page - should we state that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. The section now opens by saying the default exposure works if only the target page reads the flag, and to use $pageview if other pages read it too. Fixed in 9523bca.

- property-overrides.mdx: the intro states that flags are evaluated per SDK request, and the server examples read the flag value
- exposures.mdx: the page-exposure section says the default exposure works when only the target page reads the flag

Claude-Session: https://claude.ai/code/session_01AovXvZeS9zrgxHYRjJ7dwM
@haacked
haacked merged commit 1b25cfa into master Nov 21, 2026
28 checks passed
@haacked
haacked deleted the haacked/flag-url-targeting-docs branch November 21, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

content PR only touches files under contents/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants