From 94159814f6cc65a5d918e6d3703290850afa027b Mon Sep 17 00:00:00 2001 From: Ben White Date: Wed, 6 Mar 2024 16:40:46 +0100 Subject: [PATCH 1/2] Fixed up ingestion endpoints --- bin/deploy-hobby | 4 ++-- cypress/e2e/auto-redirect.cy.ts | 2 +- .../sidepanel/panels/sidePanelDocsLogic.ts | 2 +- frontend/src/lib/components/JSSnippet.tsx | 22 +++++++++++++------ frontend/src/lib/utils/apiHost.ts | 7 ++++-- .../feature-flags/FeatureFlagSnippets.tsx | 2 +- .../NotebookTemplates/notebookTemplates.ts | 4 ++-- .../sdks/sdk-install-instructions/flutter.tsx | 9 +++----- .../sdks/sdk-install-instructions/next-js.tsx | 2 +- .../scenes/toolbar-launch/ToolbarLaunch.tsx | 2 +- frontend/src/toolbar/posthog.ts | 2 +- plugin-server/src/utils/posthog.ts | 2 +- posthog/ph_client.py | 4 ++-- posthog/utils.py | 4 ++-- 14 files changed, 38 insertions(+), 30 deletions(-) diff --git a/bin/deploy-hobby b/bin/deploy-hobby index 5e7f2f8bfb7e6..d57c81bc996d4 100755 --- a/bin/deploy-hobby +++ b/bin/deploy-hobby @@ -67,7 +67,7 @@ curl -o /dev/null -L --header "Content-Type: application/json" -d "{ \"properties\": {\"domain\": \"${DOMAIN}\"}, \"type\": \"capture\", \"event\": \"magic_curl_install_start\" -}" https://app.posthog.com/batch/ &> /dev/null +}" https://us.i.posthog.com/batch/ &> /dev/null # update apt cache echo "Grabbing latest apt caches" @@ -223,7 +223,7 @@ curl -o /dev/null -L --header "Content-Type: application/json" -d "{ \"properties\": {\"domain\": \"${DOMAIN}\"}, \"type\": \"capture\", \"event\": \"magic_curl_install_complete\" -}" https://app.posthog.com/batch/ &> /dev/null +}" https://us.i.posthog.com/batch/ &> /dev/null echo "" echo "To stop the stack run 'docker-compose stop'" echo "To start the stack again run 'docker-compose start'" diff --git a/cypress/e2e/auto-redirect.cy.ts b/cypress/e2e/auto-redirect.cy.ts index 748a41037cc4c..4cacef126c381 100644 --- a/cypress/e2e/auto-redirect.cy.ts +++ b/cypress/e2e/auto-redirect.cy.ts @@ -29,7 +29,7 @@ describe('Redirect to other subdomain if logged in', () => { cy.visit(`/login?next=${redirect_path}`) - cy.setCookie('ph_current_instance', `"app.posthog.com"`) + cy.setCookie('ph_current_instance', `"us.posthog.com"`) cy.setCookie('is-logged-in', '1') cy.reload() diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/sidePanelDocsLogic.ts b/frontend/src/layout/navigation-3000/sidepanel/panels/sidePanelDocsLogic.ts index e58677430455c..8ea83b3ce016e 100644 --- a/frontend/src/layout/navigation-3000/sidepanel/panels/sidePanelDocsLogic.ts +++ b/frontend/src/layout/navigation-3000/sidepanel/panels/sidePanelDocsLogic.ts @@ -157,7 +157,7 @@ export const sidePanelDocsLogic = kea([ } if (event.data.type === 'external-navigation') { - // This should only be triggered for app|eu.posthog.com links + // This should only be triggered for us|eu.posthog.com links actions.handleExternalUrl(event.data.url) return } diff --git a/frontend/src/lib/components/JSSnippet.tsx b/frontend/src/lib/components/JSSnippet.tsx index 119d84622b9af..7dde2318e22ae 100644 --- a/frontend/src/lib/components/JSSnippet.tsx +++ b/frontend/src/lib/components/JSSnippet.tsx @@ -3,13 +3,21 @@ import { CodeSnippet, Language } from 'lib/components/CodeSnippet' import { apiHostOrigin } from 'lib/utils/apiHost' import { teamLogic } from 'scenes/teamLogic' -export function JSSnippet(): JSX.Element { +export function useJsSnippet(indent = 0): string { const { currentTeam } = useValues(teamLogic) - return ( - {``} - ) + return [ + '', + ] + .map((x) => ' '.repeat(indent) + x) + .join('\n') +} + +export function JSSnippet(): JSX.Element { + const snippet = useJsSnippet() + + return {snippet} } diff --git a/frontend/src/lib/utils/apiHost.ts b/frontend/src/lib/utils/apiHost.ts index 6b47d8c9c8aea..d61f473573cef 100644 --- a/frontend/src/lib/utils/apiHost.ts +++ b/frontend/src/lib/utils/apiHost.ts @@ -1,8 +1,11 @@ export function apiHostOrigin(): string { let apiHost = window.location.origin - // similar to https://github.com/PostHog/posthog-js/blob/b79315b7a4fa0caded7026bda2fec01defb0ba73/src/posthog-core.ts#L1742 + if (apiHost === 'https://us.posthog.com') { - apiHost = 'https://app.posthog.com' + apiHost = 'https://us.i.posthog.com' + } else if (apiHost === 'https://eu.posthog.com') { + apiHost = 'https://eu.i.posthog.com' } + return apiHost } diff --git a/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx b/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx index 06037bb23c2ea..6130aa984820f 100644 --- a/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx +++ b/frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx @@ -534,7 +534,7 @@ export function JSBootstrappingSnippet(): JSX.Element { // This avoids the delay between the library loading and feature flags becoming available to use. posthog.init('{project_api_key}', { - api_host: 'https://app.posthog.com', + api_host: '${apiHostOrigin()}' bootstrap: { distinctID: 'your-anonymous-id', diff --git a/frontend/src/scenes/notebooks/NotebookTemplates/notebookTemplates.ts b/frontend/src/scenes/notebooks/NotebookTemplates/notebookTemplates.ts index 3ff279c9b060f..f1c63fe133674 100644 --- a/frontend/src/scenes/notebooks/NotebookTemplates/notebookTemplates.ts +++ b/frontend/src/scenes/notebooks/NotebookTemplates/notebookTemplates.ts @@ -313,7 +313,7 @@ export const LOCAL_NOTEBOOK_TEMPLATES: NotebookType[] = [ __init: null, children: null, file: null, - src: 'https://app.posthog.com/uploaded_media/018c494d-132b-0000-2004-8861f35c13b5', + src: 'https://us.posthog.com/uploaded_media/018c494d-132b-0000-2004-8861f35c13b5', }, }, { @@ -643,7 +643,7 @@ export const LOCAL_NOTEBOOK_TEMPLATES: NotebookType[] = [ __init: null, children: null, file: null, - src: 'https://app.posthog.com/uploaded_media/018c496c-d79a-0000-bbc8-fdb0c77ec46f', + src: 'https://us.posthog.com/uploaded_media/018c496c-d79a-0000-bbc8-fdb0c77ec46f', }, }, { diff --git a/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/flutter.tsx b/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/flutter.tsx index 67e3a4a7799d3..e5164e93d378e 100644 --- a/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/flutter.tsx +++ b/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/flutter.tsx @@ -1,5 +1,6 @@ import { useValues } from 'kea' import { CodeSnippet, Language } from 'lib/components/CodeSnippet' +import { useJsSnippet } from 'lib/components/JSSnippet' import { apiHostOrigin } from 'lib/utils/apiHost' import { teamLogic } from 'scenes/teamLogic' @@ -38,8 +39,7 @@ function FlutterIOSSetupSnippet(): JSX.Element { } function FlutterWebSetupSnippet(): JSX.Element { - const { currentTeam } = useValues(teamLogic) - const url = apiHostOrigin() + const jsSnippet = useJsSnippet(4) return ( @@ -47,10 +47,7 @@ function FlutterWebSetupSnippet(): JSX.Element { ... - +${jsSnippet} diff --git a/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/next-js.tsx b/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/next-js.tsx index 2aa0271b2dee5..8b6a77fbdc3de 100644 --- a/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/next-js.tsx +++ b/frontend/src/scenes/onboarding/sdks/sdk-install-instructions/next-js.tsx @@ -27,7 +27,7 @@ import { PostHogProvider } from 'posthog-js/react' if (typeof window !== 'undefined') { // checks that we are client-side posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, { - api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com', + api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || '${apiHostOrigin()}', loaded: (posthog) => { if (process.env.NODE_ENV === 'development') posthog.debug() // debug mode in development }, diff --git a/frontend/src/scenes/toolbar-launch/ToolbarLaunch.tsx b/frontend/src/scenes/toolbar-launch/ToolbarLaunch.tsx index b5f1602ec42ff..53dfd8769762e 100644 --- a/frontend/src/scenes/toolbar-launch/ToolbarLaunch.tsx +++ b/frontend/src/scenes/toolbar-launch/ToolbarLaunch.tsx @@ -48,7 +48,7 @@ function ToolbarLaunch(): JSX.Element {

Click on the URL to launch the toolbar.{' '} - {window.location.host === 'app.posthog.com' && 'Remember to disable your adblocker.'} + {window.location.host.includes('.posthog.com') && 'Remember to disable your adblocker.'}

diff --git a/frontend/src/toolbar/posthog.ts b/frontend/src/toolbar/posthog.ts index 6a492c37cf4e5..e16b561f760a7 100644 --- a/frontend/src/toolbar/posthog.ts +++ b/frontend/src/toolbar/posthog.ts @@ -4,7 +4,7 @@ const DEFAULT_API_KEY = 'sTMFPsFhdP1Ssg' const runningOnPosthog = !!window.POSTHOG_APP_CONTEXT const apiKey = runningOnPosthog ? window.JS_POSTHOG_API_KEY : DEFAULT_API_KEY -const apiHost = runningOnPosthog ? window.JS_POSTHOG_HOST : 'https://app.posthog.com' +const apiHost = runningOnPosthog ? window.JS_POSTHOG_HOST : 'https://us.i.posthog.com' export const posthog = new PostHog(apiKey || DEFAULT_API_KEY, { host: apiHost, diff --git a/plugin-server/src/utils/posthog.ts b/plugin-server/src/utils/posthog.ts index 2f6ada2300fb5..b63604628eb2f 100644 --- a/plugin-server/src/utils/posthog.ts +++ b/plugin-server/src/utils/posthog.ts @@ -1,7 +1,7 @@ import { PostHog } from 'posthog-node' export const posthog = new PostHog('sTMFPsFhdP1Ssg', { - host: 'https://app.posthog.com', + host: 'https://us.i.posthog.com', }) if (process.env.NODE_ENV === 'test') { diff --git a/posthog/ph_client.py b/posthog/ph_client.py index e81161a59d470..9775ebd9a0334 100644 --- a/posthog/ph_client.py +++ b/posthog/ph_client.py @@ -14,10 +14,10 @@ def get_ph_client(): region = get_instance_region() if region == "EU": api_key = "phc_dZ4GK1LRjhB97XozMSkEwPXx7OVANaJEwLErkY1phUF" - host = "https://eu.posthog.com" + host = "https://eu.i.posthog.com" elif region == "US": api_key = "sTMFPsFhdP1Ssg" - host = "https://app.posthog.com" + host = "https://us.i.posthog.com" if not api_key: return diff --git a/posthog/utils.py b/posthog/utils.py index b50b37b73c877..109a89e1a46f9 100644 --- a/posthog/utils.py +++ b/posthog/utils.py @@ -302,7 +302,7 @@ def render_template( if settings.E2E_TESTING: context["e2e_testing"] = True context["js_posthog_api_key"] = "'phc_ex7Mnvi4DqeB6xSQoXU1UVPzAmUIpiciRKQQXGGTYQO'" - context["js_posthog_host"] = "'https://app.posthog.com'" + context["js_posthog_host"] = "'https://us.i.posthog.com'" elif settings.SELF_CAPTURE: api_token = get_self_capture_api_token(request) @@ -311,7 +311,7 @@ def render_template( context["js_posthog_host"] = "window.location.origin" else: context["js_posthog_api_key"] = "'sTMFPsFhdP1Ssg'" - context["js_posthog_host"] = "'https://app.posthog.com'" + context["js_posthog_host"] = "'https://us.i.posthog.com'" context["js_capture_time_to_see_data"] = settings.CAPTURE_TIME_TO_SEE_DATA context["js_kea_verbose_logging"] = settings.KEA_VERBOSE_LOGGING From 9d73067c7297ef1821f075997df9189752851e49 Mon Sep 17 00:00:00 2001 From: Ben White Date: Fri, 15 Mar 2024 12:57:17 +0100 Subject: [PATCH 2/2] Added check for assets to snippet --- frontend/src/layout.html | 2 +- frontend/src/lib/components/JSSnippet.tsx | 2 +- posthog/year_in_posthog/2023.html | 22 +-------------------- posthog/year_in_posthog/hibernating.html | 24 +---------------------- 4 files changed, 4 insertions(+), 46 deletions(-) diff --git a/frontend/src/layout.html b/frontend/src/layout.html index f3468333c3d5a..f82afa51791d6 100644 --- a/frontend/src/layout.html +++ b/frontend/src/layout.html @@ -7,7 +7,7 @@ {% include "head.html" %} ', - ` !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', ] diff --git a/posthog/year_in_posthog/2023.html b/posthog/year_in_posthog/2023.html index 54ff75cc4cb06..113ec1730c381 100644 --- a/posthog/year_in_posthog/2023.html +++ b/posthog/year_in_posthog/2023.html @@ -20,27 +20,7 @@