Skip to content
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

fix: Option to redirect app.posthog.com traffic to us.posthog.com #19377

Merged
merged 16 commits into from
Dec 17, 2023
4 changes: 3 additions & 1 deletion frontend/src/lib/components/JSSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export function JSSnippet(): JSX.Element {
return (
<CodeSnippet language={Language.HTML}>{`<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 getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".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('${currentTeam?.api_token}',{api_host:'${window.location.origin}'})
posthog.init('${currentTeam?.api_token}',{api_host:'${
window.location.origin === 'https://us.posthog.com' ? 'https://app.posthog.com' : window.location.origin
}'})
</script>`}</CodeSnippet>
)
}
3 changes: 3 additions & 0 deletions posthog/settings/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,6 @@ def add_recorder_js_headers(headers, path, url):
# temporary flag to control new UUID version setting in posthog-js
# is set to v7 to test new generation but can be set to "og" to revert
POSTHOG_JS_UUID_VERSION = os.getenv("POSTHOG_JS_UUID_VERSION", "v7")

# Temporary option to redirect all traffic from app.posthog.com to us.posthog.com
REDIRECT_APP_TO_US = get_from_env("REDIRECT_APP_TO_US", False, type_cast=str_to_bool)
4 changes: 3 additions & 1 deletion posthog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.parse import urlparse

from django.conf import settings
from django.http import HttpRequest, HttpResponse, HttpResponseServerError
from django.http import HttpRequest, HttpResponse, HttpResponseServerError, HttpResponseRedirect
from django.template import loader
from django.urls import URLPattern, include, path, re_path
from django.views.decorators.csrf import (
Expand Down Expand Up @@ -90,6 +90,8 @@

@ensure_csrf_cookie
def home(request, *args, **kwargs):
if settings.REDIRECT_APP_TO_US and request.build_absolute_uri().startswith("http://app.posthog.com"):
timgl marked this conversation as resolved.
Show resolved Hide resolved
Fixed Show fixed Hide fixed
return HttpResponseRedirect("https://us.posthog.com{}".format(request.get_full_path()))
Fixed Show fixed Hide fixed
return render_template("index.html", request)


Expand Down
Loading