vybekiit 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (665) hide show
  1. package/dist/bin.js +840 -296
  2. package/dist/global-skills/add-ai/SKILL.md +53 -0
  3. package/dist/global-skills/add-analytics/SKILL.md +65 -0
  4. package/dist/global-skills/add-app-clip/SKILL.md +280 -0
  5. package/dist/global-skills/add-app-clip/agents/openai.yaml +4 -0
  6. package/dist/global-skills/add-app-clip/references/native-module.md +96 -0
  7. package/dist/global-skills/add-blog/SKILL.md +49 -0
  8. package/dist/global-skills/add-crud/SKILL.md +28 -0
  9. package/dist/global-skills/add-files/SKILL.md +65 -0
  10. package/dist/global-skills/add-images/SKILL.md +64 -0
  11. package/dist/global-skills/add-language/SKILL.md +44 -0
  12. package/dist/global-skills/add-notifications/SKILL.md +61 -0
  13. package/dist/global-skills/add-realtime/SKILL.md +49 -0
  14. package/dist/global-skills/add-route/SKILL.md +28 -0
  15. package/dist/global-skills/add-search/SKILL.md +43 -0
  16. package/dist/global-skills/add-signin/SKILL.md +78 -0
  17. package/dist/global-skills/add-teams/SKILL.md +64 -0
  18. package/dist/global-skills/add-upload/SKILL.md +27 -0
  19. package/dist/global-skills/aws-cdk/SKILL.md +72 -0
  20. package/dist/global-skills/aws-cdk/references/bootstrap-and-project-setup.md +257 -0
  21. package/dist/global-skills/aws-cdk/references/compliance-and-drift.md +193 -0
  22. package/dist/global-skills/aws-cdk/references/construct-patterns.md +315 -0
  23. package/dist/global-skills/aws-cdk/references/import-and-migrate.md +184 -0
  24. package/dist/global-skills/aws-cdk/references/refactor-and-prevent-replacement.md +198 -0
  25. package/dist/global-skills/aws-cdk/references/troubleshooting-credentials.md +183 -0
  26. package/dist/global-skills/aws-cdk/references/troubleshooting-deployment.md +293 -0
  27. package/dist/global-skills/aws-cdk/references/troubleshooting-synth.md +274 -0
  28. package/dist/global-skills/aws-cdk/references/v1-to-v2-migration.md +119 -0
  29. package/dist/global-skills/aws-cloudformation/SKILL.md +88 -0
  30. package/dist/global-skills/aws-cloudformation/references/author-cloudformation-best-practices.script.md +179 -0
  31. package/dist/global-skills/aws-cloudformation/references/check-cloudformation-template-compliance.script.md +159 -0
  32. package/dist/global-skills/aws-cloudformation/references/cloudformation-pre-deploy-validation.script.md +217 -0
  33. package/dist/global-skills/aws-cloudformation/references/deploy-with-express-mode.script.md +271 -0
  34. package/dist/global-skills/aws-cloudformation/references/lookup-resource-properties.script.md +130 -0
  35. package/dist/global-skills/aws-cloudformation/references/troubleshoot-deployment.script.md +200 -0
  36. package/dist/global-skills/aws-cloudformation/references/validate-cloudformation-template.script.md +135 -0
  37. package/dist/global-skills/aws-serverless/SKILL.md +51 -0
  38. package/dist/global-skills/aws-serverless/assets/powertools-handler.py +49 -0
  39. package/dist/global-skills/aws-serverless/references/api-gateway.md +553 -0
  40. package/dist/global-skills/aws-serverless/references/architecture.md +262 -0
  41. package/dist/global-skills/aws-serverless/references/concurrency.md +200 -0
  42. package/dist/global-skills/aws-serverless/references/deployment.md +94 -0
  43. package/dist/global-skills/aws-serverless/references/event-sources.md +484 -0
  44. package/dist/global-skills/aws-serverless/references/lambda.md +548 -0
  45. package/dist/global-skills/aws-serverless/references/orchestration.md +449 -0
  46. package/dist/global-skills/aws-serverless/references/production.md +493 -0
  47. package/dist/global-skills/aws-serverless/references/troubleshooting.md +711 -0
  48. package/dist/global-skills/back-up-my-code/SKILL.md +48 -0
  49. package/dist/global-skills/better-auth-best-practices/SKILL.md +182 -0
  50. package/dist/global-skills/better-auth-security-best-practices/SKILL.md +432 -0
  51. package/dist/global-skills/building-native-ui/SKILL.md +377 -0
  52. package/dist/global-skills/building-native-ui/agents/openai.yaml +4 -0
  53. package/dist/global-skills/building-native-ui/references/animations.md +220 -0
  54. package/dist/global-skills/building-native-ui/references/controls.md +270 -0
  55. package/dist/global-skills/building-native-ui/references/form-sheet.md +253 -0
  56. package/dist/global-skills/building-native-ui/references/gradients.md +106 -0
  57. package/dist/global-skills/building-native-ui/references/icons.md +213 -0
  58. package/dist/global-skills/building-native-ui/references/media.md +198 -0
  59. package/dist/global-skills/building-native-ui/references/route-structure.md +229 -0
  60. package/dist/global-skills/building-native-ui/references/search.md +248 -0
  61. package/dist/global-skills/building-native-ui/references/storage.md +121 -0
  62. package/dist/global-skills/building-native-ui/references/tabs.md +433 -0
  63. package/dist/global-skills/building-native-ui/references/toolbar-and-headers.md +284 -0
  64. package/dist/global-skills/building-native-ui/references/visual-effects.md +197 -0
  65. package/dist/global-skills/building-native-ui/references/webgpu-three.md +605 -0
  66. package/dist/global-skills/building-native-ui/references/zoom-transitions.md +158 -0
  67. package/dist/global-skills/buy-domain/SKILL.md +64 -0
  68. package/dist/global-skills/check-safety/SKILL.md +94 -0
  69. package/dist/global-skills/claimable-postgres/SKILL.md +249 -0
  70. package/dist/global-skills/configure-capabilities/SKILL.md +38 -0
  71. package/dist/global-skills/connect-account/SKILL.md +64 -0
  72. package/dist/global-skills/connect-account-backend/SKILL.md +41 -0
  73. package/dist/global-skills/create-auth-skill/SKILL.md +321 -0
  74. package/dist/global-skills/design-my-data/SKILL.md +48 -0
  75. package/dist/global-skills/doctor/SKILL.md +84 -0
  76. package/dist/global-skills/eas-app-stores/SKILL.md +152 -0
  77. package/dist/global-skills/eas-app-stores/agents/openai.yaml +4 -0
  78. package/dist/global-skills/eas-app-stores/references/app-store-metadata.md +497 -0
  79. package/dist/global-skills/eas-app-stores/references/ios-app-store.md +371 -0
  80. package/dist/global-skills/eas-app-stores/references/play-store.md +246 -0
  81. package/dist/global-skills/eas-app-stores/references/testflight.md +58 -0
  82. package/dist/global-skills/eas-app-stores/references/workflows.md +120 -0
  83. package/dist/global-skills/eas-hosting/SKILL.md +423 -0
  84. package/dist/global-skills/eas-hosting/agents/openai.yaml +4 -0
  85. package/dist/global-skills/eas-observe/SKILL.md +32 -0
  86. package/dist/global-skills/eas-observe/agents/openai.yaml +4 -0
  87. package/dist/global-skills/eas-observe/references/metrics.md +47 -0
  88. package/dist/global-skills/eas-observe/references/queries.md +342 -0
  89. package/dist/global-skills/eas-observe/references/setup.md +317 -0
  90. package/dist/global-skills/eas-simulator/SKILL.md +156 -0
  91. package/dist/global-skills/eas-simulator/agents/openai.yaml +4 -0
  92. package/dist/global-skills/eas-simulator/references/controllers.md +67 -0
  93. package/dist/global-skills/eas-simulator/references/run-your-app.md +185 -0
  94. package/dist/global-skills/eas-simulator/references/troubleshooting.md +38 -0
  95. package/dist/global-skills/eas-update-insights/SKILL.md +230 -0
  96. package/dist/global-skills/eas-update-insights/agents/openai.yaml +4 -0
  97. package/dist/global-skills/eas-update-insights/references/channel-insights-schema.md +47 -0
  98. package/dist/global-skills/eas-update-insights/references/update-insights-schema.md +69 -0
  99. package/dist/global-skills/eas-workflows/SKILL.md +94 -0
  100. package/dist/global-skills/eas-workflows/agents/openai.yaml +4 -0
  101. package/dist/global-skills/eas-workflows/scripts/fetch.js +109 -0
  102. package/dist/global-skills/eas-workflows/scripts/package.json +11 -0
  103. package/dist/global-skills/eas-workflows/scripts/validate.js +84 -0
  104. package/dist/global-skills/email-best-practices/SKILL.md +73 -0
  105. package/dist/global-skills/expo-api-routes/SKILL.md +368 -0
  106. package/dist/global-skills/expo-api-routes/agents/openai.yaml +4 -0
  107. package/dist/global-skills/expo-app-clip/SKILL.md +282 -0
  108. package/dist/global-skills/expo-app-clip/agents/openai.yaml +4 -0
  109. package/dist/global-skills/expo-app-clip/references/native-module.md +96 -0
  110. package/dist/global-skills/expo-brownfield/SKILL.md +54 -0
  111. package/dist/global-skills/expo-brownfield/agents/openai.yaml +4 -0
  112. package/dist/global-skills/expo-brownfield/references/brownfield-integrated.md +526 -0
  113. package/dist/global-skills/expo-brownfield/references/brownfield-isolated.md +402 -0
  114. package/dist/global-skills/expo-brownfield/references/comparison.md +63 -0
  115. package/dist/global-skills/expo-brownfield/references/troubleshooting.md +88 -0
  116. package/dist/global-skills/expo-cicd-workflows/SKILL.md +92 -0
  117. package/dist/global-skills/expo-cicd-workflows/agents/openai.yaml +4 -0
  118. package/dist/global-skills/expo-cicd-workflows/scripts/fetch.js +109 -0
  119. package/dist/global-skills/expo-cicd-workflows/scripts/package.json +11 -0
  120. package/dist/global-skills/expo-cicd-workflows/scripts/validate.js +84 -0
  121. package/dist/global-skills/expo-data-fetching/SKILL.md +449 -0
  122. package/dist/global-skills/expo-data-fetching/agents/openai.yaml +4 -0
  123. package/dist/global-skills/expo-data-fetching/references/expo-router-loaders.md +341 -0
  124. package/dist/global-skills/expo-data-fetching/references/offline-and-cancellation.md +68 -0
  125. package/dist/global-skills/expo-deployment/SKILL.md +167 -0
  126. package/dist/global-skills/expo-deployment/agents/openai.yaml +4 -0
  127. package/dist/global-skills/expo-deployment/references/app-store-metadata.md +497 -0
  128. package/dist/global-skills/expo-deployment/references/ios-app-store.md +371 -0
  129. package/dist/global-skills/expo-deployment/references/play-store.md +246 -0
  130. package/dist/global-skills/expo-deployment/references/testflight.md +58 -0
  131. package/dist/global-skills/expo-deployment/references/workflows.md +160 -0
  132. package/dist/global-skills/expo-dev-client/SKILL.md +174 -0
  133. package/dist/global-skills/expo-dev-client/agents/openai.yaml +4 -0
  134. package/dist/global-skills/expo-dom/SKILL.md +417 -0
  135. package/dist/global-skills/expo-dom/agents/openai.yaml +4 -0
  136. package/dist/global-skills/expo-examples/SKILL.md +99 -0
  137. package/dist/global-skills/expo-examples/agents/openai.yaml +4 -0
  138. package/dist/global-skills/expo-examples/references/catalog.md +105 -0
  139. package/dist/global-skills/expo-module/SKILL.md +141 -0
  140. package/dist/global-skills/expo-module/agents/openai.yaml +4 -0
  141. package/dist/global-skills/expo-module/references/config-plugin.md +90 -0
  142. package/dist/global-skills/expo-module/references/create-expo-module.md +206 -0
  143. package/dist/global-skills/expo-module/references/lifecycle.md +127 -0
  144. package/dist/global-skills/expo-module/references/module-config.md +48 -0
  145. package/dist/global-skills/expo-module/references/native-module.md +286 -0
  146. package/dist/global-skills/expo-module/references/native-view.md +171 -0
  147. package/dist/global-skills/expo-native-ui/SKILL.md +181 -0
  148. package/dist/global-skills/expo-native-ui/agents/openai.yaml +4 -0
  149. package/dist/global-skills/expo-native-ui/references/animations.md +220 -0
  150. package/dist/global-skills/expo-native-ui/references/controls.md +270 -0
  151. package/dist/global-skills/expo-native-ui/references/gradients.md +106 -0
  152. package/dist/global-skills/expo-native-ui/references/icons.md +213 -0
  153. package/dist/global-skills/expo-native-ui/references/media.md +198 -0
  154. package/dist/global-skills/expo-native-ui/references/storage.md +121 -0
  155. package/dist/global-skills/expo-native-ui/references/visual-effects.md +197 -0
  156. package/dist/global-skills/expo-native-ui/references/webgpu-three.md +605 -0
  157. package/dist/global-skills/expo-observe/SKILL.md +30 -0
  158. package/dist/global-skills/expo-observe/references/metrics.md +47 -0
  159. package/dist/global-skills/expo-observe/references/queries.md +342 -0
  160. package/dist/global-skills/expo-observe/references/setup.md +317 -0
  161. package/dist/global-skills/expo-router/SKILL.md +230 -0
  162. package/dist/global-skills/expo-router/agents/openai.yaml +4 -0
  163. package/dist/global-skills/expo-router/references/form-sheet.md +253 -0
  164. package/dist/global-skills/expo-router/references/route-structure.md +229 -0
  165. package/dist/global-skills/expo-router/references/search.md +248 -0
  166. package/dist/global-skills/expo-router/references/tabs.md +433 -0
  167. package/dist/global-skills/expo-router/references/toolbar-and-headers.md +284 -0
  168. package/dist/global-skills/expo-router/references/zoom-transitions.md +158 -0
  169. package/dist/global-skills/expo-skill-eval/SKILL.md +314 -0
  170. package/dist/global-skills/expo-skill-eval/agents/visual-grader.md +52 -0
  171. package/dist/global-skills/expo-skill-eval/references/design-rubric.md +45 -0
  172. package/dist/global-skills/expo-skill-eval/references/runtime-matrix.md +34 -0
  173. package/dist/global-skills/expo-skill-eval/scripts/check-static.sh +64 -0
  174. package/dist/global-skills/expo-skill-eval/scripts/clean-fixture.sh +56 -0
  175. package/dist/global-skills/expo-skill-eval/scripts/generate_viewer.py +450 -0
  176. package/dist/global-skills/expo-skill-eval/scripts/latest-sdk.sh +46 -0
  177. package/dist/global-skills/expo-skill-eval/scripts/make-fixture.sh +95 -0
  178. package/dist/global-skills/expo-skill-eval/scripts/make-workspace.sh +31 -0
  179. package/dist/global-skills/expo-skill-eval/scripts/snapshot-android.sh +284 -0
  180. package/dist/global-skills/expo-skill-eval/scripts/snapshot-ios.sh +132 -0
  181. package/dist/global-skills/expo-skill-eval/scripts/snapshot-web.sh +61 -0
  182. package/dist/global-skills/expo-skill-feedback/SKILL.md +54 -0
  183. package/dist/global-skills/expo-skill-feedback/agents/openai.yaml +4 -0
  184. package/dist/global-skills/expo-skill-feedback/scripts/skill-event.cjs +180 -0
  185. package/dist/global-skills/expo-skill-feedback/scripts/skill-feedback.cjs +118 -0
  186. package/dist/global-skills/expo-skill-feedback/scripts/telemetry.cjs +65 -0
  187. package/dist/global-skills/expo-skill-feedback/scripts/telemetry_common.cjs +171 -0
  188. package/dist/global-skills/expo-tailwind-setup/SKILL.md +480 -0
  189. package/dist/global-skills/expo-tailwind-setup/agents/openai.yaml +4 -0
  190. package/dist/global-skills/expo-ui/SKILL.md +47 -0
  191. package/dist/global-skills/expo-ui/agents/openai.yaml +4 -0
  192. package/dist/global-skills/expo-ui/references/drop-in-replacements.md +27 -0
  193. package/dist/global-skills/expo-ui/references/jetpack-compose.md +73 -0
  194. package/dist/global-skills/expo-ui/references/swift-ui.md +73 -0
  195. package/dist/global-skills/expo-ui/references/universal.md +73 -0
  196. package/dist/global-skills/expo-ui/scripts/list-components.js +193 -0
  197. package/dist/global-skills/expo-upgrade/SKILL.md +134 -0
  198. package/dist/global-skills/expo-upgrade/agents/openai.yaml +4 -0
  199. package/dist/global-skills/expo-upgrade/references/expo-av-to-audio.md +132 -0
  200. package/dist/global-skills/expo-upgrade/references/expo-av-to-video.md +160 -0
  201. package/dist/global-skills/expo-upgrade/references/native-tabs.md +124 -0
  202. package/dist/global-skills/expo-upgrade/references/new-architecture.md +79 -0
  203. package/dist/global-skills/expo-upgrade/references/react-19.md +79 -0
  204. package/dist/global-skills/expo-upgrade/references/react-compiler.md +59 -0
  205. package/dist/global-skills/expo-upgrade/references/react-navigation-to-expo-router.md +61 -0
  206. package/dist/global-skills/expo-web-to-native/SKILL.md +83 -0
  207. package/dist/global-skills/expo-web-to-native/agents/openai.yaml +4 -0
  208. package/dist/global-skills/expo-web-to-native/references/false-friends.md +119 -0
  209. package/dist/global-skills/expo-web-to-native/references/native-patterns.md +39 -0
  210. package/dist/global-skills/expo-web-to-native/references/run-as-goal.md +48 -0
  211. package/dist/global-skills/expo-web-to-native/references/verify-on-device.md +45 -0
  212. package/dist/global-skills/firebase-ai-logic-basics/SKILL.md +165 -0
  213. package/dist/global-skills/firebase-ai-logic-basics/references/flutter_setup.md +95 -0
  214. package/dist/global-skills/firebase-ai-logic-basics/references/ios_setup.md +156 -0
  215. package/dist/global-skills/firebase-ai-logic-basics/references/usage_patterns_android.md +157 -0
  216. package/dist/global-skills/firebase-ai-logic-basics/references/usage_patterns_web.md +186 -0
  217. package/dist/global-skills/firebase-app-hosting-basics/SKILL.md +73 -0
  218. package/dist/global-skills/firebase-app-hosting-basics/references/cli_commands.md +85 -0
  219. package/dist/global-skills/firebase-app-hosting-basics/references/configuration.md +59 -0
  220. package/dist/global-skills/firebase-app-hosting-basics/references/emulation.md +59 -0
  221. package/dist/global-skills/firebase-auth-basics/SKILL.md +118 -0
  222. package/dist/global-skills/firebase-auth-basics/references/client_sdk_android.md +160 -0
  223. package/dist/global-skills/firebase-auth-basics/references/client_sdk_web.md +301 -0
  224. package/dist/global-skills/firebase-auth-basics/references/flutter_setup.md +149 -0
  225. package/dist/global-skills/firebase-auth-basics/references/ios_setup.md +87 -0
  226. package/dist/global-skills/firebase-auth-basics/references/security_rules.md +49 -0
  227. package/dist/global-skills/firebase-basics/SKILL.md +148 -0
  228. package/dist/global-skills/firebase-basics/references/android_setup.md +41 -0
  229. package/dist/global-skills/firebase-basics/references/firebase-cli-guide.md +18 -0
  230. package/dist/global-skills/firebase-basics/references/firebase-service-init.md +20 -0
  231. package/dist/global-skills/firebase-basics/references/flutter_setup.md +143 -0
  232. package/dist/global-skills/firebase-basics/references/ios_setup.md +113 -0
  233. package/dist/global-skills/firebase-basics/references/local-env-setup.md +80 -0
  234. package/dist/global-skills/firebase-basics/references/refresh/android_studio.md +41 -0
  235. package/dist/global-skills/firebase-basics/references/refresh/antigravity.md +64 -0
  236. package/dist/global-skills/firebase-basics/references/refresh/claude.md +12 -0
  237. package/dist/global-skills/firebase-basics/references/refresh/gemini-cli.md +13 -0
  238. package/dist/global-skills/firebase-basics/references/refresh/other-agents.md +67 -0
  239. package/dist/global-skills/firebase-basics/references/setup/android_studio.md +23 -0
  240. package/dist/global-skills/firebase-basics/references/setup/antigravity.md +98 -0
  241. package/dist/global-skills/firebase-basics/references/setup/claude_code.md +45 -0
  242. package/dist/global-skills/firebase-basics/references/setup/cursor.md +93 -0
  243. package/dist/global-skills/firebase-basics/references/setup/gemini_cli.md +53 -0
  244. package/dist/global-skills/firebase-basics/references/setup/github_copilot.md +104 -0
  245. package/dist/global-skills/firebase-basics/references/setup/other_agents.md +99 -0
  246. package/dist/global-skills/firebase-basics/references/web_setup.md +77 -0
  247. package/dist/global-skills/firebase-crashlytics/SKILL.md +42 -0
  248. package/dist/global-skills/firebase-crashlytics/references/android_setup.md +152 -0
  249. package/dist/global-skills/firebase-crashlytics/references/ios_setup.md +115 -0
  250. package/dist/global-skills/firebase-data-connect/SKILL.md +191 -0
  251. package/dist/global-skills/firebase-data-connect/examples.md +638 -0
  252. package/dist/global-skills/firebase-data-connect/reference/cloud_functions.md +184 -0
  253. package/dist/global-skills/firebase-data-connect/reference/config.md +271 -0
  254. package/dist/global-skills/firebase-data-connect/reference/data_seeding.md +185 -0
  255. package/dist/global-skills/firebase-data-connect/reference/native_sql.md +170 -0
  256. package/dist/global-skills/firebase-data-connect/reference/operations.md +385 -0
  257. package/dist/global-skills/firebase-data-connect/reference/realtime.md +210 -0
  258. package/dist/global-skills/firebase-data-connect/reference/schema.md +290 -0
  259. package/dist/global-skills/firebase-data-connect/reference/sdk_admin_node.md +141 -0
  260. package/dist/global-skills/firebase-data-connect/reference/sdk_android.md +126 -0
  261. package/dist/global-skills/firebase-data-connect/reference/sdk_flutter.md +134 -0
  262. package/dist/global-skills/firebase-data-connect/reference/sdk_ios.md +157 -0
  263. package/dist/global-skills/firebase-data-connect/reference/sdk_web.md +146 -0
  264. package/dist/global-skills/firebase-data-connect/reference/search.md +264 -0
  265. package/dist/global-skills/firebase-data-connect/reference/security.md +295 -0
  266. package/dist/global-skills/firebase-data-connect/templates.md +318 -0
  267. package/dist/global-skills/firebase-firestore/SKILL.md +89 -0
  268. package/dist/global-skills/firebase-firestore/references/enterprise/android_sdk_usage.md +230 -0
  269. package/dist/global-skills/firebase-firestore/references/enterprise/data_model.md +66 -0
  270. package/dist/global-skills/firebase-firestore/references/enterprise/flutter_setup.md +180 -0
  271. package/dist/global-skills/firebase-firestore/references/enterprise/indexes.md +135 -0
  272. package/dist/global-skills/firebase-firestore/references/enterprise/ios_setup.md +189 -0
  273. package/dist/global-skills/firebase-firestore/references/enterprise/provisioning.md +118 -0
  274. package/dist/global-skills/firebase-firestore/references/enterprise/python_sdk_usage.md +138 -0
  275. package/dist/global-skills/firebase-firestore/references/enterprise/security_rules.md +577 -0
  276. package/dist/global-skills/firebase-firestore/references/enterprise/web_sdk_usage.md +127 -0
  277. package/dist/global-skills/firebase-firestore/references/standard/android_sdk_usage.md +193 -0
  278. package/dist/global-skills/firebase-firestore/references/standard/flutter_setup.md +176 -0
  279. package/dist/global-skills/firebase-firestore/references/standard/indexes.md +113 -0
  280. package/dist/global-skills/firebase-firestore/references/standard/ios_setup.md +174 -0
  281. package/dist/global-skills/firebase-firestore/references/standard/provisioning.md +110 -0
  282. package/dist/global-skills/firebase-firestore/references/standard/security_rules.md +577 -0
  283. package/dist/global-skills/firebase-firestore/references/standard/web_sdk_usage.md +192 -0
  284. package/dist/global-skills/firebase-hosting-basics/SKILL.md +64 -0
  285. package/dist/global-skills/firebase-hosting-basics/references/configuration.md +115 -0
  286. package/dist/global-skills/firebase-hosting-basics/references/deploying.md +48 -0
  287. package/dist/global-skills/firebase-remote-config-basics/SKILL.md +124 -0
  288. package/dist/global-skills/firebase-remote-config-basics/references/android_setup.md +91 -0
  289. package/dist/global-skills/firebase-remote-config-basics/references/ios_setup.md +89 -0
  290. package/dist/global-skills/firebase-security-rules-auditor/SKILL.md +70 -0
  291. package/dist/global-skills/go-live/SKILL.md +90 -0
  292. package/dist/global-skills/harden/SKILL.md +101 -0
  293. package/dist/global-skills/instrument-feature-flags/SKILL.md +88 -0
  294. package/dist/global-skills/instrument-feature-flags/references/adding-feature-flag-code.md +3578 -0
  295. package/dist/global-skills/instrument-feature-flags/references/android.md +146 -0
  296. package/dist/global-skills/instrument-feature-flags/references/api.md +194 -0
  297. package/dist/global-skills/instrument-feature-flags/references/best-practices.md +231 -0
  298. package/dist/global-skills/instrument-feature-flags/references/django.md +263 -0
  299. package/dist/global-skills/instrument-feature-flags/references/dotnet.md +763 -0
  300. package/dist/global-skills/instrument-feature-flags/references/elixir.md +47 -0
  301. package/dist/global-skills/instrument-feature-flags/references/flask.md +131 -0
  302. package/dist/global-skills/instrument-feature-flags/references/flutter.md +212 -0
  303. package/dist/global-skills/instrument-feature-flags/references/go.md +208 -0
  304. package/dist/global-skills/instrument-feature-flags/references/ios.md +146 -0
  305. package/dist/global-skills/instrument-feature-flags/references/java.md +94 -0
  306. package/dist/global-skills/instrument-feature-flags/references/laravel.md +170 -0
  307. package/dist/global-skills/instrument-feature-flags/references/next-js.md +383 -0
  308. package/dist/global-skills/instrument-feature-flags/references/nodejs.md +216 -0
  309. package/dist/global-skills/instrument-feature-flags/references/php.md +187 -0
  310. package/dist/global-skills/instrument-feature-flags/references/python.md +191 -0
  311. package/dist/global-skills/instrument-feature-flags/references/react-native.md +166 -0
  312. package/dist/global-skills/instrument-feature-flags/references/react.md +302 -0
  313. package/dist/global-skills/instrument-feature-flags/references/ruby-on-rails.md +604 -0
  314. package/dist/global-skills/instrument-feature-flags/references/ruby.md +200 -0
  315. package/dist/global-skills/instrument-feature-flags/references/rust.md +222 -0
  316. package/dist/global-skills/instrument-feature-flags/references/usage.md +600 -0
  317. package/dist/global-skills/instrument-feature-flags/references/web.md +193 -0
  318. package/dist/global-skills/instrument-product-analytics/SKILL.md +139 -0
  319. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-android.md +1639 -0
  320. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-angular.md +944 -0
  321. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-astro-hybrid.md +1001 -0
  322. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-astro-ssr.md +1004 -0
  323. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-astro-static.md +720 -0
  324. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-astro-view-transitions.md +810 -0
  325. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-django.md +1167 -0
  326. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-expo.md +1412 -0
  327. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-fastapi.md +1585 -0
  328. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-flask.md +1208 -0
  329. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-laravel.md +2267 -0
  330. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-next-app-router.md +712 -0
  331. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-next-pages-router.md +767 -0
  332. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-nuxt-3-6.md +939 -0
  333. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-nuxt-4.md +1078 -0
  334. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-php.md +527 -0
  335. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-python.md +481 -0
  336. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-react-native.md +1823 -0
  337. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-react-react-router-6.md +582 -0
  338. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-react-react-router-7-data.md +892 -0
  339. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-react-react-router-7-declarative.md +649 -0
  340. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-react-react-router-7-framework.md +1218 -0
  341. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-react-tanstack-router-code-based.md +793 -0
  342. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-react-tanstack-router-file-based.md +780 -0
  343. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-ruby-on-rails.md +1320 -0
  344. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-ruby.md +452 -0
  345. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-sveltekit.md +854 -0
  346. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-swift.md +665 -0
  347. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-tanstack-start.md +1199 -0
  348. package/dist/global-skills/instrument-product-analytics/references/EXAMPLE-vue-3.md +910 -0
  349. package/dist/global-skills/instrument-product-analytics/references/android.md +811 -0
  350. package/dist/global-skills/instrument-product-analytics/references/angular.md +376 -0
  351. package/dist/global-skills/instrument-product-analytics/references/astro.md +165 -0
  352. package/dist/global-skills/instrument-product-analytics/references/configuration.md +299 -0
  353. package/dist/global-skills/instrument-product-analytics/references/django.md +263 -0
  354. package/dist/global-skills/instrument-product-analytics/references/dotnet.md +763 -0
  355. package/dist/global-skills/instrument-product-analytics/references/elixir.md +414 -0
  356. package/dist/global-skills/instrument-product-analytics/references/flask.md +131 -0
  357. package/dist/global-skills/instrument-product-analytics/references/flutter.md +845 -0
  358. package/dist/global-skills/instrument-product-analytics/references/go.md +567 -0
  359. package/dist/global-skills/instrument-product-analytics/references/identify-users.md +272 -0
  360. package/dist/global-skills/instrument-product-analytics/references/ios.md +154 -0
  361. package/dist/global-skills/instrument-product-analytics/references/laravel.md +170 -0
  362. package/dist/global-skills/instrument-product-analytics/references/next-js.md +383 -0
  363. package/dist/global-skills/instrument-product-analytics/references/nuxt-js-3-6.md +244 -0
  364. package/dist/global-skills/instrument-product-analytics/references/nuxt-js.md +253 -0
  365. package/dist/global-skills/instrument-product-analytics/references/php.md +646 -0
  366. package/dist/global-skills/instrument-product-analytics/references/posthog-python.md +1675 -0
  367. package/dist/global-skills/instrument-product-analytics/references/python.md +898 -0
  368. package/dist/global-skills/instrument-product-analytics/references/react-native.md +1338 -0
  369. package/dist/global-skills/instrument-product-analytics/references/react-router-v6.md +376 -0
  370. package/dist/global-skills/instrument-product-analytics/references/react-router-v7-data-mode.md +364 -0
  371. package/dist/global-skills/instrument-product-analytics/references/react-router-v7-declarative-mode.md +376 -0
  372. package/dist/global-skills/instrument-product-analytics/references/react-router-v7-framework-mode.md +479 -0
  373. package/dist/global-skills/instrument-product-analytics/references/ruby-on-rails.md +604 -0
  374. package/dist/global-skills/instrument-product-analytics/references/ruby.md +759 -0
  375. package/dist/global-skills/instrument-product-analytics/references/svelte.md +234 -0
  376. package/dist/global-skills/instrument-product-analytics/references/tanstack-start.md +193 -0
  377. package/dist/global-skills/instrument-product-analytics/references/usage.md +600 -0
  378. package/dist/global-skills/instrument-product-analytics/references/vue-js.md +306 -0
  379. package/dist/global-skills/manifest.json +125 -0
  380. package/dist/global-skills/mongodb-atlas-stream-processing/SKILL.md +284 -0
  381. package/dist/global-skills/mongodb-atlas-stream-processing/references/connection-configs.md +298 -0
  382. package/dist/global-skills/mongodb-atlas-stream-processing/references/development-workflow.md +304 -0
  383. package/dist/global-skills/mongodb-atlas-stream-processing/references/mcp-troubleshooting.md +55 -0
  384. package/dist/global-skills/mongodb-atlas-stream-processing/references/output-diagnostics.md +150 -0
  385. package/dist/global-skills/mongodb-atlas-stream-processing/references/pipeline-patterns.md +457 -0
  386. package/dist/global-skills/mongodb-atlas-stream-processing/references/sizing-and-parallelism.md +178 -0
  387. package/dist/global-skills/mongodb-connection/SKILL.md +201 -0
  388. package/dist/global-skills/mongodb-connection/references/monitoring-guide.md +191 -0
  389. package/dist/global-skills/mongodb-mcp-setup/SKILL.md +324 -0
  390. package/dist/global-skills/mongodb-natural-language-querying/SKILL.md +195 -0
  391. package/dist/global-skills/mongodb-query-optimizer/SKILL.md +150 -0
  392. package/dist/global-skills/mongodb-query-optimizer/references/aggregation-optimization.md +210 -0
  393. package/dist/global-skills/mongodb-query-optimizer/references/antipattern-examples.md +74 -0
  394. package/dist/global-skills/mongodb-query-optimizer/references/core-indexing-principles.md +134 -0
  395. package/dist/global-skills/mongodb-query-optimizer/references/update-query-examples.md +39 -0
  396. package/dist/global-skills/mongodb-schema-design/SKILL.md +181 -0
  397. package/dist/global-skills/mongodb-schema-design/references/antipattern-excessive-lookups.md +84 -0
  398. package/dist/global-skills/mongodb-schema-design/references/antipattern-unnecessary-collections.md +91 -0
  399. package/dist/global-skills/mongodb-schema-design/references/antipattern-unnecessary-indexes.md +95 -0
  400. package/dist/global-skills/mongodb-schema-design/references/fundamental-document-model.md +91 -0
  401. package/dist/global-skills/mongodb-schema-design/references/fundamental-document-size.md +226 -0
  402. package/dist/global-skills/mongodb-schema-design/references/fundamental-embed-vs-reference.md +418 -0
  403. package/dist/global-skills/mongodb-schema-design/references/fundamental-schema-validation.md +131 -0
  404. package/dist/global-skills/mongodb-schema-design/references/pattern-approximation.md +80 -0
  405. package/dist/global-skills/mongodb-schema-design/references/pattern-archive.md +143 -0
  406. package/dist/global-skills/mongodb-schema-design/references/pattern-attribute.md +77 -0
  407. package/dist/global-skills/mongodb-schema-design/references/pattern-bucket.md +102 -0
  408. package/dist/global-skills/mongodb-schema-design/references/pattern-computed.md +162 -0
  409. package/dist/global-skills/mongodb-schema-design/references/pattern-document-versioning.md +166 -0
  410. package/dist/global-skills/mongodb-schema-design/references/pattern-extended-reference.md +72 -0
  411. package/dist/global-skills/mongodb-schema-design/references/pattern-outlier.md +159 -0
  412. package/dist/global-skills/mongodb-schema-design/references/pattern-polymorphic.md +167 -0
  413. package/dist/global-skills/mongodb-schema-design/references/pattern-schema-versioning.md +273 -0
  414. package/dist/global-skills/mongodb-schema-design/references/pattern-time-series-collections.md +190 -0
  415. package/dist/global-skills/mongodb-schema-design/references/source-query-stats.md +123 -0
  416. package/dist/global-skills/mongodb-schema-design/references/source-slow-query-logs.md +63 -0
  417. package/dist/global-skills/mongodb-search-and-ai/SKILL.md +142 -0
  418. package/dist/global-skills/mongodb-search-and-ai/references/hybrid-search.md +697 -0
  419. package/dist/global-skills/mongodb-search-and-ai/references/lexical-search-indexing.md +584 -0
  420. package/dist/global-skills/mongodb-search-and-ai/references/lexical-search-querying.md +636 -0
  421. package/dist/global-skills/mongodb-search-and-ai/references/vector-search.md +746 -0
  422. package/dist/global-skills/native-data-fetching/SKILL.md +505 -0
  423. package/dist/global-skills/native-data-fetching/agents/openai.yaml +4 -0
  424. package/dist/global-skills/native-data-fetching/references/expo-router-loaders.md +341 -0
  425. package/dist/global-skills/neon/SKILL.md +343 -0
  426. package/dist/global-skills/neon-ai-gateway/SKILL.md +236 -0
  427. package/dist/global-skills/neon-functions/SKILL.md +490 -0
  428. package/dist/global-skills/neon-functions/references/ai-sdk.md +139 -0
  429. package/dist/global-skills/neon-functions/references/hono-websockets.md +145 -0
  430. package/dist/global-skills/neon-functions/references/mastra-studio.md +127 -0
  431. package/dist/global-skills/neon-functions/references/mcp.md +137 -0
  432. package/dist/global-skills/neon-functions/references/sentry.md +131 -0
  433. package/dist/global-skills/neon-functions/references/sse.md +143 -0
  434. package/dist/global-skills/neon-object-storage/SKILL.md +197 -0
  435. package/dist/global-skills/neon-postgres/SKILL.md +376 -0
  436. package/dist/global-skills/neon-postgres-branches/SKILL.md +281 -0
  437. package/dist/global-skills/neon-postgres-egress-optimizer/SKILL.md +247 -0
  438. package/dist/global-skills/onboarding/SKILL.md +101 -0
  439. package/dist/global-skills/plan-my-idea/SKILL.md +67 -0
  440. package/dist/global-skills/publish-app/SKILL.md +72 -0
  441. package/dist/global-skills/publish-extension/SKILL.md +47 -0
  442. package/dist/global-skills/resend/SKILL.md +294 -0
  443. package/dist/global-skills/resend/references/api-keys.md +98 -0
  444. package/dist/global-skills/resend/references/automations.md +228 -0
  445. package/dist/global-skills/resend/references/broadcasts.md +125 -0
  446. package/dist/global-skills/resend/references/contact-properties.md +111 -0
  447. package/dist/global-skills/resend/references/contacts.md +174 -0
  448. package/dist/global-skills/resend/references/domains.md +179 -0
  449. package/dist/global-skills/resend/references/events.md +119 -0
  450. package/dist/global-skills/resend/references/fetch-all-templates.mjs +37 -0
  451. package/dist/global-skills/resend/references/installation.md +142 -0
  452. package/dist/global-skills/resend/references/logs.md +161 -0
  453. package/dist/global-skills/resend/references/receiving.md +287 -0
  454. package/dist/global-skills/resend/references/segments.md +77 -0
  455. package/dist/global-skills/resend/references/sending/batch-email-examples.md +807 -0
  456. package/dist/global-skills/resend/references/sending/best-practices.md +453 -0
  457. package/dist/global-skills/resend/references/sending/email-management.md +135 -0
  458. package/dist/global-skills/resend/references/sending/overview.md +209 -0
  459. package/dist/global-skills/resend/references/sending/single-email-examples.md +470 -0
  460. package/dist/global-skills/resend/references/templates.md +202 -0
  461. package/dist/global-skills/resend/references/topics.md +104 -0
  462. package/dist/global-skills/resend/references/webhooks.md +317 -0
  463. package/dist/global-skills/reset-password/SKILL.md +59 -0
  464. package/dist/global-skills/save-data/SKILL.md +70 -0
  465. package/dist/global-skills/sentry-sdk-setup/SKILL.md +116 -0
  466. package/dist/global-skills/sentry-workflow/SKILL.md +32 -0
  467. package/dist/global-skills/setup-email/SKILL.md +69 -0
  468. package/dist/global-skills/setup-payments/SKILL.md +82 -0
  469. package/dist/global-skills/setup-sms/SKILL.md +51 -0
  470. package/dist/global-skills/sign-in-with-email-link/SKILL.md +53 -0
  471. package/dist/global-skills/sign-in-with-google/SKILL.md +68 -0
  472. package/dist/global-skills/sign-in-with-phone/SKILL.md +53 -0
  473. package/dist/global-skills/stripe-best-practices/SKILL.md +48 -0
  474. package/dist/global-skills/stripe-best-practices/references/billing.md +58 -0
  475. package/dist/global-skills/stripe-best-practices/references/connect.md +173 -0
  476. package/dist/global-skills/stripe-best-practices/references/payments.md +79 -0
  477. package/dist/global-skills/stripe-best-practices/references/security.md +109 -0
  478. package/dist/global-skills/stripe-best-practices/references/tax.md +37 -0
  479. package/dist/global-skills/stripe-best-practices/references/treasury.md +16 -0
  480. package/dist/global-skills/supabase/CHANGELOG.md +53 -0
  481. package/dist/global-skills/supabase/SKILL.md +145 -0
  482. package/dist/global-skills/supabase/assets/feedback-issue-template.md +17 -0
  483. package/dist/global-skills/supabase/references/skill-feedback.md +17 -0
  484. package/dist/global-skills/supabase-postgres-best-practices/CHANGELOG.md +43 -0
  485. package/dist/global-skills/supabase-postgres-best-practices/SKILL.md +64 -0
  486. package/dist/global-skills/supabase-postgres-best-practices/references/_contributing.md +170 -0
  487. package/dist/global-skills/supabase-postgres-best-practices/references/_sections.md +39 -0
  488. package/dist/global-skills/supabase-postgres-best-practices/references/_template.md +34 -0
  489. package/dist/global-skills/supabase-postgres-best-practices/references/advanced-full-text-search.md +55 -0
  490. package/dist/global-skills/supabase-postgres-best-practices/references/advanced-jsonb-indexing.md +49 -0
  491. package/dist/global-skills/supabase-postgres-best-practices/references/conn-idle-timeout.md +46 -0
  492. package/dist/global-skills/supabase-postgres-best-practices/references/conn-limits.md +44 -0
  493. package/dist/global-skills/supabase-postgres-best-practices/references/conn-pooling.md +41 -0
  494. package/dist/global-skills/supabase-postgres-best-practices/references/conn-prepared-statements.md +46 -0
  495. package/dist/global-skills/supabase-postgres-best-practices/references/data-batch-inserts.md +54 -0
  496. package/dist/global-skills/supabase-postgres-best-practices/references/data-n-plus-one.md +53 -0
  497. package/dist/global-skills/supabase-postgres-best-practices/references/data-pagination.md +50 -0
  498. package/dist/global-skills/supabase-postgres-best-practices/references/data-upsert.md +50 -0
  499. package/dist/global-skills/supabase-postgres-best-practices/references/lock-advisory.md +56 -0
  500. package/dist/global-skills/supabase-postgres-best-practices/references/lock-deadlock-prevention.md +68 -0
  501. package/dist/global-skills/supabase-postgres-best-practices/references/lock-short-transactions.md +50 -0
  502. package/dist/global-skills/supabase-postgres-best-practices/references/lock-skip-locked.md +54 -0
  503. package/dist/global-skills/supabase-postgres-best-practices/references/monitor-explain-analyze.md +45 -0
  504. package/dist/global-skills/supabase-postgres-best-practices/references/monitor-pg-stat-statements.md +55 -0
  505. package/dist/global-skills/supabase-postgres-best-practices/references/monitor-vacuum-analyze.md +55 -0
  506. package/dist/global-skills/supabase-postgres-best-practices/references/query-composite-indexes.md +44 -0
  507. package/dist/global-skills/supabase-postgres-best-practices/references/query-covering-indexes.md +40 -0
  508. package/dist/global-skills/supabase-postgres-best-practices/references/query-index-types.md +48 -0
  509. package/dist/global-skills/supabase-postgres-best-practices/references/query-missing-indexes.md +43 -0
  510. package/dist/global-skills/supabase-postgres-best-practices/references/query-partial-indexes.md +45 -0
  511. package/dist/global-skills/supabase-postgres-best-practices/references/schema-constraints.md +80 -0
  512. package/dist/global-skills/supabase-postgres-best-practices/references/schema-data-types.md +46 -0
  513. package/dist/global-skills/supabase-postgres-best-practices/references/schema-foreign-key-indexes.md +59 -0
  514. package/dist/global-skills/supabase-postgres-best-practices/references/schema-lowercase-identifiers.md +55 -0
  515. package/dist/global-skills/supabase-postgres-best-practices/references/schema-partitioning.md +55 -0
  516. package/dist/global-skills/supabase-postgres-best-practices/references/schema-primary-keys.md +61 -0
  517. package/dist/global-skills/supabase-postgres-best-practices/references/security-privileges.md +54 -0
  518. package/dist/global-skills/supabase-postgres-best-practices/references/security-rls-basics.md +50 -0
  519. package/dist/global-skills/supabase-postgres-best-practices/references/security-rls-performance.md +63 -0
  520. package/dist/global-skills/track-errors/SKILL.md +67 -0
  521. package/dist/global-skills/update-kit/SKILL.md +75 -0
  522. package/dist/global-skills/upgrading-expo/SKILL.md +134 -0
  523. package/dist/global-skills/upgrading-expo/agents/openai.yaml +4 -0
  524. package/dist/global-skills/upgrading-expo/references/expo-av-to-audio.md +132 -0
  525. package/dist/global-skills/upgrading-expo/references/expo-av-to-video.md +160 -0
  526. package/dist/global-skills/upgrading-expo/references/native-tabs.md +124 -0
  527. package/dist/global-skills/upgrading-expo/references/new-architecture.md +79 -0
  528. package/dist/global-skills/upgrading-expo/references/react-19.md +79 -0
  529. package/dist/global-skills/upgrading-expo/references/react-compiler.md +59 -0
  530. package/dist/global-skills/upgrading-expo/references/react-navigation-to-expo-router.md +61 -0
  531. package/dist/global-skills/use-dom/SKILL.md +417 -0
  532. package/dist/global-skills/use-dom/agents/openai.yaml +4 -0
  533. package/dist/global-skills/use-kit-mcp/SKILL.md +100 -0
  534. package/dist/global-skills/use-railway/SKILL.md +357 -0
  535. package/dist/global-skills/use-railway/references/analyze-db-mongo.md +84 -0
  536. package/dist/global-skills/use-railway/references/analyze-db-mysql.md +254 -0
  537. package/dist/global-skills/use-railway/references/analyze-db-postgres.md +479 -0
  538. package/dist/global-skills/use-railway/references/analyze-db-redis.md +208 -0
  539. package/dist/global-skills/use-railway/references/analyze-db.md +344 -0
  540. package/dist/global-skills/use-railway/references/configure.md +359 -0
  541. package/dist/global-skills/use-railway/references/deploy.md +225 -0
  542. package/dist/global-skills/use-railway/references/feature-flags.md +89 -0
  543. package/dist/global-skills/use-railway/references/iac.md +108 -0
  544. package/dist/global-skills/use-railway/references/operate.md +273 -0
  545. package/dist/global-skills/use-railway/references/request.md +262 -0
  546. package/dist/global-skills/use-railway/references/sandbox.md +167 -0
  547. package/dist/global-skills/use-railway/references/setup.md +364 -0
  548. package/dist/global-skills/use-railway/scripts/analyze-mongo.py +1549 -0
  549. package/dist/global-skills/use-railway/scripts/analyze-mysql.py +1195 -0
  550. package/dist/global-skills/use-railway/scripts/analyze-postgres.py +3058 -0
  551. package/dist/global-skills/use-railway/scripts/analyze-redis.py +1090 -0
  552. package/dist/global-skills/use-railway/scripts/dal.py +671 -0
  553. package/dist/global-skills/use-railway/scripts/enable-pg-stats.py +170 -0
  554. package/dist/global-skills/use-railway/scripts/pg-extensions.py +370 -0
  555. package/dist/global-skills/use-railway/scripts/railway-api.sh +52 -0
  556. package/dist/global-skills/vercel-composition-patterns/AGENTS.md +946 -0
  557. package/dist/global-skills/vercel-composition-patterns/README.md +60 -0
  558. package/dist/global-skills/vercel-composition-patterns/SKILL.md +89 -0
  559. package/dist/global-skills/vercel-composition-patterns/metadata.json +11 -0
  560. package/dist/global-skills/vercel-composition-patterns/rules/_sections.md +29 -0
  561. package/dist/global-skills/vercel-composition-patterns/rules/_template.md +24 -0
  562. package/dist/global-skills/vercel-composition-patterns/rules/architecture-avoid-boolean-props.md +100 -0
  563. package/dist/global-skills/vercel-composition-patterns/rules/architecture-compound-components.md +112 -0
  564. package/dist/global-skills/vercel-composition-patterns/rules/patterns-children-over-render-props.md +87 -0
  565. package/dist/global-skills/vercel-composition-patterns/rules/patterns-explicit-variants.md +100 -0
  566. package/dist/global-skills/vercel-composition-patterns/rules/react19-no-forwardref.md +42 -0
  567. package/dist/global-skills/vercel-composition-patterns/rules/state-context-interface.md +191 -0
  568. package/dist/global-skills/vercel-composition-patterns/rules/state-decouple-implementation.md +113 -0
  569. package/dist/global-skills/vercel-composition-patterns/rules/state-lift-state.md +125 -0
  570. package/dist/global-skills/vercel-react-best-practices/AGENTS.md +3810 -0
  571. package/dist/global-skills/vercel-react-best-practices/README.md +123 -0
  572. package/dist/global-skills/vercel-react-best-practices/SKILL.md +149 -0
  573. package/dist/global-skills/vercel-react-best-practices/metadata.json +15 -0
  574. package/dist/global-skills/vercel-react-best-practices/rules/_sections.md +46 -0
  575. package/dist/global-skills/vercel-react-best-practices/rules/_template.md +28 -0
  576. package/dist/global-skills/vercel-react-best-practices/rules/advanced-effect-event-deps.md +56 -0
  577. package/dist/global-skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +55 -0
  578. package/dist/global-skills/vercel-react-best-practices/rules/advanced-init-once.md +42 -0
  579. package/dist/global-skills/vercel-react-best-practices/rules/advanced-use-latest.md +39 -0
  580. package/dist/global-skills/vercel-react-best-practices/rules/async-api-routes.md +38 -0
  581. package/dist/global-skills/vercel-react-best-practices/rules/async-cheap-condition-before-await.md +37 -0
  582. package/dist/global-skills/vercel-react-best-practices/rules/async-defer-await.md +82 -0
  583. package/dist/global-skills/vercel-react-best-practices/rules/async-dependencies.md +51 -0
  584. package/dist/global-skills/vercel-react-best-practices/rules/async-parallel.md +28 -0
  585. package/dist/global-skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +99 -0
  586. package/dist/global-skills/vercel-react-best-practices/rules/bundle-analyzable-paths.md +63 -0
  587. package/dist/global-skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +60 -0
  588. package/dist/global-skills/vercel-react-best-practices/rules/bundle-conditional.md +31 -0
  589. package/dist/global-skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +49 -0
  590. package/dist/global-skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +35 -0
  591. package/dist/global-skills/vercel-react-best-practices/rules/bundle-preload.md +50 -0
  592. package/dist/global-skills/vercel-react-best-practices/rules/client-event-listeners.md +74 -0
  593. package/dist/global-skills/vercel-react-best-practices/rules/client-localstorage-schema.md +71 -0
  594. package/dist/global-skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +48 -0
  595. package/dist/global-skills/vercel-react-best-practices/rules/client-swr-dedup.md +56 -0
  596. package/dist/global-skills/vercel-react-best-practices/rules/js-batch-dom-css.md +107 -0
  597. package/dist/global-skills/vercel-react-best-practices/rules/js-cache-function-results.md +80 -0
  598. package/dist/global-skills/vercel-react-best-practices/rules/js-cache-property-access.md +28 -0
  599. package/dist/global-skills/vercel-react-best-practices/rules/js-cache-storage.md +70 -0
  600. package/dist/global-skills/vercel-react-best-practices/rules/js-combine-iterations.md +32 -0
  601. package/dist/global-skills/vercel-react-best-practices/rules/js-early-exit.md +50 -0
  602. package/dist/global-skills/vercel-react-best-practices/rules/js-flatmap-filter.md +60 -0
  603. package/dist/global-skills/vercel-react-best-practices/rules/js-hoist-regexp.md +45 -0
  604. package/dist/global-skills/vercel-react-best-practices/rules/js-index-maps.md +37 -0
  605. package/dist/global-skills/vercel-react-best-practices/rules/js-length-check-first.md +49 -0
  606. package/dist/global-skills/vercel-react-best-practices/rules/js-min-max-loop.md +82 -0
  607. package/dist/global-skills/vercel-react-best-practices/rules/js-request-idle-callback.md +105 -0
  608. package/dist/global-skills/vercel-react-best-practices/rules/js-set-map-lookups.md +24 -0
  609. package/dist/global-skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +57 -0
  610. package/dist/global-skills/vercel-react-best-practices/rules/rendering-activity.md +26 -0
  611. package/dist/global-skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +47 -0
  612. package/dist/global-skills/vercel-react-best-practices/rules/rendering-conditional-render.md +40 -0
  613. package/dist/global-skills/vercel-react-best-practices/rules/rendering-content-visibility.md +38 -0
  614. package/dist/global-skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +46 -0
  615. package/dist/global-skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +82 -0
  616. package/dist/global-skills/vercel-react-best-practices/rules/rendering-hydration-suppress-warning.md +30 -0
  617. package/dist/global-skills/vercel-react-best-practices/rules/rendering-resource-hints.md +85 -0
  618. package/dist/global-skills/vercel-react-best-practices/rules/rendering-script-defer-async.md +68 -0
  619. package/dist/global-skills/vercel-react-best-practices/rules/rendering-svg-precision.md +28 -0
  620. package/dist/global-skills/vercel-react-best-practices/rules/rendering-usetransition-loading.md +75 -0
  621. package/dist/global-skills/vercel-react-best-practices/rules/rerender-defer-reads.md +39 -0
  622. package/dist/global-skills/vercel-react-best-practices/rules/rerender-dependencies.md +45 -0
  623. package/dist/global-skills/vercel-react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
  624. package/dist/global-skills/vercel-react-best-practices/rules/rerender-derived-state.md +29 -0
  625. package/dist/global-skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +74 -0
  626. package/dist/global-skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +58 -0
  627. package/dist/global-skills/vercel-react-best-practices/rules/rerender-memo-with-default-value.md +38 -0
  628. package/dist/global-skills/vercel-react-best-practices/rules/rerender-memo.md +44 -0
  629. package/dist/global-skills/vercel-react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
  630. package/dist/global-skills/vercel-react-best-practices/rules/rerender-no-inline-components.md +82 -0
  631. package/dist/global-skills/vercel-react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
  632. package/dist/global-skills/vercel-react-best-practices/rules/rerender-split-combined-hooks.md +64 -0
  633. package/dist/global-skills/vercel-react-best-practices/rules/rerender-transitions.md +40 -0
  634. package/dist/global-skills/vercel-react-best-practices/rules/rerender-use-deferred-value.md +59 -0
  635. package/dist/global-skills/vercel-react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
  636. package/dist/global-skills/vercel-react-best-practices/rules/server-after-nonblocking.md +73 -0
  637. package/dist/global-skills/vercel-react-best-practices/rules/server-auth-actions.md +96 -0
  638. package/dist/global-skills/vercel-react-best-practices/rules/server-cache-lru.md +41 -0
  639. package/dist/global-skills/vercel-react-best-practices/rules/server-cache-react.md +76 -0
  640. package/dist/global-skills/vercel-react-best-practices/rules/server-dedup-props.md +65 -0
  641. package/dist/global-skills/vercel-react-best-practices/rules/server-hoist-static-io.md +149 -0
  642. package/dist/global-skills/vercel-react-best-practices/rules/server-no-shared-module-state.md +50 -0
  643. package/dist/global-skills/vercel-react-best-practices/rules/server-parallel-fetching.md +83 -0
  644. package/dist/global-skills/vercel-react-best-practices/rules/server-parallel-nested-fetching.md +34 -0
  645. package/dist/global-skills/vercel-react-best-practices/rules/server-serialization.md +38 -0
  646. package/dist/global-skills/web-to-native/SKILL.md +83 -0
  647. package/dist/global-skills/web-to-native/references/false-friends.md +119 -0
  648. package/dist/global-skills/web-to-native/references/native-patterns.md +39 -0
  649. package/dist/global-skills/web-to-native/references/run-as-goal.md +48 -0
  650. package/dist/global-skills/web-to-native/references/verify-on-device.md +45 -0
  651. package/dist/global-skills/wire-auth/SKILL.md +28 -0
  652. package/dist/global-skills/wire-database/SKILL.md +28 -0
  653. package/dist/global-skills/wire-email/SKILL.md +27 -0
  654. package/dist/global-skills/wire-payments/SKILL.md +27 -0
  655. package/dist/global-skills/workers-best-practices/SKILL.md +127 -0
  656. package/dist/global-skills/workers-best-practices/references/review.md +174 -0
  657. package/dist/global-skills/workers-best-practices/references/rules.md +463 -0
  658. package/dist/global-skills/wrangler/SKILL.md +922 -0
  659. package/dist/global-skills/xcode-project-setup/SKILL.md +140 -0
  660. package/dist/global-skills/xcode-project-setup/scripts/xcode_spm_setup/Package.resolved +41 -0
  661. package/dist/global-skills/xcode-project-setup/scripts/xcode_spm_setup/Package.swift +17 -0
  662. package/dist/global-skills/xcode-project-setup/scripts/xcode_spm_setup/Sources/main.swift +232 -0
  663. package/package.json +21 -20
  664. package/LICENSE.md +0 -47
  665. package/dist/index.js +0 -21593
@@ -0,0 +1,3578 @@
1
+ # Adding feature flag code - Docs
2
+
3
+ Once you've created your feature flag in PostHog, the next step is to add your code:
4
+
5
+ ## Web
6
+
7
+ ### Boolean feature flags
8
+
9
+ Web
10
+
11
+ PostHog AI
12
+
13
+ ```javascript
14
+ const result = posthog.getFeatureFlagResult('flag-key')
15
+ if (result?.enabled) {
16
+ // Do something differently for this user
17
+ // Optional: fetch the payload from the same evaluation result
18
+ const matchedFlagPayload = result?.payload
19
+ }
20
+ ```
21
+
22
+ ### Multivariate feature flags
23
+
24
+ Web
25
+
26
+ PostHog AI
27
+
28
+ ```javascript
29
+ const result = posthog.getFeatureFlagResult('flag-key')
30
+ if (result?.variant == 'variant-key') { // replace 'variant-key' with the key of your variant
31
+ // Do something differently for this user
32
+ // Optional: fetch the payload from the same evaluation result
33
+ const matchedFlagPayload = result?.payload
34
+ }
35
+ ```
36
+
37
+ ### Inspecting all feature flags
38
+
39
+ You can inspect all currently loaded feature flags with `getAllFeatureFlags()`. It returns each flag's `key`, `enabled` state, `variant`, and `payload`, and does not send a `$feature_flag_called` event, so calling it won't affect your experiment results or flag usage analytics:
40
+
41
+ Web
42
+
43
+ PostHog AI
44
+
45
+ ```javascript
46
+ for (const flag of posthog.getAllFeatureFlags()) {
47
+ console.log(flag.key, flag.enabled, flag.variant, flag.payload)
48
+ }
49
+ ```
50
+
51
+ ### Ensuring flags are loaded before usage
52
+
53
+ Every time a user loads a page, we send a request in the background to fetch the feature flags that apply to that user. We store those flags in your chosen persistence option (local storage by default).
54
+
55
+ This means that for most pages, the feature flags are available immediately — **except for the first time a user visits**.
56
+
57
+ To handle this, you can use the `onFeatureFlags` callback to wait for the feature flag request to finish:
58
+
59
+ Web
60
+
61
+ PostHog AI
62
+
63
+ ```javascript
64
+ posthog.onFeatureFlags(function (flags, flagVariants, { errorsLoading }) {
65
+ // feature flags are guaranteed to be available at this point
66
+ if (posthog.isFeatureEnabled('flag-key')) {
67
+ // do something
68
+ }
69
+ })
70
+ ```
71
+
72
+ #### Callback parameters
73
+
74
+ The `onFeatureFlags` callback receives the following parameters:
75
+
76
+ - `flags: string[]`: An object containing the feature flags that apply to the user.
77
+
78
+ - `flagVariants: Record<string, string | boolean>`: An object containing the variants that apply to the user.
79
+
80
+ - `{ errorsLoading }: { errorsLoading?: boolean }`: An object containing a boolean indicating if an error occurred during the request to load the feature flags. This is `true` if the request timed out or if there was an error. It will be `false` or `undefined` if the request was successful.
81
+
82
+ You won't usually need to use these, but they are useful if you want to be extra careful about feature flags not being loaded yet because of a network error and/or a network timeout (see `feature_flag_request_timeout_ms`).
83
+
84
+ ### Evaluating only specific flags
85
+
86
+ By default, the JavaScript SDK requests that every eligible feature flag be evaluated for the current user. If you'd only like to evaluate and return a subset of flags, pass `flag_keys` when initializing PostHog:
87
+
88
+ Web
89
+
90
+ PostHog AI
91
+
92
+ ```javascript
93
+ posthog.init('<ph_project_token>', {
94
+ api_host: 'https://us.i.posthog.com',
95
+ defaults: '2026-05-30',
96
+ flag_keys: ['checkout-flow', 'new-dashboard'],
97
+ })
98
+ ```
99
+
100
+ PostHog scopes evaluation and the response to those keys for this SDK instance. Dependency flags required to evaluate requested flags may also be evaluated and returned. Leave `flag_keys` unset to evaluate all eligible flags.
101
+
102
+ ### Reloading feature flags
103
+
104
+ Feature flag values are cached. If something has changed with your user and you'd like to refetch their flag values, call:
105
+
106
+ Web
107
+
108
+ PostHog AI
109
+
110
+ ```javascript
111
+ posthog.reloadFeatureFlags()
112
+ ```
113
+
114
+ ### Overriding server properties
115
+
116
+ Sometimes, you might want to evaluate feature flags using properties that haven't been ingested yet, or were set incorrectly earlier. You can do so by setting properties the flag depends on with these calls:
117
+
118
+ Web
119
+
120
+ PostHog AI
121
+
122
+ ```javascript
123
+ posthog.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'})
124
+ ```
125
+
126
+ > **Note:** These are set for the entire session. Successive calls are additive: all properties you set are combined together and sent for flag evaluation.
127
+
128
+ Whenever you set these properties, we also trigger a reload of feature flags to ensure we have the latest values. You can disable this by passing in the optional parameter for reloading:
129
+
130
+ Web
131
+
132
+ PostHog AI
133
+
134
+ ```javascript
135
+ posthog.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'}, false)
136
+ ```
137
+
138
+ At any point, you can reset these properties by calling `resetPersonPropertiesForFlags`:
139
+
140
+ Web
141
+
142
+ PostHog AI
143
+
144
+ ```javascript
145
+ posthog.resetPersonPropertiesForFlags()
146
+ ```
147
+
148
+ The same holds for [group](/manual/group-analytics.md) properties:
149
+
150
+ Web
151
+
152
+ PostHog AI
153
+
154
+ ```javascript
155
+ // set properties for a group
156
+ posthog.setGroupPropertiesForFlags({'company': {'property1': 'value', property2: 'value2'}})
157
+ // reset properties for a given group:
158
+ posthog.resetGroupPropertiesForFlags('company')
159
+ // reset properties for all groups:
160
+ posthog.resetGroupPropertiesForFlags()
161
+ ```
162
+
163
+ > **Note:** You don't need to add the group names here, since these properties are automatically attached to the current group (set via `posthog.group()`). When you change the group, these properties are reset.
164
+
165
+ #### Automatic overrides
166
+
167
+ Whenever you call `posthog.identify` with person properties, we automatically add these properties to flag evaluation calls to help determine the correct flag values. The same is true for when you call `posthog.group()`.
168
+
169
+ #### Default overridden properties
170
+
171
+ By default, we always override some properties based on the user IP address.
172
+
173
+ The list of properties that this overrides:
174
+
175
+ 1. `$geoip_city_name`
176
+ 2. `$geoip_country_name`
177
+ 3. `$geoip_country_code`
178
+ 4. `$geoip_continent_name`
179
+ 5. `$geoip_continent_code`
180
+ 6. `$geoip_postal_code`
181
+ 7. `$geoip_time_zone`
182
+
183
+ This enables any geolocation-based flags to work without manually setting these properties.
184
+
185
+ ### Request timeout
186
+
187
+ You can configure the `feature_flag_request_timeout_ms` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked in the case when PostHog's servers are too slow to respond. By default, this is set at 3 seconds.
188
+
189
+ JavaScript
190
+
191
+ PostHog AI
192
+
193
+ ```javascript
194
+ posthog.init('<ph_project_token>', {
195
+ api_host: 'https://us.i.posthog.com',
196
+ defaults: '2026-05-30',
197
+ feature_flag_request_timeout_ms: 3000 // Time in milliseconds. Default is 3000 (3 seconds).
198
+ })
199
+ ```
200
+
201
+ ### Feature flag error handling
202
+
203
+ When using the PostHog SDK, it's important to handle potential errors that may occur during feature flag operations. Here's an example of how to wrap PostHog SDK methods in an error handler:
204
+
205
+ JavaScript
206
+
207
+ PostHog AI
208
+
209
+ ```javascript
210
+ function handleFeatureFlag(client, flagKey, distinctId) {
211
+ try {
212
+ const isEnabled = client.isFeatureEnabled(flagKey, distinctId);
213
+ console.log(`Feature flag '${flagKey}' for user '${distinctId}' is ${isEnabled ? 'enabled' : 'disabled'}`);
214
+ return isEnabled;
215
+ } catch (error) {
216
+ console.error(`Error fetching feature flag '${flagKey}': ${error.message}`);
217
+ // Optionally, you can return a default value or throw the error
218
+ // return false; // Default to disabled
219
+ throw error;
220
+ }
221
+ }
222
+ // Usage example
223
+ try {
224
+ const flagEnabled = handleFeatureFlag(client, 'new-feature', 'user-123');
225
+ if (flagEnabled) {
226
+ // Implement new feature logic
227
+ } else {
228
+ // Implement old feature logic
229
+ }
230
+ } catch (error) {
231
+ // Handle the error at a higher level
232
+ console.error('Feature flag check failed, using default behavior');
233
+ // Implement fallback logic
234
+ }
235
+ ```
236
+
237
+ ## React
238
+
239
+ There are two ways to implement feature flags in React:
240
+
241
+ 1. Using hooks.
242
+ 2. Using the `<PostHogFeature>` component.
243
+
244
+ ### Method 1: Using hooks
245
+
246
+ PostHog provides several hooks to make it easy to use feature flags in your React app.
247
+
248
+ | Hook | Description |
249
+ | --- | --- |
250
+ | useFeatureFlagEnabled | Returns whether the feature flag is enabled. This sends a $feature_flag_called event. Without a default value, it returns boolean \\\| undefined while flags are loading or absent. Pass an optional default value to return that value instead and narrow the return type to boolean. |
251
+ | useFeatureFlagVariantKey | Returns the variant key of the feature flag. This sends a $feature_flag_called event. |
252
+ | useActiveFeatureFlags | Returns an array of active feature flags. This does not send a $feature_flag_called event. |
253
+ | useFeatureFlagPayload | Returns the payload of the feature flag. This does not send a $feature_flag_called event. Always use this with useFeatureFlagEnabled or useFeatureFlagVariantKey. |
254
+
255
+ #### Example 1: Using a boolean feature flag
256
+
257
+ React
258
+
259
+ PostHog AI
260
+
261
+ ```jsx
262
+ import { useFeatureFlagEnabled, useFeatureFlagPayload } from '@posthog/react'
263
+ function App() {
264
+ const showWelcomeMessage = useFeatureFlagEnabled('flag-key')
265
+ const payload = useFeatureFlagPayload('flag-key')
266
+ return (
267
+ <div className="App">
268
+ {
269
+ showWelcomeMessage ? (
270
+ <div>
271
+ <h1>Welcome!</h1>
272
+ <p>Thanks for trying out our feature flags.</p>
273
+ </div>
274
+ ) : (
275
+ <div>
276
+ <h2>No welcome message</h2>
277
+ <p>Because the feature flag evaluated to false.</p>
278
+ </div>
279
+ )
280
+ }
281
+ </div>
282
+ );
283
+ }
284
+ export default App;
285
+ ```
286
+
287
+ To avoid handling `undefined` while flags are loading, pass a default value as the second argument:
288
+
289
+ React
290
+
291
+ PostHog AI
292
+
293
+ ```jsx
294
+ const showWelcomeMessage = useFeatureFlagEnabled('flag-key', false)
295
+ ```
296
+
297
+ #### Example 2: Using a multivariate feature flag
298
+
299
+ React
300
+
301
+ PostHog AI
302
+
303
+ ```jsx
304
+ import { useFeatureFlagVariantKey } from '@posthog/react'
305
+ function App() {
306
+ const variantKey = useFeatureFlagVariantKey('show-welcome-message')
307
+ let welcomeMessage = ''
308
+ if (variantKey === 'variant-a') {
309
+ welcomeMessage = 'Welcome to the Alpha!'
310
+ } else if (variantKey === 'variant-b') {
311
+ welcomeMessage = 'Welcome to the Beta!'
312
+ }
313
+ return (
314
+ <div className="App">
315
+ {
316
+ welcomeMessage ? (
317
+ <div>
318
+ <h1>{welcomeMessage}</h1>
319
+ <p>Thanks for trying out our feature flags.</p>
320
+ </div>
321
+ ) : (
322
+ <div>
323
+ <h2>No welcome message</h2>
324
+ <p>Because the feature flag evaluated to false.</p>
325
+ </div>
326
+ )
327
+ }
328
+ </div>
329
+ );
330
+ }
331
+ export default App;
332
+ ```
333
+
334
+ #### Example 3: Using a flag payload
335
+
336
+ **Payload hook**
337
+
338
+ The `useFeatureFlagPayload` hook does *not* send a [`$feature_flag_called`](https://posthog.com/docs/experiments/new-experimentation-engine#experiment-exposure) event, which is required for the experiment to be tracked. To ensure the exposure event is sent, you should **always** use the `useFeatureFlagPayload` hook with either the `useFeatureFlagEnabled` or `useFeatureFlagVariantKey` hook.
339
+
340
+ React
341
+
342
+ PostHog AI
343
+
344
+ ```jsx
345
+ import { useFeatureFlagEnabled, useFeatureFlagPayload } from '@posthog/react'
346
+ function App() {
347
+ const variant = useFeatureFlagEnabled('show-welcome-message')
348
+ const payload = useFeatureFlagPayload('show-welcome-message')
349
+ return (
350
+ <>
351
+ {
352
+ variant ? (
353
+ <div className="welcome-message">
354
+ <h2>{payload?.welcomeTitle}</h2>
355
+ <p>{payload?.welcomeMessage}</p>
356
+ </div>
357
+ ) : <div>
358
+ <h2>No custom welcome message</h2>
359
+ <p>Because the feature flag evaluated to false.</p>
360
+ </div>
361
+ }
362
+ </>
363
+ )
364
+ }
365
+ ```
366
+
367
+ ### Method 2: Using the PostHogFeature component
368
+
369
+ The `PostHogFeature` component simplifies code by handling feature flag related logic.
370
+
371
+ It also automatically captures metrics, like how many times a user interacts with this feature.
372
+
373
+ > **Note:** You still need the [`PostHogProvider`](/docs/libraries/react.md#installation) at the top level for this to work.
374
+
375
+ Here is an example:
376
+
377
+ React
378
+
379
+ PostHog AI
380
+
381
+ ```jsx
382
+ import { PostHogFeature } from '@posthog/react'
383
+ function App() {
384
+ return (
385
+ <PostHogFeature flag='show-welcome-message' match={true}>
386
+ <div>
387
+ <h1>Hello</h1>
388
+ <p>Thanks for trying out our feature flags.</p>
389
+ </div>
390
+ </PostHogFeature>
391
+ )
392
+ }
393
+ ```
394
+
395
+ - The `match` on the component can be either `true`, or the variant key, to match on a specific variant.
396
+
397
+ - If you also want to show a default message, you can pass these in the `fallback` attribute.
398
+
399
+ If you wish to customise logic around when the component is considered visible, you can pass in `visibilityObserverOptions` to the feature. These take the same options as the [IntersectionObserver API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). By default, we use a threshold of 0.1.
400
+
401
+ #### Payloads
402
+
403
+ If your flag has a payload, you can pass a function to children whose first argument is the payload. For example:
404
+
405
+ React
406
+
407
+ PostHog AI
408
+
409
+ ```jsx
410
+ import { PostHogFeature } from '@posthog/react'
411
+ function App() {
412
+ return (
413
+ <PostHogFeature flag='show-welcome-message' match={true}>
414
+ {(payload) => {
415
+ return (
416
+ <div>
417
+ <h1>{payload.welcomeMessage}</h1>
418
+ <p>Thanks for trying out our feature flags.</p>
419
+ </div>
420
+ )
421
+ }}
422
+ </PostHogFeature>
423
+ )
424
+ }
425
+ ```
426
+
427
+ ### Request timeout
428
+
429
+ You can configure the `feature_flag_request_timeout_ms` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked in the case when PostHog's servers are too slow to respond. By default, this is set at 3 seconds.
430
+
431
+ JavaScript
432
+
433
+ PostHog AI
434
+
435
+ ```javascript
436
+ posthog.init('<ph_project_token>', {
437
+ api_host: 'https://us.i.posthog.com',
438
+ defaults: '2026-05-30',
439
+ feature_flag_request_timeout_ms: 3000 // Time in milliseconds. Default is 3000 (3 seconds).
440
+ }
441
+ )
442
+ ```
443
+
444
+ ### Error handling
445
+
446
+ When using the PostHog SDK, it's important to handle potential errors that may occur during feature flag operations. Here's an example of how to wrap PostHog SDK methods in an error handler:
447
+
448
+ JavaScript
449
+
450
+ PostHog AI
451
+
452
+ ```javascript
453
+ function handleFeatureFlag(client, flagKey, distinctId) {
454
+ try {
455
+ const isEnabled = client.isFeatureEnabled(flagKey, distinctId);
456
+ console.log(`Feature flag '${flagKey}' for user '${distinctId}' is ${isEnabled ? 'enabled' : 'disabled'}`);
457
+ return isEnabled;
458
+ } catch (error) {
459
+ console.error(`Error fetching feature flag '${flagKey}': ${error.message}`);
460
+ // Optionally, you can return a default value or throw the error
461
+ // return false; // Default to disabled
462
+ throw error;
463
+ }
464
+ }
465
+ // Usage example
466
+ try {
467
+ const flagEnabled = handleFeatureFlag(client, 'new-feature', 'user-123');
468
+ if (flagEnabled) {
469
+ // Implement new feature logic
470
+ } else {
471
+ // Implement old feature logic
472
+ }
473
+ } catch (error) {
474
+ // Handle the error at a higher level
475
+ console.error('Feature flag check failed, using default behavior');
476
+ // Implement fallback logic
477
+ }
478
+ ```
479
+
480
+ ## Node.js
481
+
482
+ There are two steps to implement feature flags in Node:
483
+
484
+ ### Step 1: Evaluate flags once
485
+
486
+ Call `client.evaluateFlags()` once for the user, then read values from the returned snapshot.
487
+
488
+ #### Boolean feature flags
489
+
490
+ Node.js
491
+
492
+ PostHog AI
493
+
494
+ ```javascript
495
+ const flags = await client.evaluateFlags('distinct_id_of_your_user')
496
+ if (flags.isEnabled('flag-key')) {
497
+ // Do something differently for this user
498
+ // Optional: fetch the payload
499
+ const matchedFlagPayload = flags.getFlagPayload('flag-key')
500
+ }
501
+ ```
502
+
503
+ #### Multivariate feature flags
504
+
505
+ Node.js
506
+
507
+ PostHog AI
508
+
509
+ ```javascript
510
+ const flags = await client.evaluateFlags('distinct_id_of_your_user')
511
+ const enabledVariant = flags.getFlag('flag-key')
512
+ if (enabledVariant === 'variant-key') { // replace 'variant-key' with the key of your variant
513
+ // Do something differently for this user
514
+ // Optional: fetch the payload
515
+ const matchedFlagPayload = flags.getFlagPayload('flag-key')
516
+ }
517
+ ```
518
+
519
+ `flags.getFlag()` returns the variant string for multivariate flags, `true` for enabled boolean flags, `false` for disabled flags, and `undefined` when the flag wasn't returned by the evaluation.
520
+
521
+ > **Note:** `client.isFeatureEnabled()`, `client.getFeatureFlag()`, `client.getFeatureFlagPayload()`, and `capture({ sendFeatureFlags: true })` still work during the migration period, but they're deprecated. Prefer `evaluateFlags()` for new code.
522
+
523
+ ### Step 2: Include feature flag information when capturing events
524
+
525
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
526
+
527
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
528
+
529
+ There are two methods you can use to include feature flag information in your events:
530
+
531
+ #### Method 1: Pass the evaluated flags snapshot to `capture()`
532
+
533
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
534
+
535
+ Node.js
536
+
537
+ PostHog AI
538
+
539
+ ```javascript
540
+ const flags = await client.evaluateFlags('distinct_id_of_your_user')
541
+ if (flags.isEnabled('flag-key')) {
542
+ // Do something differently for this user
543
+ }
544
+ client.capture({
545
+ distinctId: 'distinct_id_of_your_user',
546
+ event: 'event_name',
547
+ flags,
548
+ })
549
+ ```
550
+
551
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
552
+
553
+ To reduce event property bloat, pass a filtered snapshot:
554
+
555
+ Node.js
556
+
557
+ PostHog AI
558
+
559
+ ```javascript
560
+ // Attach only flags accessed with isEnabled() or getFlag() before this call
561
+ client.capture({
562
+ distinctId: 'distinct_id_of_your_user',
563
+ event: 'event_name',
564
+ flags: flags.onlyAccessed(),
565
+ })
566
+ // Attach only specific flags
567
+ client.capture({
568
+ distinctId: 'distinct_id_of_your_user',
569
+ event: 'event_name',
570
+ flags: flags.only(['checkout-flow', 'new-dashboard']),
571
+ })
572
+ ```
573
+
574
+ `onlyAccessed()` is order-dependent. If you call it before accessing any flags with `isEnabled()` or `getFlag()`, no feature flag properties are attached.
575
+
576
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
577
+
578
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
579
+
580
+ Node.js
581
+
582
+ PostHog AI
583
+
584
+ ```javascript
585
+ client.capture({
586
+ distinctId: 'distinct_id_of_your_user',
587
+ event: 'event_name',
588
+ properties: {
589
+ // Replace feature-flag-key with your flag key and 'variant-key' with the key of your variant
590
+ '$feature/feature-flag-key': 'variant-key',
591
+ },
592
+ })
593
+ ```
594
+
595
+ ### Evaluating only specific flags
596
+
597
+ By default, `evaluateFlags()` evaluates every flag for the user. If you only need a few flags, pass `flagKeys` to request only those flags:
598
+
599
+ Node.js
600
+
601
+ PostHog AI
602
+
603
+ ```javascript
604
+ const flags = await client.evaluateFlags('distinct_id_of_your_user', {
605
+ flagKeys: ['checkout-flow', 'new-dashboard'],
606
+ })
607
+ ```
608
+
609
+ ### Sending `$feature_flag_called` events
610
+
611
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `evaluateFlags()`, the SDK sends this event when you call `flags.isEnabled()` or `flags.getFlag()` for a flag.
612
+
613
+ The SDK deduplicates these events per `(distinct_id, flag, value)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
614
+
615
+ `flags.getFlagPayload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `onlyAccessed()`.
616
+
617
+ ### Advanced: Overriding server properties
618
+
619
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
620
+
621
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
622
+
623
+ For example:
624
+
625
+ Node.js
626
+
627
+ PostHog AI
628
+
629
+ ```javascript
630
+ const flags = await client.evaluateFlags('distinct_id_of_the_user', {
631
+ personProperties: {
632
+ property_name: 'value',
633
+ },
634
+ groups: {
635
+ your_group_type: 'your_group_id',
636
+ another_group_type: 'your_group_id',
637
+ },
638
+ groupProperties: {
639
+ your_group_type: {
640
+ group_property_name: 'value',
641
+ },
642
+ another_group_type: {
643
+ group_property_name: 'value',
644
+ },
645
+ },
646
+ })
647
+ if (flags.isEnabled('flag-key')) {
648
+ // Do something differently for this user
649
+ }
650
+ ```
651
+
652
+ ### Overriding GeoIP properties
653
+
654
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
655
+
656
+ You can override GeoIP properties by including them in the `person_properties` parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
657
+
658
+ The following GeoIP properties can be overridden:
659
+
660
+ - `$geoip_country_code`
661
+ - `$geoip_country_name`
662
+ - `$geoip_city_name`
663
+ - `$geoip_city_confidence`
664
+ - `$geoip_continent_code`
665
+ - `$geoip_continent_name`
666
+ - `$geoip_latitude`
667
+ - `$geoip_longitude`
668
+ - `$geoip_postal_code`
669
+ - `$geoip_subdivision_1_code`
670
+ - `$geoip_subdivision_1_name`
671
+ - `$geoip_subdivision_2_code`
672
+ - `$geoip_subdivision_2_name`
673
+ - `$geoip_subdivision_3_code`
674
+ - `$geoip_subdivision_3_name`
675
+ - `$geoip_time_zone`
676
+
677
+ Simply include any of these properties in the `person_properties` parameter alongside your other person properties when calling feature flags.
678
+
679
+ ### Request timeout
680
+
681
+ You can configure the `featureFlagsRequestTimeoutMs` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked if PostHog's servers are too slow to respond. By default, this is set to 3 seconds.
682
+
683
+ JavaScript
684
+
685
+ PostHog AI
686
+
687
+ ```javascript
688
+ const client = new PostHog('<ph_project_token>', {
689
+ host: 'https://us.i.posthog.com',
690
+ featureFlagsRequestTimeoutMs: 3000, // Time in milliseconds. Defaults to 3000 (3 seconds).
691
+ })
692
+ ```
693
+
694
+ ## Python
695
+
696
+ There are two steps to implement feature flags in Python:
697
+
698
+ ### Step 1: Evaluate flags once
699
+
700
+ Call `posthog.evaluate_flags()` once for the user, then read values from the returned snapshot.
701
+
702
+ #### Boolean feature flags
703
+
704
+ Python
705
+
706
+ PostHog AI
707
+
708
+ ```python
709
+ flags = posthog.evaluate_flags("distinct_id_of_your_user")
710
+ if flags.is_enabled("flag-key"):
711
+ # Do something differently for this user
712
+ # Optional: fetch the payload
713
+ matched_flag_payload = flags.get_flag_payload("flag-key")
714
+ ```
715
+
716
+ #### Multivariate feature flags
717
+
718
+ Python
719
+
720
+ PostHog AI
721
+
722
+ ```python
723
+ flags = posthog.evaluate_flags("distinct_id_of_your_user")
724
+ enabled_variant = flags.get_flag("flag-key")
725
+ if enabled_variant == "variant-key": # replace "variant-key" with the key of your variant
726
+ # Do something differently for this user
727
+ # Optional: fetch the payload
728
+ matched_flag_payload = flags.get_flag_payload("flag-key")
729
+ ```
730
+
731
+ `flags.get_flag()` returns the variant string for multivariate flags, `True` for enabled boolean flags, `False` for disabled flags, and `None` when the flag wasn't returned by the evaluation.
732
+
733
+ > **Note:** `posthog.feature_enabled()`, `posthog.get_feature_flag()`, `posthog.get_feature_flag_payload()`, and `posthog.capture(send_feature_flags=True)` still work during the migration period, but they're deprecated. Prefer `posthog.evaluate_flags()` for new code.
734
+
735
+ ### Step 2: Include feature flag information when capturing events
736
+
737
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
738
+
739
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
740
+
741
+ There are two methods you can use to include feature flag information in your events:
742
+
743
+ #### Method 1: Pass the evaluated flags snapshot to `capture()`
744
+
745
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
746
+
747
+ Python
748
+
749
+ PostHog AI
750
+
751
+ ```python
752
+ flags = posthog.evaluate_flags("distinct_id_of_your_user")
753
+ if flags.is_enabled("flag-key"):
754
+ # Do something differently for this user
755
+ pass
756
+ posthog.capture(
757
+ "event_name",
758
+ distinct_id="distinct_id_of_your_user",
759
+ flags=flags,
760
+ )
761
+ ```
762
+
763
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
764
+
765
+ To reduce event property bloat, pass a filtered snapshot:
766
+
767
+ Python
768
+
769
+ PostHog AI
770
+
771
+ ```python
772
+ # Attach only flags accessed with is_enabled() or get_flag() before this call
773
+ posthog.capture(
774
+ "event_name",
775
+ distinct_id="distinct_id_of_your_user",
776
+ flags=flags.only_accessed(),
777
+ )
778
+ # Attach only specific flags
779
+ posthog.capture(
780
+ "event_name",
781
+ distinct_id="distinct_id_of_your_user",
782
+ flags=flags.only(["checkout-flow", "new-dashboard"]),
783
+ )
784
+ ```
785
+
786
+ `only_accessed()` is order-dependent. If you call it before accessing any flags with `is_enabled()` or `get_flag()`, no feature flag properties are attached.
787
+
788
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
789
+
790
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
791
+
792
+ Python
793
+
794
+ PostHog AI
795
+
796
+ ```python
797
+ posthog.capture(
798
+ "event_name",
799
+ distinct_id="distinct_id_of_the_user",
800
+ properties={
801
+ # Replace feature-flag-key with your flag key and "variant-key" with the key of your variant
802
+ "$feature/feature-flag-key": "variant-key",
803
+ },
804
+ )
805
+ ```
806
+
807
+ ### Evaluating only specific flags
808
+
809
+ By default, `posthog.evaluate_flags()` evaluates every flag for the user. If you only need a few flags, pass `flag_keys` to request only those flags:
810
+
811
+ Python
812
+
813
+ PostHog AI
814
+
815
+ ```python
816
+ flags = posthog.evaluate_flags(
817
+ "distinct_id_of_your_user",
818
+ flag_keys=["checkout-flow", "new-dashboard"],
819
+ )
820
+ ```
821
+
822
+ ### Sending `$feature_flag_called` events
823
+
824
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `posthog.evaluate_flags()`, the SDK sends this event when you call `flags.is_enabled()` or `flags.get_flag()` for a flag.
825
+
826
+ The SDK deduplicates these events per `(distinct_id, flag, value)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
827
+
828
+ `flags.get_flag_payload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `only_accessed()`.
829
+
830
+ ### Advanced: Overriding server properties
831
+
832
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
833
+
834
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
835
+
836
+ For example:
837
+
838
+ Python
839
+
840
+ PostHog AI
841
+
842
+ ```python
843
+ flags = posthog.evaluate_flags(
844
+ "distinct_id_of_the_user",
845
+ person_properties={"property_name": "value"},
846
+ groups={
847
+ "your_group_type": "your_group_id",
848
+ "another_group_type": "your_group_id",
849
+ },
850
+ group_properties={
851
+ "your_group_type": {"group_property_name": "value"},
852
+ "another_group_type": {"group_property_name": "value"},
853
+ },
854
+ )
855
+ if flags.is_enabled("flag-key"):
856
+ # Do something differently for this user
857
+ ```
858
+
859
+ ### Overriding GeoIP properties
860
+
861
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
862
+
863
+ You can override GeoIP properties by including them in the `person_properties` parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
864
+
865
+ The following GeoIP properties can be overridden:
866
+
867
+ - `$geoip_country_code`
868
+ - `$geoip_country_name`
869
+ - `$geoip_city_name`
870
+ - `$geoip_city_confidence`
871
+ - `$geoip_continent_code`
872
+ - `$geoip_continent_name`
873
+ - `$geoip_latitude`
874
+ - `$geoip_longitude`
875
+ - `$geoip_postal_code`
876
+ - `$geoip_subdivision_1_code`
877
+ - `$geoip_subdivision_1_name`
878
+ - `$geoip_subdivision_2_code`
879
+ - `$geoip_subdivision_2_name`
880
+ - `$geoip_subdivision_3_code`
881
+ - `$geoip_subdivision_3_name`
882
+ - `$geoip_time_zone`
883
+
884
+ Simply include any of these properties in the `person_properties` parameter alongside your other person properties when calling feature flags.
885
+
886
+ ### Request timeout
887
+
888
+ You can configure the `feature_flags_request_timeout_seconds` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked if PostHog's servers are too slow to respond. By default, this is set to 3 seconds.
889
+
890
+ Python
891
+
892
+ PostHog AI
893
+
894
+ ```python
895
+ posthog = Posthog(
896
+ "<ph_project_token>",
897
+ host="https://us.i.posthog.com",
898
+ feature_flags_request_timeout_seconds=3, # Time in seconds. Defaults to 3.
899
+ )
900
+ ```
901
+
902
+ ## PHP
903
+
904
+ There are two steps to implement feature flags in PHP:
905
+
906
+ ### Step 1: Evaluate flags once
907
+
908
+ Call `PostHog::evaluateFlags()` once for the user, then read values from the returned snapshot.
909
+
910
+ #### Boolean feature flags
911
+
912
+ PHP
913
+
914
+ PostHog AI
915
+
916
+ ```php
917
+ $flags = PostHog::evaluateFlags('distinct_id_of_your_user');
918
+ if ($flags->isEnabled('flag-key')) {
919
+ // Do something differently for this user
920
+ // Optional: fetch the payload
921
+ $matchedFlagPayload = $flags->getFlagPayload('flag-key');
922
+ }
923
+ ```
924
+
925
+ #### Multivariate feature flags
926
+
927
+ PHP
928
+
929
+ PostHog AI
930
+
931
+ ```php
932
+ $flags = PostHog::evaluateFlags('distinct_id_of_your_user');
933
+ $enabledVariant = $flags->getFlag('flag-key');
934
+ if ($enabledVariant === 'variant-key') { // replace 'variant-key' with the key of your variant
935
+ // Do something differently for this user
936
+ // Optional: fetch the payload
937
+ $matchedFlagPayload = $flags->getFlagPayload('flag-key');
938
+ }
939
+ ```
940
+
941
+ `$flags->getFlag()` returns the variant string for multivariate flags, `true` for enabled boolean flags, `false` for disabled flags, and `null` when the flag wasn't returned by the evaluation.
942
+
943
+ You can also call `$flags->getKeys()` to list the evaluated flag keys, or `$flags->getEventProperties()` to get the `$feature/<flag-key>` and `$active_feature_flags` properties that would be attached to a captured event.
944
+
945
+ > **Note:** `PostHog::isFeatureEnabled()`, `PostHog::getFeatureFlag()`, `PostHog::getFeatureFlagPayload()`, and `capture(['send_feature_flags' => true])` still work during the migration period, but they're deprecated. Prefer `evaluateFlags()` for new code.
946
+
947
+ ### Step 2: Include feature flag information when capturing events
948
+
949
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
950
+
951
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
952
+
953
+ There are two methods you can use to include feature flag information in your events:
954
+
955
+ #### Method 1: Pass the evaluated flags snapshot to `capture()`
956
+
957
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
958
+
959
+ PHP
960
+
961
+ PostHog AI
962
+
963
+ ```php
964
+ $flags = PostHog::evaluateFlags('distinct_id_of_your_user');
965
+ if ($flags->isEnabled('flag-key')) {
966
+ // Do something differently for this user
967
+ }
968
+ PostHog::capture([
969
+ 'distinctId' => 'distinct_id_of_your_user',
970
+ 'event' => 'event_name',
971
+ 'flags' => $flags,
972
+ ]);
973
+ ```
974
+
975
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
976
+
977
+ To reduce event property bloat, pass a filtered snapshot:
978
+
979
+ PHP
980
+
981
+ PostHog AI
982
+
983
+ ```php
984
+ // Attach only flags accessed with isEnabled() or getFlag() before this call
985
+ PostHog::capture([
986
+ 'distinctId' => 'distinct_id_of_your_user',
987
+ 'event' => 'event_name',
988
+ 'flags' => $flags->onlyAccessed(),
989
+ ]);
990
+ // Attach only specific flags
991
+ PostHog::capture([
992
+ 'distinctId' => 'distinct_id_of_your_user',
993
+ 'event' => 'event_name',
994
+ 'flags' => $flags->only(['checkout-flow', 'new-dashboard']),
995
+ ]);
996
+ ```
997
+
998
+ `onlyAccessed()` is order-dependent. If you call it before accessing any flags with `isEnabled()` or `getFlag()`, no feature flag properties are attached.
999
+
1000
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
1001
+
1002
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
1003
+
1004
+ PHP
1005
+
1006
+ PostHog AI
1007
+
1008
+ ```php
1009
+ PostHog::capture([
1010
+ 'distinctId' => 'distinct_id_of_your_user',
1011
+ 'event' => 'event_name',
1012
+ 'properties' => [
1013
+ // Replace feature-flag-key with your flag key and 'variant-key' with the key of your variant
1014
+ '$feature/feature-flag-key' => 'variant-key',
1015
+ ],
1016
+ ]);
1017
+ ```
1018
+
1019
+ ### Evaluating only specific flags
1020
+
1021
+ By default, `evaluateFlags()` evaluates every flag for the user. If you only need a few flags, pass `flagKeys` to request only those flags:
1022
+
1023
+ PHP
1024
+
1025
+ PostHog AI
1026
+
1027
+ ```php
1028
+ $flags = PostHog::evaluateFlags(
1029
+ distinctId: 'distinct_id_of_your_user',
1030
+ flagKeys: ['checkout-flow', 'new-dashboard'],
1031
+ );
1032
+ ```
1033
+
1034
+ ### Optional evaluation parameters
1035
+
1036
+ `evaluateFlags()` also accepts optional parameters for local evaluation and GeoIP behavior:
1037
+
1038
+ PHP
1039
+
1040
+ PostHog AI
1041
+
1042
+ ```php
1043
+ $flags = PostHog::evaluateFlags(
1044
+ distinctId: 'distinct_id_of_your_user',
1045
+ groups: ['company' => 'company_id_in_your_db'],
1046
+ personProperties: ['plan' => 'pro'],
1047
+ groupProperties: ['company' => ['employees' => 11]],
1048
+ onlyEvaluateLocally: false, // Defaults to false. Set to true to avoid a remote fallback.
1049
+ disableGeoip: false, // Defaults to false. Set to true to disable GeoIP enrichment during remote evaluation.
1050
+ flagKeys: ['checkout-flow', 'new-dashboard'],
1051
+ );
1052
+ ```
1053
+
1054
+ ### Sending `$feature_flag_called` events
1055
+
1056
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `evaluateFlags()`, the SDK sends this event when you call `$flags->isEnabled()` or `$flags->getFlag()` for a flag.
1057
+
1058
+ The SDK deduplicates these events per `(flag key, distinct_id)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
1059
+
1060
+ `$flags->getFlagPayload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `onlyAccessed()`.
1061
+
1062
+ ### Advanced: Overriding server properties
1063
+
1064
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
1065
+
1066
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
1067
+
1068
+ For example:
1069
+
1070
+ PHP
1071
+
1072
+ PostHog AI
1073
+
1074
+ ```php
1075
+ $flags = PostHog::evaluateFlags(
1076
+ distinctId: 'distinct_id_of_the_user',
1077
+ groups: [
1078
+ 'your_group_type' => 'your_group_id',
1079
+ 'another_group_type' => 'your_group_id',
1080
+ ],
1081
+ personProperties: ['property_name' => 'value'],
1082
+ groupProperties: [
1083
+ 'your_group_type' => ['group_property_name' => 'value'],
1084
+ 'another_group_type' => ['group_property_name' => 'value'],
1085
+ ],
1086
+ );
1087
+ if ($flags->isEnabled('flag-key')) {
1088
+ // Do something differently for this user
1089
+ }
1090
+ ```
1091
+
1092
+ ### Overriding GeoIP properties
1093
+
1094
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
1095
+
1096
+ You can override GeoIP properties by including them in the `person_properties` parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
1097
+
1098
+ The following GeoIP properties can be overridden:
1099
+
1100
+ - `$geoip_country_code`
1101
+ - `$geoip_country_name`
1102
+ - `$geoip_city_name`
1103
+ - `$geoip_city_confidence`
1104
+ - `$geoip_continent_code`
1105
+ - `$geoip_continent_name`
1106
+ - `$geoip_latitude`
1107
+ - `$geoip_longitude`
1108
+ - `$geoip_postal_code`
1109
+ - `$geoip_subdivision_1_code`
1110
+ - `$geoip_subdivision_1_name`
1111
+ - `$geoip_subdivision_2_code`
1112
+ - `$geoip_subdivision_2_name`
1113
+ - `$geoip_subdivision_3_code`
1114
+ - `$geoip_subdivision_3_name`
1115
+ - `$geoip_time_zone`
1116
+
1117
+ Simply include any of these properties in the `person_properties` parameter alongside your other person properties when calling feature flags.
1118
+
1119
+ ### Request timeout
1120
+
1121
+ You can configure the `feature_flag_request_timeout_ms` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked if PostHog's servers are too slow to respond. By default, this is set to 3 seconds.
1122
+
1123
+ PHP
1124
+
1125
+ PostHog AI
1126
+
1127
+ ```php
1128
+ PostHog::init("<ph_project_token>",
1129
+ [
1130
+ 'host' => 'https://us.i.posthog.com',
1131
+ 'feature_flag_request_timeout_ms' => 3000, // Time in milliseconds. Defaults to 3000 (3 seconds).
1132
+ ]
1133
+ );
1134
+ ```
1135
+
1136
+ ## Ruby
1137
+
1138
+ There are two steps to implement feature flags in Ruby:
1139
+
1140
+ ### Step 1: Evaluate flags once
1141
+
1142
+ Call `posthog.evaluate_flags()` once for the user, then read values from the returned snapshot.
1143
+
1144
+ #### Boolean feature flags
1145
+
1146
+ Ruby
1147
+
1148
+ PostHog AI
1149
+
1150
+ ```ruby
1151
+ flags = posthog.evaluate_flags('distinct_id_of_your_user')
1152
+ if flags.enabled?('flag-key')
1153
+ # Do something differently for this user
1154
+ # Optional: fetch the payload
1155
+ matched_flag_payload = flags.get_flag_payload('flag-key')
1156
+ end
1157
+ ```
1158
+
1159
+ #### Multivariate feature flags
1160
+
1161
+ Ruby
1162
+
1163
+ PostHog AI
1164
+
1165
+ ```ruby
1166
+ flags = posthog.evaluate_flags('distinct_id_of_your_user')
1167
+ enabled_variant = flags.get_flag('flag-key')
1168
+ if enabled_variant == 'variant-key' # replace 'variant-key' with the key of your variant
1169
+ # Do something differently for this user
1170
+ # Optional: fetch the payload
1171
+ matched_flag_payload = flags.get_flag_payload('flag-key')
1172
+ end
1173
+ ```
1174
+
1175
+ `flags.get_flag()` returns the variant string for multivariate flags, `true` for enabled boolean flags, `false` for disabled flags, and `nil` when the flag wasn't returned by the evaluation.
1176
+
1177
+ > **Note:** `posthog.is_feature_enabled()`, `posthog.get_feature_flag()`, `posthog.get_feature_flag_result()`, `posthog.get_feature_flag_payload()`, and `capture({ ..., send_feature_flags: true })` still work during the migration period, but they're deprecated. Prefer `evaluate_flags()` for new code.
1178
+
1179
+ ### Step 2: Include feature flag information when capturing events
1180
+
1181
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
1182
+
1183
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
1184
+
1185
+ There are two methods you can use to include feature flag information in your events:
1186
+
1187
+ #### Method 1: Pass the evaluated flags snapshot to `capture()`
1188
+
1189
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
1190
+
1191
+ Ruby
1192
+
1193
+ PostHog AI
1194
+
1195
+ ```ruby
1196
+ flags = posthog.evaluate_flags('distinct_id_of_your_user')
1197
+ if flags.enabled?('flag-key')
1198
+ # Do something differently for this user
1199
+ end
1200
+ posthog.capture({
1201
+ distinct_id: 'distinct_id_of_your_user',
1202
+ event: 'event_name',
1203
+ flags: flags,
1204
+ })
1205
+ ```
1206
+
1207
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
1208
+
1209
+ To reduce event property bloat, pass a filtered snapshot:
1210
+
1211
+ Ruby
1212
+
1213
+ PostHog AI
1214
+
1215
+ ```ruby
1216
+ # Attach only flags accessed with enabled?() or get_flag() before this call
1217
+ posthog.capture({
1218
+ distinct_id: 'distinct_id_of_your_user',
1219
+ event: 'event_name',
1220
+ flags: flags.only_accessed,
1221
+ })
1222
+ # Attach only specific flags
1223
+ posthog.capture({
1224
+ distinct_id: 'distinct_id_of_your_user',
1225
+ event: 'event_name',
1226
+ flags: flags.only(['checkout-flow', 'new-dashboard']),
1227
+ })
1228
+ ```
1229
+
1230
+ `only_accessed` is order-dependent. If you call it before accessing any flags with `enabled?()` or `get_flag()`, no feature flag properties are attached.
1231
+
1232
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
1233
+
1234
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
1235
+
1236
+ Ruby
1237
+
1238
+ PostHog AI
1239
+
1240
+ ```ruby
1241
+ posthog.capture({
1242
+ distinct_id: 'distinct_id_of_your_user',
1243
+ event: 'event_name',
1244
+ properties: {
1245
+ # Replace feature-flag-key with your flag key and 'variant-key' with the key of your variant
1246
+ '$feature/feature-flag-key': 'variant-key',
1247
+ },
1248
+ })
1249
+ ```
1250
+
1251
+ ### Evaluating only specific flags
1252
+
1253
+ By default, `evaluate_flags()` evaluates every flag for the user. If you only need a few flags, pass `flag_keys` to request only those flags:
1254
+
1255
+ Ruby
1256
+
1257
+ PostHog AI
1258
+
1259
+ ```ruby
1260
+ flags = posthog.evaluate_flags(
1261
+ 'distinct_id_of_your_user',
1262
+ flag_keys: ['checkout-flow', 'new-dashboard'],
1263
+ )
1264
+ ```
1265
+
1266
+ ### Evaluating locally only
1267
+
1268
+ If you want to skip the remote `/flags` request and only use locally cached definitions, pass `only_evaluate_locally: true`:
1269
+
1270
+ Ruby
1271
+
1272
+ PostHog AI
1273
+
1274
+ ```ruby
1275
+ flags = posthog.evaluate_flags(
1276
+ 'distinct_id_of_your_user',
1277
+ only_evaluate_locally: true,
1278
+ )
1279
+ ```
1280
+
1281
+ ### Disabling GeoIP for flag evaluation
1282
+
1283
+ Pass `disable_geoip: true` to disable GeoIP lookup for remote flag evaluation:
1284
+
1285
+ Ruby
1286
+
1287
+ PostHog AI
1288
+
1289
+ ```ruby
1290
+ flags = posthog.evaluate_flags(
1291
+ 'distinct_id_of_your_user',
1292
+ disable_geoip: true,
1293
+ )
1294
+ ```
1295
+
1296
+ ### Sending `$feature_flag_called` events
1297
+
1298
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `evaluate_flags()`, the SDK sends this event when you call `flags.enabled?()` or `flags.get_flag()` for a flag.
1299
+
1300
+ The SDK deduplicates these events per `(distinct_id, flag, value)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
1301
+
1302
+ `flags.get_flag_payload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `only_accessed`.
1303
+
1304
+ ### Advanced: Overriding server properties
1305
+
1306
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
1307
+
1308
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
1309
+
1310
+ For example:
1311
+
1312
+ Ruby
1313
+
1314
+ PostHog AI
1315
+
1316
+ ```ruby
1317
+ flags = posthog.evaluate_flags(
1318
+ 'distinct_id_of_the_user',
1319
+ person_properties: {
1320
+ property_name: 'value'
1321
+ },
1322
+ groups: {
1323
+ your_group_type: 'your_group_id',
1324
+ another_group_type: 'your_group_id',
1325
+ },
1326
+ group_properties: {
1327
+ your_group_type: {
1328
+ group_property_name: 'value'
1329
+ },
1330
+ another_group_type: {
1331
+ group_property_name: 'value'
1332
+ },
1333
+ },
1334
+ )
1335
+ if flags.enabled?('flag-key')
1336
+ # Do something differently for this user
1337
+ end
1338
+ ```
1339
+
1340
+ ### Overriding GeoIP properties
1341
+
1342
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
1343
+
1344
+ You can override GeoIP properties by including them in the `person_properties` parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
1345
+
1346
+ The following GeoIP properties can be overridden:
1347
+
1348
+ - `$geoip_country_code`
1349
+ - `$geoip_country_name`
1350
+ - `$geoip_city_name`
1351
+ - `$geoip_city_confidence`
1352
+ - `$geoip_continent_code`
1353
+ - `$geoip_continent_name`
1354
+ - `$geoip_latitude`
1355
+ - `$geoip_longitude`
1356
+ - `$geoip_postal_code`
1357
+ - `$geoip_subdivision_1_code`
1358
+ - `$geoip_subdivision_1_name`
1359
+ - `$geoip_subdivision_2_code`
1360
+ - `$geoip_subdivision_2_name`
1361
+ - `$geoip_subdivision_3_code`
1362
+ - `$geoip_subdivision_3_name`
1363
+ - `$geoip_time_zone`
1364
+
1365
+ Simply include any of these properties in the `person_properties` parameter alongside your other person properties when calling feature flags.
1366
+
1367
+ ### Request timeout
1368
+
1369
+ You can configure the `feature_flag_request_timeout_seconds` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked if PostHog's servers are too slow to respond. By default, this is set to 3 seconds.
1370
+
1371
+ Ruby
1372
+
1373
+ PostHog AI
1374
+
1375
+ ```ruby
1376
+ posthog = PostHog::Client.new({
1377
+ # rest of your configuration...
1378
+ feature_flag_request_timeout_seconds: 3 # Time in seconds. Defaults to 3.
1379
+ })
1380
+ ```
1381
+
1382
+ ## Go
1383
+
1384
+ There are two steps to implement feature flags in Go:
1385
+
1386
+ ### Step 1: Evaluate flags once
1387
+
1388
+ Call `client.EvaluateFlags()` once for the user, then read values from the returned snapshot.
1389
+
1390
+ #### Boolean feature flags
1391
+
1392
+ Go
1393
+
1394
+ PostHog AI
1395
+
1396
+ ```go
1397
+ flags, err := client.EvaluateFlags(posthog.EvaluateFlagsPayload{
1398
+ DistinctId: "distinct_id_of_your_user",
1399
+ })
1400
+ if err != nil {
1401
+ // Handle error (e.g. capture error and fallback to default behavior)
1402
+ }
1403
+ if flags.IsEnabled("flag-key") {
1404
+ // Do something differently for this user
1405
+ // Optional: fetch the payload
1406
+ matchedFlagPayload := flags.GetFlagPayload("flag-key")
1407
+ }
1408
+ ```
1409
+
1410
+ #### Multivariate feature flags
1411
+
1412
+ Go
1413
+
1414
+ PostHog AI
1415
+
1416
+ ```go
1417
+ flags, err := client.EvaluateFlags(posthog.EvaluateFlagsPayload{
1418
+ DistinctId: "distinct_id_of_your_user",
1419
+ })
1420
+ if err != nil {
1421
+ // Handle error (e.g. capture error and fallback to default behavior)
1422
+ }
1423
+ enabledVariant := flags.GetFlag("flag-key")
1424
+ if enabledVariant == "variant-key" { // replace "variant-key" with the key of your variant
1425
+ // Do something differently for this user
1426
+ // Optional: fetch the payload
1427
+ matchedFlagPayload := flags.GetFlagPayload("flag-key")
1428
+ }
1429
+ ```
1430
+
1431
+ `flags.GetFlag()` returns the variant string for multivariate flags, `true` for enabled boolean flags, `false` for disabled flags, and `nil` when the flag wasn't returned by the evaluation.
1432
+
1433
+ > **Note:** `client.IsFeatureEnabled()`, `client.GetFeatureFlag()`, `client.GetFeatureFlagPayload()`, and `Capture.SendFeatureFlags` still work during the migration period, but they're deprecated. Prefer `EvaluateFlags()` for new code.
1434
+
1435
+ ### Step 2: Include feature flag information when capturing events
1436
+
1437
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
1438
+
1439
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
1440
+
1441
+ There are two methods you can use to include feature flag information in your events:
1442
+
1443
+ #### Method 1: Pass the evaluated flags snapshot to `Capture`
1444
+
1445
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
1446
+
1447
+ Go
1448
+
1449
+ PostHog AI
1450
+
1451
+ ```go
1452
+ flags, err := client.EvaluateFlags(posthog.EvaluateFlagsPayload{
1453
+ DistinctId: "distinct_id_of_your_user",
1454
+ })
1455
+ if err != nil {
1456
+ // Handle error
1457
+ }
1458
+ if flags.IsEnabled("flag-key") {
1459
+ // Do something differently for this user
1460
+ }
1461
+ client.Enqueue(posthog.Capture{
1462
+ DistinctId: "distinct_id_of_your_user",
1463
+ Event: "event_name",
1464
+ Flags: flags,
1465
+ })
1466
+ ```
1467
+
1468
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
1469
+
1470
+ To reduce event property bloat, pass a filtered snapshot:
1471
+
1472
+ Go
1473
+
1474
+ PostHog AI
1475
+
1476
+ ```go
1477
+ // Attach only flags accessed with IsEnabled() or GetFlag() before this call
1478
+ client.Enqueue(posthog.Capture{
1479
+ DistinctId: "distinct_id_of_your_user",
1480
+ Event: "event_name",
1481
+ Flags: flags.OnlyAccessed(),
1482
+ })
1483
+ // Attach only specific flags
1484
+ client.Enqueue(posthog.Capture{
1485
+ DistinctId: "distinct_id_of_your_user",
1486
+ Event: "event_name",
1487
+ Flags: flags.Only([]string{"checkout-flow", "new-dashboard"}),
1488
+ })
1489
+ ```
1490
+
1491
+ `OnlyAccessed()` is order-dependent. If you call it before accessing any flags with `IsEnabled()` or `GetFlag()`, no feature flag properties are attached.
1492
+
1493
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
1494
+
1495
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
1496
+
1497
+ Go
1498
+
1499
+ PostHog AI
1500
+
1501
+ ```go
1502
+ client.Enqueue(posthog.Capture{
1503
+ DistinctId: "distinct_id_of_your_user",
1504
+ Event: "event_name",
1505
+ Properties: posthog.NewProperties().
1506
+ Set("$feature/feature-flag-key", "variant-key"), // replace feature-flag-key with your flag key. Replace "variant-key" with the key of your variant
1507
+ })
1508
+ ```
1509
+
1510
+ ### Evaluating only specific flags
1511
+
1512
+ By default, `EvaluateFlags()` evaluates every flag for the user. If you only need a few flags, pass `FlagKeys` to request only those flags:
1513
+
1514
+ Go
1515
+
1516
+ PostHog AI
1517
+
1518
+ ```go
1519
+ flags, err := client.EvaluateFlags(posthog.EvaluateFlagsPayload{
1520
+ DistinctId: "distinct_id_of_your_user",
1521
+ FlagKeys: []string{"checkout-flow", "new-dashboard"},
1522
+ })
1523
+ ```
1524
+
1525
+ ### Sending `$feature_flag_called` events
1526
+
1527
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `EvaluateFlags()`, the SDK sends this event when you call `flags.IsEnabled()` or `flags.GetFlag()` for a flag.
1528
+
1529
+ The SDK deduplicates these events per `(distinct_id, flag, value)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
1530
+
1531
+ `flags.GetFlagPayload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `OnlyAccessed()`.
1532
+
1533
+ ### Advanced: Overriding server properties
1534
+
1535
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
1536
+
1537
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
1538
+
1539
+ For example:
1540
+
1541
+ Go
1542
+
1543
+ PostHog AI
1544
+
1545
+ ```go
1546
+ flags, err := client.EvaluateFlags(posthog.EvaluateFlagsPayload{
1547
+ DistinctId: "distinct_id_of_the_user",
1548
+ Groups: posthog.NewGroups().
1549
+ Set("your_group_type", "your_group_id").
1550
+ Set("another_group_type", "your_group_id"),
1551
+ PersonProperties: posthog.NewProperties().
1552
+ Set("property_name", "value"),
1553
+ GroupProperties: map[string]posthog.Properties{
1554
+ "your_group_type": posthog.NewProperties().
1555
+ Set("group_property_name", "value"),
1556
+ "another_group_type": posthog.NewProperties().
1557
+ Set("group_property_name", "value"),
1558
+ },
1559
+ })
1560
+ if err != nil {
1561
+ // Handle error
1562
+ }
1563
+ if flags.IsEnabled("flag-key") {
1564
+ // Do something differently for this user
1565
+ }
1566
+ ```
1567
+
1568
+ ### Overriding GeoIP properties
1569
+
1570
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
1571
+
1572
+ You can override GeoIP properties by including them in the `person_properties` parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
1573
+
1574
+ The following GeoIP properties can be overridden:
1575
+
1576
+ - `$geoip_country_code`
1577
+ - `$geoip_country_name`
1578
+ - `$geoip_city_name`
1579
+ - `$geoip_city_confidence`
1580
+ - `$geoip_continent_code`
1581
+ - `$geoip_continent_name`
1582
+ - `$geoip_latitude`
1583
+ - `$geoip_longitude`
1584
+ - `$geoip_postal_code`
1585
+ - `$geoip_subdivision_1_code`
1586
+ - `$geoip_subdivision_1_name`
1587
+ - `$geoip_subdivision_2_code`
1588
+ - `$geoip_subdivision_2_name`
1589
+ - `$geoip_subdivision_3_code`
1590
+ - `$geoip_subdivision_3_name`
1591
+ - `$geoip_time_zone`
1592
+
1593
+ Simply include any of these properties in the `person_properties` parameter alongside your other person properties when calling feature flags.
1594
+
1595
+ ### Request timeout
1596
+
1597
+ You can configure the `FeatureFlagRequestTimeout` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked if PostHog's servers are too slow to respond. By default, this is set to 3 seconds.
1598
+
1599
+ Go
1600
+
1601
+ PostHog AI
1602
+
1603
+ ```go
1604
+ // import "time"
1605
+ client, _ := posthog.NewWithConfig(
1606
+ os.Getenv("<ph_project_token>"),
1607
+ posthog.Config{
1608
+ PersonalApiKey: "your personal API key", // Optional, but much more performant. If this token is not supplied, then fetching feature flag values will be slower.
1609
+ Endpoint: "https://us.i.posthog.com",
1610
+ FeatureFlagRequestTimeout: 3 * time.Second, // Defaults to 3 seconds.
1611
+ },
1612
+ )
1613
+ ```
1614
+
1615
+ ## React Native
1616
+
1617
+ There are two ways to implement feature flags in React Native:
1618
+
1619
+ 1. Using hooks.
1620
+ 2. Loading the flag directly.
1621
+
1622
+ ### Method 1: Using hooks
1623
+
1624
+ #### Example 1: Boolean feature flags
1625
+
1626
+ React Native
1627
+
1628
+ PostHog AI
1629
+
1630
+ ```jsx
1631
+ import { useFeatureFlag } from 'posthog-react-native'
1632
+ const MyComponent = () => {
1633
+ const booleanFlag = useFeatureFlag('key-for-your-boolean-flag')
1634
+ if (booleanFlag === undefined) {
1635
+ // the response is undefined if the flags are being loaded
1636
+ return null
1637
+ }
1638
+ // Optional use the 'useFeatureFlagWithPayload' hook for fetching the feature flag payload
1639
+ return booleanFlag ? <Text>Testing feature 😄</Text> : <Text>Not Testing feature 😢</Text>
1640
+ }
1641
+ ```
1642
+
1643
+ #### Example 2: Multivariate feature flags
1644
+
1645
+ React Native
1646
+
1647
+ PostHog AI
1648
+
1649
+ ```jsx
1650
+ import { useFeatureFlag } from 'posthog-react-native'
1651
+ const MyComponent = () => {
1652
+ const multiVariantFeature = useFeatureFlag('key-for-your-multivariate-flag')
1653
+ if (multiVariantFeature === undefined) {
1654
+ // the response is undefined if the flags are being loaded
1655
+ return null
1656
+ } else if (multiVariantFeature === 'variant-name') { // replace 'variant-name' with the name of your variant
1657
+ // Do something
1658
+ }
1659
+ // Optional use the 'useFeatureFlagWithPayload' hook for fetching the feature flag payload
1660
+ return <div/>
1661
+ }
1662
+ ```
1663
+
1664
+ ### Method 2: Loading the flag directly
1665
+
1666
+ React Native
1667
+
1668
+ PostHog AI
1669
+
1670
+ ```jsx
1671
+ // Defaults to undefined if not loaded yet or if there was a problem loading
1672
+ posthog.isFeatureEnabled('key-for-your-boolean-flag')
1673
+ // Defaults to undefined if not loaded yet or if there was a problem loading
1674
+ posthog.getFeatureFlag('key-for-your-boolean-flag')
1675
+ // Multivariant feature flags are returned as a string
1676
+ posthog.getFeatureFlag('key-for-your-multivariate-flag')
1677
+ // Optional: fetch the payload (returns 'JsonType' or undefined if not loaded yet or if there was a problem loading)
1678
+ posthog.getFeatureFlagResult('key-for-your-multivariate-flag')?.payload
1679
+ ```
1680
+
1681
+ ### Inspecting all feature flags
1682
+
1683
+ You can inspect all currently loaded feature flags with `getAllFeatureFlags()`. It returns each flag's `key`, `enabled` state, `variant`, and `payload`, and does not send a `$feature_flag_called` event, so calling it won't affect your experiment results or flag usage analytics:
1684
+
1685
+ React Native
1686
+
1687
+ PostHog AI
1688
+
1689
+ ```jsx
1690
+ for (const flag of posthog.getAllFeatureFlags()) {
1691
+ console.log(flag.key, flag.enabled, flag.variant, flag.payload)
1692
+ }
1693
+ ```
1694
+
1695
+ ### Ensuring flags are loaded before usage
1696
+
1697
+ Every time a user opens the app, we send a request in the background to fetch the feature flags that apply to that user. We store those flags in the storage.
1698
+
1699
+ This means that for most screens, the feature flags are available immediately — **except for the first time a user visits**.
1700
+
1701
+ To handle this, you can use the `onFeatureFlags` callback to wait for the feature flag request to finish:
1702
+
1703
+ React Native
1704
+
1705
+ PostHog AI
1706
+
1707
+ ```jsx
1708
+ posthog.onFeatureFlags((flags) => {
1709
+ // feature flags are guaranteed to be available at this point
1710
+ if (posthog.isFeatureEnabled('flag-key')) {
1711
+ // do something
1712
+ }
1713
+ })
1714
+ ```
1715
+
1716
+ ### Reloading flags
1717
+
1718
+ PostHog loads feature flags when instantiated and refreshes whenever methods are called that affect the flag.
1719
+
1720
+ If want to manually trigger a refresh, you can call `reloadFeatureFlagsAsync()`:
1721
+
1722
+ React Native
1723
+
1724
+ PostHog AI
1725
+
1726
+ ```jsx
1727
+ posthog.reloadFeatureFlagsAsync().then((refreshedFlags) => console.log(refreshedFlags))
1728
+ ```
1729
+
1730
+ Or when you want to trigger the reload, but don't care about the result:
1731
+
1732
+ React Native
1733
+
1734
+ PostHog AI
1735
+
1736
+ ```jsx
1737
+ posthog.reloadFeatureFlags()
1738
+ ```
1739
+
1740
+ ### Feature flag caching
1741
+
1742
+ The React Native SDK caches feature flag values in AsyncStorage. Cached values persist indefinitely with no TTL until updated by a successful API call. This enables offline support and reduces latency, but means **inactive users may see stale flag values** from their last session.
1743
+
1744
+ For example, if a user last opened your app when a flag was `false`, that value remains cached even after you roll it out to 100%. When they reopen the app, the SDK returns the cached `false` first, then fetches the fresh `true` value from the API.
1745
+
1746
+ To ensure fresh flag values:
1747
+
1748
+ React Native
1749
+
1750
+ PostHog AI
1751
+
1752
+ ```jsx
1753
+ // Force refresh on app start
1754
+ await posthog.reloadFeatureFlagsAsync()
1755
+ ```
1756
+
1757
+ Or clear cached values for inactive users:
1758
+
1759
+ React Native
1760
+
1761
+ PostHog AI
1762
+
1763
+ ```jsx
1764
+ if (lastActiveDate < migrationDate) {
1765
+ posthog.reset() // Clears all cached data
1766
+ }
1767
+ ```
1768
+
1769
+ ### Request timeout
1770
+
1771
+ You can configure the `featureFlagsRequestTimeoutMs` parameter when initializing your PostHog client to set a flag request timeout. This helps prevent your code from being blocked in the case when PostHog's servers are too slow to respond. By default, this is set at 10 seconds.
1772
+
1773
+ React Native
1774
+
1775
+ PostHog AI
1776
+
1777
+ ```jsx
1778
+ export const posthog = new PostHog('<ph_project_token>', {
1779
+ // usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com'
1780
+ host: 'https://us.i.posthog.com',
1781
+ featureFlagsRequestTimeoutMs: 10000 // Time in milliseconds. Default is 10000 (10 seconds).
1782
+ })
1783
+ ```
1784
+
1785
+ ### Error handling
1786
+
1787
+ When using the PostHog SDK, it's important to handle potential errors that may occur during feature flag operations. Here's an example of how to wrap PostHog SDK methods in an error handler:
1788
+
1789
+ React Native
1790
+
1791
+ PostHog AI
1792
+
1793
+ ```jsx
1794
+ function handleFeatureFlag(client, flagKey, distinctId) {
1795
+ try {
1796
+ const isEnabled = client.isFeatureEnabled(flagKey, distinctId);
1797
+ console.log(`Feature flag '${flagKey}' for user '${distinctId}' is ${isEnabled ? 'enabled' : 'disabled'}`);
1798
+ return isEnabled;
1799
+ } catch (error) {
1800
+ console.error(`Error fetching feature flag '${flagKey}': ${error.message}`);
1801
+ // Optionally, you can return a default value or throw the error
1802
+ // return false; // Default to disabled
1803
+ throw error;
1804
+ }
1805
+ }
1806
+ // Usage example
1807
+ try {
1808
+ const flagEnabled = handleFeatureFlag(client, 'new-feature', 'user-123');
1809
+ if (flagEnabled) {
1810
+ // Implement new feature logic
1811
+ } else {
1812
+ // Implement old feature logic
1813
+ }
1814
+ } catch (error) {
1815
+ // Handle the error at a higher level
1816
+ console.error('Feature flag check failed, using default behavior');
1817
+ // Implement fallback logic
1818
+ }
1819
+ ```
1820
+
1821
+ ### Overriding server properties
1822
+
1823
+ Sometimes, you might want to evaluate feature flags using properties that haven't been ingested yet, or were set incorrectly earlier. You can do so by setting properties the flag depends on with these calls:
1824
+
1825
+ React Native
1826
+
1827
+ PostHog AI
1828
+
1829
+ ```jsx
1830
+ posthog.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'})
1831
+ ```
1832
+
1833
+ Note that these are set for the entire session. Successive calls are additive: all properties you set are combined together and sent for flag evaluation.
1834
+
1835
+ Whenever you set these properties, we also trigger a reload of feature flags to ensure we have the latest values. You can disable this by passing in the optional parameter for reloading:
1836
+
1837
+ React Native
1838
+
1839
+ PostHog AI
1840
+
1841
+ ```jsx
1842
+ posthog.setPersonPropertiesForFlags({'property1': 'value', property2: 'value2'}, false)
1843
+ ```
1844
+
1845
+ At any point, you can reset these properties by calling `resetPersonPropertiesForFlags`:
1846
+
1847
+ React Native
1848
+
1849
+ PostHog AI
1850
+
1851
+ ```jsx
1852
+ posthog.resetPersonPropertiesForFlags()
1853
+ ```
1854
+
1855
+ The same holds for [group](/docs/product-analytics/group-analytics.md) properties:
1856
+
1857
+ React Native
1858
+
1859
+ PostHog AI
1860
+
1861
+ ```jsx
1862
+ // set properties for a group
1863
+ posthog.setGroupPropertiesForFlags({'company': {'property1': 'value', property2: 'value2'}})
1864
+ // reset properties for all groups:
1865
+ posthog.resetGroupPropertiesForFlags()
1866
+ ```
1867
+
1868
+ > **Note:** You don't need to add the group names here, since these properties are automatically attached to the current group (set via `posthog.group()`). When you change the group, these properties are reset.
1869
+
1870
+ **Automatic overrides**
1871
+
1872
+ Whenever you call `posthog.identify` with person properties, we automatically add these properties to flag evaluation calls to help determine the correct flag values. The same is true for when you call `posthog.group()`.
1873
+
1874
+ **Default overridden properties**
1875
+
1876
+ By default, we always override some properties based on the user IP address.
1877
+
1878
+ The list of properties that this overrides:
1879
+
1880
+ 1. $geoip\_city\_name
1881
+ 2. $geoip\_country\_name
1882
+ 3. $geoip\_country\_code
1883
+ 4. $geoip\_continent\_name
1884
+ 5. $geoip\_continent\_code
1885
+ 6. $geoip\_postal\_code
1886
+ 7. $geoip\_time\_zone
1887
+
1888
+ This enables any geolocation-based flags to work without manually setting these properties.
1889
+
1890
+ ## Android
1891
+
1892
+ ### Boolean feature flags
1893
+
1894
+ Kotlin
1895
+
1896
+ PostHog AI
1897
+
1898
+ ```kotlin
1899
+ import com.posthog.PostHog
1900
+ val result = PostHog.getFeatureFlagResult("flag-key")
1901
+ if (result?.enabled == true) {
1902
+ // Do something differently for this user
1903
+ // Optional: fetch the payload from the same evaluation result
1904
+ val matchedFlagPayload = result.payload
1905
+ }
1906
+ ```
1907
+
1908
+ ### Multivariate feature flags
1909
+
1910
+ Kotlin
1911
+
1912
+ PostHog AI
1913
+
1914
+ ```kotlin
1915
+ import com.posthog.PostHog
1916
+ val result = PostHog.getFeatureFlagResult("flag-key")
1917
+ if (result?.variant == "variant-key") { // replace "variant-key" with the key of your variant
1918
+ // Do something differently for this user
1919
+ // Optional: fetch the payload from the same evaluation result
1920
+ val matchedFlagPayload = result.payload
1921
+ }
1922
+ ```
1923
+
1924
+ ### Inspecting all feature flags
1925
+
1926
+ You can inspect all currently loaded feature flags with `PostHog.getAllFeatureFlags()`. It returns each flag's `key`, `enabled` state, `variant`, and `payload`, and does not send a `$feature_flag_called` event, so calling it won't affect your experiment results or flag usage analytics:
1927
+
1928
+ Kotlin
1929
+
1930
+ PostHog AI
1931
+
1932
+ ```kotlin
1933
+ import com.posthog.PostHog
1934
+ PostHog.getAllFeatureFlags()?.forEach { flag ->
1935
+ println("${flag.key} ${flag.enabled} ${flag.variant} ${flag.payload}")
1936
+ }
1937
+ ```
1938
+
1939
+ ### Ensuring flags are loaded before usage
1940
+
1941
+ Every time a user opens the app, we send a request in the background to fetch the feature flags that apply to that user. We store those flags in the storage.
1942
+
1943
+ This means that for most screens, the feature flags are available immediately – **except for the first time a user visits**.
1944
+
1945
+ To handle this, you can use the `onFeatureFlags` callback to wait for the feature flag request to finish:
1946
+
1947
+ Kotlin
1948
+
1949
+ PostHog AI
1950
+
1951
+ ```kotlin
1952
+ import com.posthog.PostHog
1953
+ import com.posthog.android.PostHogAndroidConfig
1954
+ import com.posthog.PostHogOnFeatureFlags
1955
+ // During SDK initialization
1956
+ val config = PostHogAndroidConfig(apiKey = "<ph_project_token>").apply {
1957
+ onFeatureFlags = PostHogOnFeatureFlags {
1958
+ if (PostHog.isFeatureEnabled("flag-key")) {
1959
+ // do something
1960
+ }
1961
+ }
1962
+ }
1963
+ // And/or after the SDK is initialized
1964
+ PostHog.reloadFeatureFlags {
1965
+ if (PostHog.isFeatureEnabled("flag-key")) {
1966
+ // do something
1967
+ }
1968
+ }
1969
+ ```
1970
+
1971
+ ### Reloading feature flags
1972
+
1973
+ Feature flag values are cached. If something has changed with your user and you'd like to refetch their flag values, call:
1974
+
1975
+ Kotlin
1976
+
1977
+ PostHog AI
1978
+
1979
+ ```kotlin
1980
+ import com.posthog.PostHog
1981
+ PostHog.reloadFeatureFlags()
1982
+ ```
1983
+
1984
+ ### Tracking feature usage
1985
+
1986
+ To track when someone sees or interacts with a feature, use `captureFeatureView` and `captureFeatureInteraction`.
1987
+
1988
+ Kotlin
1989
+
1990
+ PostHog AI
1991
+
1992
+ ```kotlin
1993
+ import com.posthog.PostHog
1994
+ PostHog.captureFeatureView("flag-key", flagVariant = "variant-key")
1995
+ PostHog.captureFeatureInteraction("flag-key", flagVariant = "variant-key")
1996
+ ```
1997
+
1998
+ ## iOS
1999
+
2000
+ ### Boolean feature flags
2001
+
2002
+ Swift
2003
+
2004
+ PostHog AI
2005
+
2006
+ ```swift
2007
+ if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"), result.enabled {
2008
+ // Do something differently for this user
2009
+ // Optional: fetch the payload from the same evaluation result
2010
+ let matchedFlagPayload = result.payload
2011
+ }
2012
+ ```
2013
+
2014
+ ### Multivariate feature flags
2015
+
2016
+ Swift
2017
+
2018
+ PostHog AI
2019
+
2020
+ ```swift
2021
+ if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"), result.variant == "variant-key" { // replace "variant-key" with the key of your variant
2022
+ // Do something differently for this user
2023
+ // Optional: fetch the payload from the same evaluation result
2024
+ let matchedFlagPayload = result.payload
2025
+ }
2026
+ ```
2027
+
2028
+ ### Typed payloads
2029
+
2030
+ If your payload is a JSON object, you can decode it into a `Decodable` type:
2031
+
2032
+ Swift
2033
+
2034
+ PostHog AI
2035
+
2036
+ ```swift
2037
+ struct FlagPayload: Decodable {
2038
+ let title: String
2039
+ }
2040
+ if let result = PostHogSDK.shared.getFeatureFlagResult("flag-key"),
2041
+ let payload = result.payloadAs(FlagPayload.self) {
2042
+ // Use payload.title
2043
+ }
2044
+ ```
2045
+
2046
+ ### Inspecting all feature flags
2047
+
2048
+ You can inspect all currently loaded feature flags with `getAllFeatureFlags()`. It returns each flag's `key`, `enabled` state, `variant`, and `payload`, and does not send a `$feature_flag_called` event, so calling it won't affect your experiment results or flag usage analytics:
2049
+
2050
+ Swift
2051
+
2052
+ PostHog AI
2053
+
2054
+ ```swift
2055
+ for flag in PostHogSDK.shared.getAllFeatureFlags() ?? [] {
2056
+ print(flag.key, flag.enabled, flag.variant as Any, flag.payload as Any)
2057
+ }
2058
+ ```
2059
+
2060
+ ### Reloading feature flags
2061
+
2062
+ Feature flag values are cached. If something has changed with your user and you'd like to refetch their flag values, call:
2063
+
2064
+ Swift
2065
+
2066
+ PostHog AI
2067
+
2068
+ ```swift
2069
+ PostHogSDK.shared.reloadFeatureFlags()
2070
+ ```
2071
+
2072
+ ### Ensuring flags are loaded before usage
2073
+
2074
+ Every time a user opens the app, we send a request in the background to fetch the feature flags that apply to that user. We store those flags in the storage.
2075
+
2076
+ This means that for most screens, the feature flags are available immediately – **except for the first time a user visits**.
2077
+
2078
+ To handle this, you can use the `didReceiveFeatureFlags` notification to wait for the feature flag request to finish:
2079
+
2080
+ Swift
2081
+
2082
+ PostHog AI
2083
+
2084
+ ```swift
2085
+ class AppDelegate: NSObject, UIApplicationDelegate {
2086
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
2087
+ // register for `didReceiveFeatureFlags` notification before SDK initialization
2088
+ NotificationCenter.default.addObserver(
2089
+ self,
2090
+ selector: #selector(receiveFeatureFlags),
2091
+ name: PostHogSDK.didReceiveFeatureFlags,
2092
+ object: nil
2093
+ )
2094
+ let POSTHOG_PROJECT_TOKEN = "<ph_project_token>"
2095
+ // usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com'
2096
+ let POSTHOG_HOST = "https://us.i.posthog.com"
2097
+ let config = PostHogConfig(projectToken: POSTHOG_PROJECT_TOKEN, host: POSTHOG_HOST)
2098
+ PostHogSDK.shared.setup(config)
2099
+ return true
2100
+ }
2101
+ // The "receiveFeatureFlags" method will be called when the SDK receives the feature flags from the server.
2102
+ @objc func receiveFeatureFlags() {
2103
+ print("receiveFeatureFlags called")
2104
+ }
2105
+ }
2106
+ ```
2107
+
2108
+ Alternatively, you can use the completion block of the `reloadFeatureFlags(_:)` method. This allows you to execute logic immediately after the flags are reloaded:
2109
+
2110
+ Swift
2111
+
2112
+ PostHog AI
2113
+
2114
+ ```swift
2115
+ // Reload feature flags and check if a specific feature is enabled
2116
+ PostHogSDK.shared.reloadFeatureFlags {
2117
+ if PostHogSDK.shared.isFeatureEnabled("flag-key") {
2118
+ // do something
2119
+ }
2120
+ }
2121
+ ```
2122
+
2123
+ ### Tracking feature usage
2124
+
2125
+ To track when someone sees or interacts with a feature, use `captureFeatureView` and `captureFeatureInteraction`.
2126
+
2127
+ Swift
2128
+
2129
+ PostHog AI
2130
+
2131
+ ```swift
2132
+ PostHogSDK.shared.captureFeatureView(flag: "flag-key", flagVariant: "variant-key")
2133
+ PostHogSDK.shared.captureFeatureInteraction(flag: "flag-key", flagVariant: "variant-key")
2134
+ ```
2135
+
2136
+ ## Flutter
2137
+
2138
+ ### Boolean feature flags
2139
+
2140
+ Dart
2141
+
2142
+ PostHog AI
2143
+
2144
+ ```dart
2145
+ final result = await Posthog().getFeatureFlagResult('flag-key');
2146
+ if (result != null && result.enabled) {
2147
+ // Do something differently for this user
2148
+ // Optional: fetch the payload from the same evaluation result
2149
+ final matchedFlagPayload = result.payload;
2150
+ }
2151
+ ```
2152
+
2153
+ ### Multivariate feature flags
2154
+
2155
+ Dart
2156
+
2157
+ PostHog AI
2158
+
2159
+ ```dart
2160
+ final result = await Posthog().getFeatureFlagResult('flag-key');
2161
+ if (result != null && result.variant == 'variant-key') { // replace 'variant-key' with the key of your variant
2162
+ // Do something differently for this user
2163
+ // Optional: fetch the payload from the same evaluation result
2164
+ final matchedFlagPayload = result.payload;
2165
+ }
2166
+ ```
2167
+
2168
+ ### Ensuring flags are loaded before usage
2169
+
2170
+ > To use the `onFeatureFlags` callback, you must [set up the SDK manually](#installation). On Android and iOS, disable `com.posthog.posthog.AUTO_INIT` first.
2171
+
2172
+ Every time a user opens the app, we send a request in the background to fetch the feature flags that apply to that user. We store those flags in the storage.
2173
+
2174
+ This means that for most screens, the feature flags are available immediately – **except for the first time a user visits**.
2175
+
2176
+ To handle this, you can use the `onFeatureFlags` callback in your config to be notified when flags are loaded:
2177
+
2178
+ Dart
2179
+
2180
+ PostHog AI
2181
+
2182
+ ```dart
2183
+ final config = PostHogConfig('<ph_project_token>');
2184
+ config.host = 'https://us.i.posthog.com';
2185
+ config.onFeatureFlags = () async {
2186
+ if (await Posthog().isFeatureEnabled('flag-key')) {
2187
+ // do something
2188
+ }
2189
+ };
2190
+ await Posthog().setup(config);
2191
+ ```
2192
+
2193
+ ### Reloading feature flags
2194
+
2195
+ Feature flag values are cached. If something has changed with your user and you'd like to refetch their flag values, call:
2196
+
2197
+ Dart
2198
+
2199
+ PostHog AI
2200
+
2201
+ ```dart
2202
+ await Posthog().reloadFeatureFlags();
2203
+ ```
2204
+
2205
+ ## Java
2206
+
2207
+ There are two steps to implement feature flags in Java:
2208
+
2209
+ ### Step 1: Evaluate flags once
2210
+
2211
+ Call `posthog.evaluateFlags()` once for the user, then read values from the returned snapshot.
2212
+
2213
+ #### Boolean feature flags
2214
+
2215
+ Java
2216
+
2217
+ PostHog AI
2218
+
2219
+ ```java
2220
+ PostHogFeatureFlagEvaluations flags = posthog.evaluateFlags("distinct_id_of_your_user");
2221
+ if (flags.isEnabled("flag-key")) {
2222
+ // Do something differently for this user
2223
+ // Optional: fetch the payload
2224
+ String matchedFlagPayload = flags.getFlagPayload("flag-key");
2225
+ }
2226
+ ```
2227
+
2228
+ #### Multivariate feature flags
2229
+
2230
+ Java
2231
+
2232
+ PostHog AI
2233
+
2234
+ ```java
2235
+ PostHogFeatureFlagEvaluations flags = posthog.evaluateFlags("distinct_id_of_your_user");
2236
+ Object flagValue = flags.getFlag("flag-key");
2237
+ String enabledVariant = flagValue instanceof String ? (String) flagValue : null;
2238
+ if ("variant-key".equals(enabledVariant)) { // replace "variant-key" with the key of your variant
2239
+ // Do something differently for this user
2240
+ // Optional: fetch the payload
2241
+ String matchedFlagPayload = flags.getFlagPayload("flag-key");
2242
+ }
2243
+ ```
2244
+
2245
+ `flags.getFlag()` returns the variant string for multivariate flags, `true` for enabled boolean flags, `false` for disabled flags, and `null` when the flag wasn't returned by the evaluation.
2246
+
2247
+ > **Note:** `posthog.isFeatureEnabled()`, `posthog.getFeatureFlag()`, `posthog.getFeatureFlagPayload()`, and `PostHogCaptureOptions.builder().appendFeatureFlags(true)` still work during the migration period, but they're deprecated. Prefer `evaluateFlags()` for new code.
2248
+
2249
+ ### Step 2: Include feature flag information when capturing events
2250
+
2251
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
2252
+
2253
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
2254
+
2255
+ There are two methods you can use to include feature flag information in your events:
2256
+
2257
+ #### Method 1: Pass the evaluated flags snapshot to `capture()`
2258
+
2259
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
2260
+
2261
+ Java
2262
+
2263
+ PostHog AI
2264
+
2265
+ ```java
2266
+ PostHogFeatureFlagEvaluations flags = posthog.evaluateFlags("distinct_id_of_your_user");
2267
+ if (flags.isEnabled("flag-key")) {
2268
+ // Do something differently for this user
2269
+ }
2270
+ posthog.capture(
2271
+ "distinct_id_of_your_user",
2272
+ "event_name",
2273
+ PostHogCaptureOptions.builder()
2274
+ .flags(flags)
2275
+ .build()
2276
+ );
2277
+ ```
2278
+
2279
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
2280
+
2281
+ To reduce event property bloat, pass a filtered snapshot:
2282
+
2283
+ Java
2284
+
2285
+ PostHog AI
2286
+
2287
+ ```java
2288
+ // Attach only flags accessed with isEnabled() or getFlag() before this call
2289
+ posthog.capture(
2290
+ "distinct_id_of_your_user",
2291
+ "event_name",
2292
+ PostHogCaptureOptions.builder()
2293
+ .flags(flags.onlyAccessed())
2294
+ .build()
2295
+ );
2296
+ // Attach only specific flags
2297
+ posthog.capture(
2298
+ "distinct_id_of_your_user",
2299
+ "event_name",
2300
+ PostHogCaptureOptions.builder()
2301
+ .flags(flags.only("checkout-flow", "new-dashboard"))
2302
+ .build()
2303
+ );
2304
+ ```
2305
+
2306
+ `onlyAccessed()` is order-dependent. If you call it before accessing any flags with `isEnabled()` or `getFlag()`, no feature flag properties are attached.
2307
+
2308
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
2309
+
2310
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
2311
+
2312
+ Java
2313
+
2314
+ PostHog AI
2315
+
2316
+ ```java
2317
+ posthog.capture(
2318
+ "distinct_id_of_your_user",
2319
+ "event_name",
2320
+ PostHogCaptureOptions.builder()
2321
+ .property("$feature/feature-flag-key", "variant-key") // replace feature-flag-key with your flag key. Replace "variant-key" with the key of your variant
2322
+ .build()
2323
+ );
2324
+ ```
2325
+
2326
+ ### Evaluating only specific flags
2327
+
2328
+ By default, `evaluateFlags()` evaluates every flag for the user. If you only need a few flags, pass `flagKeys` to request only those flags:
2329
+
2330
+ Java
2331
+
2332
+ PostHog AI
2333
+
2334
+ ```java
2335
+ import java.util.Arrays;
2336
+ PostHogFeatureFlagEvaluations flags = posthog.evaluateFlags(
2337
+ "distinct_id_of_your_user",
2338
+ PostHogEvaluateFlagsOptions.builder()
2339
+ .flagKeys(Arrays.asList("checkout-flow", "new-dashboard"))
2340
+ .build()
2341
+ );
2342
+ ```
2343
+
2344
+ ### Sending `$feature_flag_called` events
2345
+
2346
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `evaluateFlags()`, the SDK sends this event when you call `flags.isEnabled()` or `flags.getFlag()` for a flag.
2347
+
2348
+ The SDK deduplicates these events per `(distinct_id, flag, value)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
2349
+
2350
+ `flags.getFlagPayload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `onlyAccessed()`.
2351
+
2352
+ ### Advanced: Overriding server properties
2353
+
2354
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
2355
+
2356
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
2357
+
2358
+ For example:
2359
+
2360
+ Java
2361
+
2362
+ PostHog AI
2363
+
2364
+ ```java
2365
+ import com.posthog.server.PostHogEvaluateFlagsOptions;
2366
+ PostHogFeatureFlagEvaluations flags = posthog.evaluateFlags(
2367
+ "distinct_id_of_the_user",
2368
+ PostHogEvaluateFlagsOptions.builder()
2369
+ .group("your_group_type", "your_group_id")
2370
+ .group("another_group_type", "your_group_id")
2371
+ .groupProperty("your_group_type", "group_property_name", "value")
2372
+ .groupProperty("another_group_type", "group_property_name", "value")
2373
+ .personProperty("property_name", "value")
2374
+ .build()
2375
+ );
2376
+ if (flags.isEnabled("flag-key")) {
2377
+ // Do something differently for this user
2378
+ }
2379
+ ```
2380
+
2381
+ ### Overriding GeoIP properties
2382
+
2383
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
2384
+
2385
+ You can override GeoIP properties by including them in the `person_properties` parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
2386
+
2387
+ The following GeoIP properties can be overridden:
2388
+
2389
+ - `$geoip_country_code`
2390
+ - `$geoip_country_name`
2391
+ - `$geoip_city_name`
2392
+ - `$geoip_city_confidence`
2393
+ - `$geoip_continent_code`
2394
+ - `$geoip_continent_name`
2395
+ - `$geoip_latitude`
2396
+ - `$geoip_longitude`
2397
+ - `$geoip_postal_code`
2398
+ - `$geoip_subdivision_1_code`
2399
+ - `$geoip_subdivision_1_name`
2400
+ - `$geoip_subdivision_2_code`
2401
+ - `$geoip_subdivision_2_name`
2402
+ - `$geoip_subdivision_3_code`
2403
+ - `$geoip_subdivision_3_name`
2404
+ - `$geoip_time_zone`
2405
+
2406
+ Simply include any of these properties in the `person_properties` parameter alongside your other person properties when calling feature flags.
2407
+
2408
+ ## Rust
2409
+
2410
+ There are two steps to implement feature flags in Rust:
2411
+
2412
+ ### Step 1: Evaluate flags once
2413
+
2414
+ Call `client.evaluate_flags()` once for the user, then read values from the returned snapshot.
2415
+
2416
+ #### Boolean feature flags
2417
+
2418
+ Rust
2419
+
2420
+ PostHog AI
2421
+
2422
+ ```rust
2423
+ use posthog_rs::EvaluateFlagsOptions;
2424
+ let flags = client.evaluate_flags(
2425
+ "distinct_id_of_your_user",
2426
+ EvaluateFlagsOptions::default(),
2427
+ ).await.unwrap();
2428
+ if flags.is_enabled("flag-key") {
2429
+ // Do something differently for this user
2430
+ // Optional: fetch the payload
2431
+ let matched_flag_payload = flags.get_flag_payload("flag-key");
2432
+ }
2433
+ ```
2434
+
2435
+ #### Multivariate feature flags
2436
+
2437
+ Rust
2438
+
2439
+ PostHog AI
2440
+
2441
+ ```rust
2442
+ use posthog_rs::{EvaluateFlagsOptions, FlagValue};
2443
+ let flags = client.evaluate_flags(
2444
+ "distinct_id_of_your_user",
2445
+ EvaluateFlagsOptions::default(),
2446
+ ).await.unwrap();
2447
+ match flags.get_flag("flag-key") {
2448
+ Some(FlagValue::String(variant)) if variant == "variant-key" => {
2449
+ // Do something differently for this user
2450
+ // Optional: fetch the payload
2451
+ let matched_flag_payload = flags.get_flag_payload("flag-key");
2452
+ }
2453
+ _ => {}
2454
+ }
2455
+ ```
2456
+
2457
+ `flags.get_flag()` returns `Some(FlagValue::String(...))` for multivariate flags, `Some(FlagValue::Boolean(true))` for enabled boolean flags, `Some(FlagValue::Boolean(false))` for disabled flags, and `None` when the flag wasn't returned by the evaluation.
2458
+
2459
+ > **Note:** `client.is_feature_enabled()`, `client.get_feature_flag()`, `client.get_feature_flag_payload()`, and `client.get_feature_flags()` still work during the migration period, but they're deprecated. Prefer `evaluate_flags()` for new code.
2460
+
2461
+ ### Step 2: Include feature flag information when capturing events
2462
+
2463
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
2464
+
2465
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
2466
+
2467
+ There are two methods you can use to include feature flag information in your events:
2468
+
2469
+ #### Method 1: Pass the evaluated flags snapshot to the event
2470
+
2471
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
2472
+
2473
+ Rust
2474
+
2475
+ PostHog AI
2476
+
2477
+ ```rust
2478
+ use posthog_rs::{EvaluateFlagsOptions, Event};
2479
+ let flags = client.evaluate_flags(
2480
+ "distinct_id_of_your_user",
2481
+ EvaluateFlagsOptions::default(),
2482
+ ).await.unwrap();
2483
+ if flags.is_enabled("flag-key") {
2484
+ // Do something differently for this user
2485
+ }
2486
+ let mut event = Event::new("event_name", "distinct_id_of_your_user");
2487
+ event.with_flags(&flags);
2488
+ client.capture(event);
2489
+ ```
2490
+
2491
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
2492
+
2493
+ To reduce event property bloat, pass a filtered snapshot:
2494
+
2495
+ Rust
2496
+
2497
+ PostHog AI
2498
+
2499
+ ```rust
2500
+ // Attach only flags accessed with is_enabled() or get_flag() before this call
2501
+ let mut event = Event::new("event_name", "distinct_id_of_your_user");
2502
+ event.with_flags(&flags.only_accessed());
2503
+ client.capture(event);
2504
+ // Attach only specific flags
2505
+ let mut event = Event::new("event_name", "distinct_id_of_your_user");
2506
+ event.with_flags(&flags.only(&["checkout-flow", "new-dashboard"]));
2507
+ client.capture(event);
2508
+ ```
2509
+
2510
+ `only_accessed()` is order-dependent. If you call it before accessing any flags with `is_enabled()` or `get_flag()`, no feature flag properties are attached.
2511
+
2512
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
2513
+
2514
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
2515
+
2516
+ Rust
2517
+
2518
+ PostHog AI
2519
+
2520
+ ```rust
2521
+ use posthog_rs::Event;
2522
+ let mut event = Event::new("event_name", "distinct_id_of_your_user");
2523
+ event.insert_prop("$feature/feature-flag-key", "variant-key").unwrap();
2524
+ client.capture(event);
2525
+ ```
2526
+
2527
+ ### Evaluating only specific flags
2528
+
2529
+ By default, `evaluate_flags()` evaluates every flag for the user. If you only need a few flags, pass `flag_keys` to request only those flags:
2530
+
2531
+ Rust
2532
+
2533
+ PostHog AI
2534
+
2535
+ ```rust
2536
+ use posthog_rs::EvaluateFlagsOptions;
2537
+ let flags = client.evaluate_flags(
2538
+ "distinct_id_of_your_user",
2539
+ EvaluateFlagsOptions {
2540
+ flag_keys: Some(vec!["checkout-flow".to_string(), "new-dashboard".to_string()]),
2541
+ ..Default::default()
2542
+ },
2543
+ ).await.unwrap();
2544
+ ```
2545
+
2546
+ ### Sending `$feature_flag_called` events
2547
+
2548
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `evaluate_flags()`, the SDK sends this event when you call `flags.is_enabled()` or `flags.get_flag()` for a flag.
2549
+
2550
+ The SDK deduplicates these events per `(distinct_id, flag, value)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
2551
+
2552
+ `flags.get_flag_payload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `only_accessed()`.
2553
+
2554
+ ### Blocking client
2555
+
2556
+ If you're using the blocking client (with `default-features = false`), the API is the same but without `.await`:
2557
+
2558
+ Rust
2559
+
2560
+ PostHog AI
2561
+
2562
+ ```rust
2563
+ use posthog_rs::EvaluateFlagsOptions;
2564
+ let flags = client.evaluate_flags(
2565
+ "distinct_id_of_your_user",
2566
+ EvaluateFlagsOptions::default(),
2567
+ ).unwrap();
2568
+ if flags.is_enabled("flag-key") {
2569
+ // Do something differently for this user
2570
+ }
2571
+ ```
2572
+
2573
+ ## Elixir
2574
+
2575
+ There are two steps to implement feature flags in Elixir:
2576
+
2577
+ ### Step 1: Evaluate flags once
2578
+
2579
+ Call `PostHog.FeatureFlags.evaluate_flags/1` once for the user, then read values from the returned snapshot.
2580
+
2581
+ #### Boolean feature flags
2582
+
2583
+ Elixir
2584
+
2585
+ PostHog AI
2586
+
2587
+ ```elixir
2588
+ {:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
2589
+ if PostHog.FeatureFlags.Evaluations.enabled?(snapshot, "flag-key") do
2590
+ # Do something differently for this user
2591
+ # Optional: fetch the payload
2592
+ payload = PostHog.FeatureFlags.Evaluations.get_flag_payload(snapshot, "flag-key")
2593
+ end
2594
+ ```
2595
+
2596
+ #### Multivariate feature flags
2597
+
2598
+ Elixir
2599
+
2600
+ PostHog AI
2601
+
2602
+ ```elixir
2603
+ {:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
2604
+ enabled_variant = PostHog.FeatureFlags.Evaluations.get_flag(snapshot, "flag-key")
2605
+ if enabled_variant == "variant-key" do
2606
+ # Do something differently for this user
2607
+ # Optional: fetch the payload
2608
+ payload = PostHog.FeatureFlags.Evaluations.get_flag_payload(snapshot, "flag-key")
2609
+ end
2610
+ ```
2611
+
2612
+ `PostHog.FeatureFlags.Evaluations.get_flag/2` returns the variant string for multivariate flags, `true` for enabled boolean flags, `false` for disabled flags, and `nil` when the flag wasn't returned by the evaluation.
2613
+
2614
+ > **Note:** `PostHog.FeatureFlags.check/2`, `PostHog.FeatureFlags.check!/2`, `PostHog.FeatureFlags.get_feature_flag_result/2`, and `PostHog.FeatureFlags.get_feature_flag_result!/2` still work during the migration period, but they're deprecated. Prefer `evaluate_flags/1` for new code.
2615
+
2616
+ ### Step 2: Include feature flag information when capturing events
2617
+
2618
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
2619
+
2620
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
2621
+
2622
+ There are two methods you can use to include feature flag information in your events:
2623
+
2624
+ #### Method 1: Put the evaluated flags snapshot in context
2625
+
2626
+ Put the same `snapshot` object that you used for branching into context. Subsequent captures from the same process attach the exact flag values from that evaluation and don't make another `/flags` request.
2627
+
2628
+ Elixir
2629
+
2630
+ PostHog AI
2631
+
2632
+ ```elixir
2633
+ {:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
2634
+ if PostHog.FeatureFlags.Evaluations.enabled?(snapshot, "flag-key") do
2635
+ # Do something differently for this user
2636
+ end
2637
+ PostHog.FeatureFlags.set_in_context(snapshot)
2638
+ PostHog.capture("event_name", %{distinct_id: "distinct_id_of_your_user"})
2639
+ ```
2640
+
2641
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
2642
+
2643
+ To reduce event property bloat, put a filtered snapshot in context:
2644
+
2645
+ Elixir
2646
+
2647
+ PostHog AI
2648
+
2649
+ ```elixir
2650
+ {:ok, snapshot} = PostHog.FeatureFlags.evaluate_flags("distinct_id_of_your_user")
2651
+ # Attach only flags accessed with enabled?/2 or get_flag/2 before this call
2652
+ PostHog.FeatureFlags.Evaluations.enabled?(snapshot, "flag-key")
2653
+ PostHog.FeatureFlags.set_in_context(
2654
+ PostHog.FeatureFlags.Evaluations.only_accessed(snapshot)
2655
+ )
2656
+ # Or attach only specific flags
2657
+ PostHog.FeatureFlags.set_in_context(
2658
+ PostHog.FeatureFlags.Evaluations.only(snapshot, ["checkout-flow", "new-dashboard"])
2659
+ )
2660
+ ```
2661
+
2662
+ `only_accessed/1` is order-dependent. If you call it before accessing any flags with `enabled?/2` or `get_flag/2`, no feature flag properties are attached.
2663
+
2664
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
2665
+
2666
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
2667
+
2668
+ Elixir
2669
+
2670
+ PostHog AI
2671
+
2672
+ ```elixir
2673
+ PostHog.capture("event_name", %{
2674
+ "$feature/feature-flag-key" => "variant-key",
2675
+ distinct_id: "distinct_id_of_your_user"
2676
+ })
2677
+ ```
2678
+
2679
+ ### Evaluating only specific flags
2680
+
2681
+ By default, `evaluate_flags/1` evaluates every flag for the user. If you only need a few flags, pass `flag_keys` to request only those flags:
2682
+
2683
+ Elixir
2684
+
2685
+ PostHog AI
2686
+
2687
+ ```elixir
2688
+ {:ok, snapshot} =
2689
+ PostHog.FeatureFlags.evaluate_flags(%{
2690
+ distinct_id: "distinct_id_of_your_user",
2691
+ flag_keys: ["checkout-flow", "new-dashboard"]
2692
+ })
2693
+ ```
2694
+
2695
+ ### Sending `$feature_flag_called` events
2696
+
2697
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `evaluate_flags/1`, the SDK sends this event when you call `PostHog.FeatureFlags.Evaluations.enabled?/2` or `PostHog.FeatureFlags.Evaluations.get_flag/2` for a flag.
2698
+
2699
+ `PostHog.FeatureFlags.Evaluations.get_flag_payload/2` doesn't send `$feature_flag_called` events.
2700
+
2701
+ ## .NET
2702
+
2703
+ There are two steps to implement feature flags in .NET:
2704
+
2705
+ ### Step 1: Evaluate flags once
2706
+
2707
+ Call `EvaluateFlagsAsync()` once for the user, then read values from the returned snapshot.
2708
+
2709
+ #### Boolean feature flags
2710
+
2711
+ C#
2712
+
2713
+ PostHog AI
2714
+
2715
+ ```csharp
2716
+ var flags = await posthog.EvaluateFlagsAsync("distinct_id_of_your_user");
2717
+ if (flags.IsEnabled("flag-key"))
2718
+ {
2719
+ // Do something differently for this user
2720
+ // Optional: fetch the payload
2721
+ var matchedPayload = flags.GetFlagPayload("flag-key");
2722
+ }
2723
+ ```
2724
+
2725
+ #### Multivariate feature flags
2726
+
2727
+ C#
2728
+
2729
+ PostHog AI
2730
+
2731
+ ```csharp
2732
+ var flags = await posthog.EvaluateFlagsAsync("distinct_id_of_your_user");
2733
+ var enabledVariant = flags.GetFlag("flag-key")?.VariantKey;
2734
+ if (enabledVariant == "variant-key") // replace "variant-key" with the key of your variant
2735
+ {
2736
+ // Do something differently for this user
2737
+ // Optional: fetch the payload
2738
+ var matchedPayload = flags.GetFlagPayload("flag-key");
2739
+ }
2740
+ ```
2741
+
2742
+ `flags.GetFlag()` returns a nullable `FeatureFlag` object. Check `VariantKey` for multivariate flags and `IsEnabled` for boolean flags. It returns `null` when the flag wasn't returned by the evaluation.
2743
+
2744
+ > **Note:** `posthog.IsFeatureEnabledAsync()`, `posthog.GetFeatureFlagAsync()`, and `Capture(..., sendFeatureFlags: true, ...)` still work during the migration period, but they're deprecated. Prefer `EvaluateFlagsAsync()` for new code.
2745
+
2746
+ ### Step 2: Include feature flag information when capturing events
2747
+
2748
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
2749
+
2750
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
2751
+
2752
+ There are two methods you can use to include feature flag information in your events:
2753
+
2754
+ #### Method 1: Pass the evaluated flags snapshot to `Capture()`
2755
+
2756
+ Pass the same `flags` object that you used for branching. This attaches the exact flag values from that evaluation and doesn't make another `/flags` request.
2757
+
2758
+ C#
2759
+
2760
+ PostHog AI
2761
+
2762
+ ```csharp
2763
+ var flags = await posthog.EvaluateFlagsAsync("distinct_id_of_your_user");
2764
+ if (flags.IsEnabled("flag-key"))
2765
+ {
2766
+ // Do something differently for this user
2767
+ }
2768
+ posthog.Capture(
2769
+ "distinct_id_of_your_user",
2770
+ "event_name",
2771
+ properties: null,
2772
+ groups: null,
2773
+ flags: flags
2774
+ );
2775
+ ```
2776
+
2777
+ By default, this attaches every flag in the snapshot using `$feature/<flag-key>` properties and `$active_feature_flags`.
2778
+
2779
+ To reduce event property bloat, pass a filtered snapshot:
2780
+
2781
+ C#
2782
+
2783
+ PostHog AI
2784
+
2785
+ ```csharp
2786
+ // Attach only flags accessed with IsEnabled() or GetFlag() before this call
2787
+ posthog.Capture(
2788
+ "distinct_id_of_your_user",
2789
+ "event_name",
2790
+ properties: null,
2791
+ groups: null,
2792
+ flags: flags.OnlyAccessed()
2793
+ );
2794
+ // Attach only specific flags
2795
+ posthog.Capture(
2796
+ "distinct_id_of_your_user",
2797
+ "event_name",
2798
+ properties: null,
2799
+ groups: null,
2800
+ flags: flags.Only("checkout-flow", "new-dashboard")
2801
+ );
2802
+ ```
2803
+
2804
+ #### Method 2: Include the `$feature/feature_flag_name` property manually
2805
+
2806
+ In the event properties, include `$feature/feature_flag_name: variant_key`:
2807
+
2808
+ C#
2809
+
2810
+ PostHog AI
2811
+
2812
+ ```csharp
2813
+ posthog.Capture(
2814
+ "distinct_id_of_your_user",
2815
+ "event_name",
2816
+ properties: new()
2817
+ {
2818
+ // Replace feature-flag-key with your flag key and "variant-key" with the key of your variant
2819
+ ["$feature/feature-flag-key"] = "variant-key",
2820
+ }
2821
+ );
2822
+ ```
2823
+
2824
+ ### Evaluating only specific flags
2825
+
2826
+ By default, `EvaluateFlagsAsync()` evaluates every flag for the user. If you only need a few flags, pass `FlagKeysToEvaluate` to request only those flags:
2827
+
2828
+ C#
2829
+
2830
+ PostHog AI
2831
+
2832
+ ```csharp
2833
+ var flags = await posthog.EvaluateFlagsAsync(
2834
+ "distinct_id_of_your_user",
2835
+ options: new AllFeatureFlagsOptions
2836
+ {
2837
+ FlagKeysToEvaluate = new[] { "checkout-flow", "new-dashboard" },
2838
+ }
2839
+ );
2840
+ ```
2841
+
2842
+ ### Sending `$feature_flag_called` events
2843
+
2844
+ Capturing `$feature_flag_called` events enables PostHog to know when a flag was accessed by a user and provide [analytics and insights](/docs/product-analytics/insights.md) on the flag. With `EvaluateFlagsAsync()`, the SDK sends this event when you call `flags.IsEnabled()` or `flags.GetFlag()` for a flag.
2845
+
2846
+ The SDK deduplicates these events per `(distinct_id, flag, value)` in a local cache. If you reinitialize the PostHog client, the cache resets and `$feature_flag_called` events may be sent again. PostHog handles duplicates, so duplicate `$feature_flag_called` events don't affect your analytics.
2847
+
2848
+ `flags.GetFlagPayload()` doesn't send `$feature_flag_called` events and doesn't count as an access for `OnlyAccessed()`.
2849
+
2850
+ ### Advanced: Overriding server properties
2851
+
2852
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
2853
+
2854
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
2855
+
2856
+ For example:
2857
+
2858
+ C#
2859
+
2860
+ PostHog AI
2861
+
2862
+ ```csharp
2863
+ var flags = await posthog.EvaluateFlagsAsync(
2864
+ "distinct_id_of_the_user",
2865
+ options: new AllFeatureFlagsOptions
2866
+ {
2867
+ PersonProperties = new()
2868
+ {
2869
+ ["property_name"] = "value",
2870
+ },
2871
+ Groups = new()
2872
+ {
2873
+ new Group("your_group_type", "your_group_id")
2874
+ {
2875
+ ["group_property_name"] = "value",
2876
+ },
2877
+ new Group("another_group_type", "another_group_id")
2878
+ {
2879
+ ["group_property_name"] = "another value",
2880
+ },
2881
+ },
2882
+ }
2883
+ );
2884
+ if (flags.IsEnabled("flag-key"))
2885
+ {
2886
+ // Do something differently for this user
2887
+ }
2888
+ ```
2889
+
2890
+ ### Overriding GeoIP properties
2891
+
2892
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
2893
+
2894
+ You can override GeoIP properties by including them in the `person_properties` parameter when evaluating feature flags. This is useful when you're evaluating flags on your backend and want to use the client's location instead of your server's location.
2895
+
2896
+ The following GeoIP properties can be overridden:
2897
+
2898
+ - `$geoip_country_code`
2899
+ - `$geoip_country_name`
2900
+ - `$geoip_city_name`
2901
+ - `$geoip_city_confidence`
2902
+ - `$geoip_continent_code`
2903
+ - `$geoip_continent_name`
2904
+ - `$geoip_latitude`
2905
+ - `$geoip_longitude`
2906
+ - `$geoip_postal_code`
2907
+ - `$geoip_subdivision_1_code`
2908
+ - `$geoip_subdivision_1_name`
2909
+ - `$geoip_subdivision_2_code`
2910
+ - `$geoip_subdivision_2_name`
2911
+ - `$geoip_subdivision_3_code`
2912
+ - `$geoip_subdivision_3_name`
2913
+ - `$geoip_time_zone`
2914
+
2915
+ Simply include any of these properties in the `person_properties` parameter alongside your other person properties when calling feature flags.
2916
+
2917
+ ## API
2918
+
2919
+ There are 3 steps to implement feature flags using the PostHog API:
2920
+
2921
+ ### Step 1: Evaluate the feature flag value using `flags`
2922
+
2923
+ `flags` is the endpoint used to determine if a given flag is enabled for a certain user or not.
2924
+
2925
+ #### Request
2926
+
2927
+ PostHog AI
2928
+
2929
+ ### Terminal
2930
+
2931
+ ```shell
2932
+ # Basic request (flags only)
2933
+ curl -v -L --header "Content-Type: application/json" -d ' {
2934
+ "api_key": "<ph_project_token>",
2935
+ "distinct_id": "distinct_id_of_your_user",
2936
+ "groups" : {
2937
+ "group_type": "group_id"
2938
+ }
2939
+ }' "https://us.i.posthog.com/flags?v=2"
2940
+ # With configuration (flags + PostHog config)
2941
+ curl -v -L --header "Content-Type: application/json" -d ' {
2942
+ "api_key": "<ph_project_token>",
2943
+ "distinct_id": "distinct_id_of_your_user",
2944
+ "groups" : {
2945
+ "group_type": "group_id"
2946
+ }
2947
+ }' "https://us.i.posthog.com/flags?v=2&config=true"
2948
+ ```
2949
+
2950
+ ### Python
2951
+
2952
+ ```python
2953
+ import requests
2954
+ import json
2955
+ # Basic request (flags only)
2956
+ url = "https://us.i.posthog.com/flags?v=2"
2957
+ headers = {
2958
+ "Content-Type": "application/json"
2959
+ }
2960
+ payload = {
2961
+ "api_key": "<ph_project_token>",
2962
+ "distinct_id": "user distinct id",
2963
+ "groups": {
2964
+ "group_type": "group_id"
2965
+ }
2966
+ }
2967
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
2968
+ print(response.json())
2969
+ # With configuration (flags + PostHog config)
2970
+ url_with_config = "https://us.i.posthog.com/flags?v=2&config=true"
2971
+ response_with_config = requests.post(url_with_config, headers=headers, data=json.dumps(payload))
2972
+ print(response_with_config.json())
2973
+ ```
2974
+
2975
+ ### Node.js
2976
+
2977
+ ```javascript
2978
+ import fetch from "node-fetch";
2979
+ async function sendFlagsRequest() {
2980
+ const headers = {
2981
+ "Content-Type": "application/json",
2982
+ };
2983
+ const payload = {
2984
+ api_key: "<ph_project_token>",
2985
+ distinct_id: "user distinct id",
2986
+ groups: {
2987
+ group_type: "group_id",
2988
+ },
2989
+ };
2990
+ // Basic request (flags only)
2991
+ const url = "https://us.i.posthog.com/flags?v=2";
2992
+ const response = await fetch(url, {
2993
+ method: "POST",
2994
+ headers: headers,
2995
+ body: JSON.stringify(payload),
2996
+ });
2997
+ const data = await response.json();
2998
+ console.log(data);
2999
+ // With configuration (flags + PostHog config)
3000
+ const urlWithConfig = "https://us.i.posthog.com/flags?v=2&config=true";
3001
+ const responseWithConfig = await fetch(urlWithConfig, {
3002
+ method: "POST",
3003
+ headers: headers,
3004
+ body: JSON.stringify(payload),
3005
+ });
3006
+ const dataWithConfig = await responseWithConfig.json();
3007
+ console.log(dataWithConfig);
3008
+ }
3009
+ sendFlagsRequest();
3010
+ ```
3011
+
3012
+ > **Note:** The `groups` key is only required for group-based feature flags. If you use it, replace `group_type` and `group_id` with the values for your group such as `company: "Twitter"`.
3013
+
3014
+ #### Using evaluation context tags and runtime filtering without SDKs
3015
+
3016
+ When making direct API calls to the `/flags` endpoint, you can control which flags are evaluated using evaluation context tags and runtime filtering.
3017
+
3018
+ ##### Evaluation contexts
3019
+
3020
+ To filter flags by evaluation context, include the `evaluation_contexts` field in your request body:
3021
+
3022
+ > **Note:** The legacy parameter `evaluation_environments` is also supported for backward compatibility.
3023
+
3024
+ PostHog AI
3025
+
3026
+ ### Terminal
3027
+
3028
+ ```shell
3029
+ curl -v -L --header "Content-Type: application/json" -d ' {
3030
+ "api_key": "<ph_project_token>",
3031
+ "distinct_id": "distinct_id_of_your_user",
3032
+ "evaluation_contexts": ["production", "web"]
3033
+ }' "https://us.i.posthog.com/flags?v=2"
3034
+ ```
3035
+
3036
+ ### Python
3037
+
3038
+ ```python
3039
+ import requests
3040
+ import json
3041
+ url = "https://us.i.posthog.com/flags?v=2"
3042
+ headers = {
3043
+ "Content-Type": "application/json"
3044
+ }
3045
+ payload = {
3046
+ "api_key": "<ph_project_token>",
3047
+ "distinct_id": "user distinct id",
3048
+ "evaluation_contexts": ["production", "web"]
3049
+ }
3050
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
3051
+ print(response.json())
3052
+ ```
3053
+
3054
+ ### JavaScript
3055
+
3056
+ ```javascript
3057
+ const response = await fetch("https://us.i.posthog.com/flags?v=2", {
3058
+ method: "POST",
3059
+ headers: {
3060
+ "Content-Type": "application/json",
3061
+ },
3062
+ body: JSON.stringify({
3063
+ api_key: "<ph_project_token>",
3064
+ distinct_id: "user-distinct-id",
3065
+ evaluation_contexts: ["production", "web"]
3066
+ }),
3067
+ });
3068
+ const data = await response.json();
3069
+ ```
3070
+
3071
+ Only flags where at least one evaluation tag matches (or flags with no tags at all) will be returned. For example:
3072
+
3073
+ - Flag with evaluation context tags `["production", "api", "backend"]` + request with `["production", "web"]` = ✅ Flag evaluates ("production" matches)
3074
+ - Flag with evaluation context tags `["staging", "api"]` + request with `["production", "web"]` = ❌ Flag doesn't evaluate (no tags match)
3075
+ - Flag with evaluation context tags `["web", "mobile"]` + request with `["production", "web"]` = ✅ Flag evaluates ("web" matches)
3076
+ - Flag with no evaluation context tags = ✅ Always evaluates (backward compatibility)
3077
+
3078
+ ##### Runtime detection
3079
+
3080
+ Evaluation runtime (server vs. client) is automatically detected based on your request headers and user-agent. This determines which flags are available based on their runtime setting (server-only, client-only, or all).
3081
+
3082
+ **How runtime is detected:**
3083
+
3084
+ 1. **User-Agent patterns** - The system analyzes the User-Agent header:
3085
+
3086
+ - **Client-side patterns**: `Mozilla/`, `Chrome/`, `Safari/`, `Firefox/`, `Edge/` (browsers), or mobile SDKs like `posthog-android/`, `posthog-ios/`, `posthog-react-native/`, `posthog-flutter/`
3087
+ - **Server-side patterns**: `posthog-python/`, `posthog-ruby/`, `posthog-php/`, `posthog-java/`, `posthog-go/`, `posthog-node/`, `posthog-dotnet/`, `posthog-elixir/`, `python-requests/`, `curl/`
3088
+ 2. **Browser-specific headers** - Presence of these headers indicates client-side:
3089
+
3090
+ - `Origin` header
3091
+ - `Referer` header
3092
+ - `Sec-Fetch-Mode` header
3093
+ - `Sec-Fetch-Site` header
3094
+ 3. **Default behavior** - If runtime can't be determined, the system includes flags with no runtime requirement and those set to "all"
3095
+
3096
+ **Examples of runtime detection:**
3097
+
3098
+ JavaScript
3099
+
3100
+ PostHog AI
3101
+
3102
+ ```javascript
3103
+ // Browser fetch - Detected as CLIENT runtime
3104
+ // Will receive: client-only flags + "all" flags
3105
+ // Won't receive: server-only flags
3106
+ const response = await fetch("https://us.i.posthog.com/flags?v=2", {
3107
+ method: "POST",
3108
+ headers: {
3109
+ "Content-Type": "application/json",
3110
+ // Browser automatically adds Origin, Referer, Sec-Fetch-* headers
3111
+ },
3112
+ body: JSON.stringify({
3113
+ api_key: "<ph_project_token>",
3114
+ distinct_id: "user-id"
3115
+ })
3116
+ });
3117
+ ```
3118
+
3119
+ Python
3120
+
3121
+ PostHog AI
3122
+
3123
+ ```python
3124
+ # Python requests - Detected as SERVER runtime
3125
+ # Will receive: server-only flags + "all" flags
3126
+ # Won't receive: client-only flags
3127
+ import requests
3128
+ response = requests.post(
3129
+ "https://us.i.posthog.com/flags?v=2",
3130
+ json={
3131
+ "api_key": "<ph_project_token>",
3132
+ "distinct_id": "user-id"
3133
+ }
3134
+ # python-requests/ in User-Agent indicates server-side
3135
+ )
3136
+ ```
3137
+
3138
+ Terminal
3139
+
3140
+ PostHog AI
3141
+
3142
+ ```shell
3143
+ # curl - Detected as SERVER runtime
3144
+ # Will receive: server-only flags + "all" flags
3145
+ # Won't receive: client-only flags
3146
+ curl -v -L --header "Content-Type: application/json" -d '{
3147
+ "api_key": "<ph_project_token>",
3148
+ "distinct_id": "user-id"
3149
+ }' "https://us.i.posthog.com/flags?v=2"
3150
+ # curl/ in User-Agent indicates server-side
3151
+ ```
3152
+
3153
+ JavaScript
3154
+
3155
+ PostHog AI
3156
+
3157
+ ```javascript
3158
+ // Node.js with custom User-Agent - Control runtime detection
3159
+ const response = await fetch("https://us.i.posthog.com/flags?v=2", {
3160
+ method: "POST",
3161
+ headers: {
3162
+ "Content-Type": "application/json",
3163
+ "User-Agent": "posthog-node/3.0.0" // Explicitly indicates server-side
3164
+ },
3165
+ body: JSON.stringify({
3166
+ api_key: "<ph_project_token>",
3167
+ distinct_id: "user-id"
3168
+ })
3169
+ });
3170
+ ```
3171
+
3172
+ ##### Combining evaluation context tags and runtime filtering
3173
+
3174
+ Both features work together as sequential filters:
3175
+
3176
+ JavaScript
3177
+
3178
+ PostHog AI
3179
+
3180
+ ```javascript
3181
+ // Example: Production web client
3182
+ const response = await fetch("https://us.i.posthog.com/flags?v=2", {
3183
+ method: "POST",
3184
+ headers: {
3185
+ "Content-Type": "application/json",
3186
+ // Browser headers will trigger client runtime detection
3187
+ },
3188
+ body: JSON.stringify({
3189
+ api_key: "<ph_project_token>",
3190
+ distinct_id: "user-id",
3191
+ evaluation_contexts: ["production", "web"]
3192
+ })
3193
+ });
3194
+ // This request will only receive flags that:
3195
+ // 1. Have runtime set to "client" OR "all" (due to browser headers)
3196
+ // AND
3197
+ // 2. Have evaluation context tags matching "production" OR "web" (or no tags)
3198
+ // Note: You can also use the legacy "evaluation_environments" parameter
3199
+ ```
3200
+
3201
+ This allows precise control over which flags are evaluated in different contexts, helping optimize costs and improve security by ensuring flags only evaluate where intended.
3202
+
3203
+ #### Response
3204
+
3205
+ The response varies depending on whether you include the `config=true` query parameter:
3206
+
3207
+ ##### Basic response (`/flags?v=2`)
3208
+
3209
+ Use this endpoint when you only need to evaluate feature flags. It returns a response with just the flag evaluation results.
3210
+
3211
+ > **Note:** If a feature flag is associated with an experiment that has a [holdout group](/docs/experiments/holdouts.md), users in the holdout receive a variant value in the format `holdout-{holdout_id}` (e.g., `holdout-727`). You can detect holdout users by checking if the variant starts with `holdout-`.
3212
+
3213
+ JSON
3214
+
3215
+ PostHog AI
3216
+
3217
+ ```json
3218
+ {
3219
+ "flags": {
3220
+ "my-awesome-flag": {
3221
+ "key": "my-awesome-flag",
3222
+ "enabled": true,
3223
+ "reason": {
3224
+ "code": "condition_match",
3225
+ "condition_index": 0,
3226
+ "description": "Condition set 1 matched"
3227
+ },
3228
+ "metadata": {
3229
+ "id": 1,
3230
+ "version": 1,
3231
+ "payload": "{\"example\": \"json\", \"payload\": \"value\"}"
3232
+ }
3233
+ },
3234
+ "my-multivariate-flag" :{
3235
+ "key":"my-multivariate-flag",
3236
+ "enabled": true,
3237
+ "variant": "some-string-value",
3238
+ "reason": {
3239
+ "code": "condition_match",
3240
+ "condition_index": 1,
3241
+ "description": "Condition set 2 matched"
3242
+ },
3243
+ "metadata": {
3244
+ "id": 2,
3245
+ "version": 42,
3246
+ }
3247
+ },
3248
+ "flag-thats-not-on": {
3249
+ "key": "flag-thats-not-on",
3250
+ "enabled": false,
3251
+ "reason": {
3252
+ "code": "no_condition_match",
3253
+ "condition_index": 0,
3254
+ "description": "No condition sets matched"
3255
+ },
3256
+ "metadata": {
3257
+ "id": 3,
3258
+ "version": 1
3259
+ }
3260
+ }
3261
+ },
3262
+ "errorsWhileComputingFlags": false,
3263
+ "requestId": "550e8400-e29b-41d4-a716-446655440000"
3264
+ }
3265
+ ```
3266
+
3267
+ ##### Full response with configuration (`/flags?v=2&config=true`)
3268
+
3269
+ Use this endpoint when you need both feature flag evaluation and PostHog configuration information (useful for client-side SDKs that need to initialize PostHog):
3270
+
3271
+ JSON
3272
+
3273
+ PostHog AI
3274
+
3275
+ ```json
3276
+ {
3277
+ "config": {
3278
+ "enable_collect_everything": true
3279
+ },
3280
+ "toolbarParams": {},
3281
+ "errorsWhileComputingFlags": false,
3282
+ "isAuthenticated": false,
3283
+ "requestId": "550e8400-e29b-41d4-a716-446655440000",
3284
+ "supportedCompression": [
3285
+ "gzip",
3286
+ "lz64"
3287
+ ],
3288
+ "flags": {
3289
+ "my-awesome-flag": {
3290
+ "key": "my-awesome-flag",
3291
+ "enabled": true,
3292
+ "reason": {
3293
+ "code": "condition_match",
3294
+ "condition_index": 0,
3295
+ "description": "Condition set 1 matched"
3296
+ },
3297
+ "metadata": {
3298
+ "id": 1,
3299
+ "version": 1,
3300
+ "payload": "{\"example\": \"json\", \"payload\": \"value\"}"
3301
+ }
3302
+ },
3303
+ "my-multivariate-flag" :{
3304
+ "key":"my-multivariate-flag",
3305
+ "enabled": true,
3306
+ "variant": "some-string-value",
3307
+ "reason": {
3308
+ "code": "condition_match",
3309
+ "condition_index": 1,
3310
+ "description": "Condition set 2 matched"
3311
+ },
3312
+ "metadata": {
3313
+ "id": 2,
3314
+ "version": 42,
3315
+ }
3316
+ },
3317
+ "flag-thats-not-on": {
3318
+ "key": "flag-thats-not-on",
3319
+ "enabled": false,
3320
+ "reason": {
3321
+ "code": "no_condition_match",
3322
+ "condition_index": 0,
3323
+ "description": "No condition sets matched"
3324
+ },
3325
+ "metadata": {
3326
+ "id": 3,
3327
+ "version": 1
3328
+ }
3329
+ }
3330
+ }
3331
+ }
3332
+ ```
3333
+
3334
+ > **Note:** `errorsWhileComputingFlags` will return `true` if we didn't manage to compute some flags (for example, if there's an [ongoing incident involving flag evaluation](https://status.posthog.com/)).
3335
+ >
3336
+ > This enables partial updates to currently active flags in your clients.
3337
+
3338
+ #### Quota limiting
3339
+
3340
+ If your organization exceeds its feature flag quota, the `/flags` endpoint will return a modified response with `quotaLimited`.
3341
+
3342
+ For basic response (`/flags?v=2`):
3343
+
3344
+ JSON
3345
+
3346
+ PostHog AI
3347
+
3348
+ ```json
3349
+ {
3350
+ "flags": {},
3351
+ "errorsWhileComputingFlags": false,
3352
+ "quotaLimited": ["feature_flags"],
3353
+ "requestId": "d4d89b14-9619-4627-adf2-01b761691c2e"
3354
+ }
3355
+ ```
3356
+
3357
+ For full response with configuration (`/flags?v=2&config=true`):
3358
+
3359
+ JSON
3360
+
3361
+ PostHog AI
3362
+
3363
+ ```json
3364
+ {
3365
+ "config": {
3366
+ "enable_collect_everything": true
3367
+ },
3368
+ "toolbarParams": {},
3369
+ "isAuthenticated": false,
3370
+ "supportedCompression": [
3371
+ "gzip",
3372
+ "lz64"
3373
+ ],
3374
+ "flags": {},
3375
+ "errorsWhileComputingFlags": false,
3376
+ "quotaLimited": ["feature_flags"],
3377
+ "requestId": "d4d89b14-9619-4627-adf2-01b761691c2e"
3378
+ // ... other fields, not relevant to feature flags
3379
+ }
3380
+ ```
3381
+
3382
+ When you receive a response with `quotaLimited` containing `"feature_flags"`, it means:
3383
+
3384
+ 1. Your feature flag evaluations have been temporarily paused because you've exceeded your feature flag quota
3385
+ 2. If you want to continue evaluating feature flags, you can increase your quota in [your billing settings](https://us.posthog.com/organization/billing) under **Feature flags & Experiments** or [contact support](https://us.posthog.com/#panel=support%3Asupport%3Abilling%3A%3Atrue)
3386
+
3387
+ ### Step 2: Include feature flag information when capturing events
3388
+
3389
+ If you want use your feature flag to breakdown or filter events in your [insights](/docs/product-analytics/insights.md), you'll need to include feature flag information in those events. This ensures that the feature flag value is attributed correctly to the event.
3390
+
3391
+ > **Note:** This step is only required for events captured using our server-side SDKs or [API](/docs/api.md).
3392
+
3393
+ To do this, include the `$feature/feature_flag_name` property in your event:
3394
+
3395
+ PostHog AI
3396
+
3397
+ ### Terminal
3398
+
3399
+ ```shell
3400
+ curl -v -L --header "Content-Type: application/json" -d ' {
3401
+ "api_key": "<ph_project_token>",
3402
+ "event": "your_event_name",
3403
+ "distinct_id": "distinct_id_of_your_user",
3404
+ "properties": {
3405
+ "$feature/feature-flag-key": "variant-key" # Replace feature-flag-key with your flag key. Replace 'variant-key' with the key of your variant
3406
+ }
3407
+ }' https://us.i.posthog.com/i/v0/e/
3408
+ ```
3409
+
3410
+ ### Python
3411
+
3412
+ ```python
3413
+ import requests
3414
+ import json
3415
+ url = "https://us.i.posthog.com/i/v0/e/"
3416
+ headers = {
3417
+ "Content-Type": "application/json"
3418
+ }
3419
+ payload = {
3420
+ "api_key": "<ph_project_token>",
3421
+ "event": "your_event_name",
3422
+ "distinct_id": "distinct_id_of_your_user",
3423
+ "properties": {
3424
+ "$feature/feature-flag-key": "variant-key" # Replace feature-flag-key with your flag key. Replace 'variant-key' with the key of your variant
3425
+ }
3426
+ }
3427
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
3428
+ print(response)
3429
+ ```
3430
+
3431
+ ### Step 3: Send a `$feature_flag_called` event
3432
+
3433
+ To track usage of your feature flag and view related analytics in PostHog, submit the `$feature_flag_called` event whenever you check a feature flag value in your code.
3434
+
3435
+ You need to include two properties with this event:
3436
+
3437
+ 1. `$feature_flag_response`: This is the name of the variant the user has been assigned to e.g., "control" or "test"
3438
+ 2. `$feature_flag`: This is the key of the feature flag in your experiment.
3439
+
3440
+ PostHog AI
3441
+
3442
+ ### Terminal
3443
+
3444
+ ```shell
3445
+ curl -v -L --header "Content-Type: application/json" -d ' {
3446
+ "api_key": "<ph_project_token>",
3447
+ "event": "$feature_flag_called",
3448
+ "distinct_id": "distinct_id_of_your_user",
3449
+ "properties": {
3450
+ "$feature_flag": "feature-flag-key",
3451
+ "$feature_flag_response": "variant-name"
3452
+ }
3453
+ }' https://us.i.posthog.com/i/v0/e/
3454
+ ```
3455
+
3456
+ ### Python
3457
+
3458
+ ```python
3459
+ import requests
3460
+ import json
3461
+ url = "https://us.i.posthog.com/i/v0/e/"
3462
+ headers = {
3463
+ "Content-Type": "application/json"
3464
+ }
3465
+ payload = {
3466
+ "api_key": "<ph_project_token>",
3467
+ "event": "feature_flag_called",
3468
+ "distinct_id": "distinct_id_of_your_user",
3469
+ "properties": {
3470
+ "$feature_flag": "feature-flag-key",
3471
+ "$feature_flag_response": "variant-name"
3472
+ }
3473
+ }
3474
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
3475
+ print(response)
3476
+ ```
3477
+
3478
+ ### Advanced: Overriding server properties
3479
+
3480
+ Sometimes, you may want to evaluate feature flags using [person properties](/docs/product-analytics/person-properties.md), [groups](/docs/product-analytics/group-analytics.md), or group properties that haven't been ingested yet, or were set incorrectly earlier.
3481
+
3482
+ You can provide properties to evaluate the flag with by using the `person properties`, `groups`, and `group properties` arguments. PostHog will then use these values to evaluate the flag, instead of any properties currently stored on your PostHog server.
3483
+
3484
+ For example:
3485
+
3486
+ PostHog AI
3487
+
3488
+ ### Terminal
3489
+
3490
+ ```shell
3491
+ curl -v -L --header "Content-Type: application/json" -d ' {
3492
+ "api_key": "<ph_project_token>",
3493
+ "distinct_id": "distinct_id_of_your_user",
3494
+ "groups" : { # Required only for group-based feature flags
3495
+ "group_type": "group_id" # Replace "group_type" with the name of your group type. Replace "group_id" with the id of your group.
3496
+ },
3497
+ "person_properties": {"<personProp1>": "<personVal1>"}, # Optional. Include any properties used to calculate the value of the feature flag.
3498
+ "group_properties": {"group type": {"<groupProp1>":"<groupVal1>"}} # Optional. Include any properties used to calculate the value of the feature flag.
3499
+ }' https://us.i.posthog.com/flags?v=2
3500
+ ```
3501
+
3502
+ ### Python
3503
+
3504
+ ```python
3505
+ import requests
3506
+ import json
3507
+ url = "https://us.i.posthog.com/flags?v=2"
3508
+ headers = {
3509
+ "Content-Type": "application/json"
3510
+ }
3511
+ payload = {
3512
+ "api_key": "<ph_project_token>",
3513
+ "distinct_id": "distinct_id_of_your_user",
3514
+ "groups" : { # Required only for group-based feature flags
3515
+ "group_type": "group_id" # Replace "group_type" with the name of your group type. Replace "group_id" with the id of your group.
3516
+ },
3517
+ "person_properties": {"<personProp1>": "<personVal1>"}, # Optional. Include any properties used to calculate the value of the feature flag.
3518
+ "group_properties": {"group type": {"<groupProp1>":"<groupVal1>"}} # Optional. Include any properties used to calculate the value of the feature flag.
3519
+ }
3520
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
3521
+ print(response.json())
3522
+ ```
3523
+
3524
+ ### Overriding GeoIP properties
3525
+
3526
+ By default, a user's GeoIP properties are set using the IP address they use to capture events on the frontend. You may want to override the these properties when evaluating feature flags. A common reason to do this is when you're not using PostHog on your frontend, so the user has no GeoIP properties.
3527
+
3528
+ To override the GeoIP properties used to evaluate a feature flag, provide an IP address in the `HTTP_X_FORWARDED_FOR` when making your `/flags` request:
3529
+
3530
+ PostHog AI
3531
+
3532
+ ### Terminal
3533
+
3534
+ ```shell
3535
+ curl -v -L \
3536
+ --header "Content-Type: application/json" \
3537
+ --header "HTTP_X_FORWARDED_FOR: the_client_ip_address_to_use " \
3538
+ -d ' {
3539
+ "api_key": "<ph_project_token>",
3540
+ "distinct_id": "distinct_id_of_your_user"
3541
+ }' https://us.i.posthog.com/flags?v=2
3542
+ ```
3543
+
3544
+ ### Python
3545
+
3546
+ ```python
3547
+ import requests
3548
+ import json
3549
+ url = "https://us.i.posthog.com/flags?v=2"
3550
+ headers = {
3551
+ "Content-Type": "application/json",
3552
+ "HTTP_X_FORWARDED_FOR": "the_client_ip_address_to_use"
3553
+ }
3554
+ payload = {
3555
+ "api_key": "<ph_project_token>",
3556
+ "distinct_id": "distinct_id_of_your_user"
3557
+ }
3558
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
3559
+ print(response.json())
3560
+ ```
3561
+
3562
+ The list of properties that this overrides:
3563
+
3564
+ 1. `$geoip_city_name`
3565
+ 2. `$geoip_country_name`
3566
+ 3. `$geoip_country_code`
3567
+ 4. `$geoip_continent_name`
3568
+ 5. `$geoip_continent_code`
3569
+ 6. `$geoip_postal_code`
3570
+ 7. `$geoip_time_zone`
3571
+
3572
+ ### Community questions
3573
+
3574
+ Ask a question
3575
+
3576
+ ### Was this page useful?
3577
+
3578
+ HelpfulCould be better