-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When DEBUG, include posthog.js with local posthog host #1840
Conversation
This was initially included in session recording project, but removed in #1837 Wins of doing it this way: - Less noisy data in production. - Slack thread by @paolodamico: https://posthog.slack.com/archives/C018RGRS10S/p1602486169005700 - Can develop/dogfood feature flags for development. - Used in session recording - can "merge" half-complete solutions that are not yet ready for release - Session recording can be done in localhost now :) Downsides: - If feature flags are not cleaned up, this may cause drift between local checkouts and production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general terms my only concern with this is that this will cause users running debug instances to get events from their PostHog app usage as events from their own app, which can be a bit disconcerting.
As I'm working on #1755 I ran into the same issue that prompted you to consider this change, my solution (unpushed) was this (though I wasn't considering the Cypress case you mentioned). Basically we this we get feature flags without getting noisy data from debug instances.
<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init('sTMFPsFhdP1Ssg', {api_host: 'https://app.posthog.com'{% if debug %}, autocapture: false, capture_pageview: false{% endif %}})
</script>
Thanks for the feedback @paolodamico
@paolodamico Isn't that desirable? My assumption is DEBUG = development environment, correct me if I'm wrong. If not, maybe worth adding another env variable?
This has significant downsides - having to manage dev feature flags from prod makes dogfooding them harder. See wins 2-4 |
I like this a lot, I think we can assume that DEBUG users are likely to actually want these events for testing PostHog on actual data (I want em!). And for those who don't want them, there's env var |
+1 for this. |
Well my only outstanding concern is with users that run the app with |
https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#safe should be of use here. |
This broke tracking See also #1840 (comment)
Changes
This was initially included in session recording project, but removed in
#1837
Wins of doing it this way:
are not yet ready for release
Downsides:
local checkouts and production.
Checklist