Skip to content

Commit

Permalink
feat: Swap ingestion endpoints to new .i.posthog.com ones (#20736)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Apr 22, 2024
1 parent 8c8f7bd commit a8bcc67
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 72 deletions.
4 changes: 2 additions & 2 deletions bin/deploy-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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'"
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/auto-redirect.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% include "head.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".split(" "), n = 0; n < o.length; n++)g(u, o[n]); e._i.push([i, s, a]) }, e.__SV = 1) }(document, window.posthog || []);
!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.replace(".i.posthog.com","-assets.i.posthog.com")+"/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({{ js_posthog_api_key | safe}}, { api_host: {{ js_posthog_host | safe}}, persistence: 'localStorage+cookie'})
</script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const sidePanelDocsLogic = kea<sidePanelDocsLogicType>([
}

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
}
Expand Down
22 changes: 15 additions & 7 deletions frontend/src/lib/components/JSSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<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:'${apiHostOrigin()}'})
</script>`}</CodeSnippet>
)
return [
'<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.replace(".i.posthog.com","-assets.i.posthog.com")+"/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:'${apiHostOrigin()}'})`,
'</script>',
]
.map((x) => ' '.repeat(indent) + x)
.join('\n')
}

export function JSSnippet(): JSX.Element {
const snippet = useJsSnippet()

return <CodeSnippet language={Language.HTML}>{snippet}</CodeSnippet>
}
7 changes: 5 additions & 2 deletions frontend/src/lib/utils/apiHost.ts
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
{
Expand Down Expand Up @@ -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',
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -38,19 +39,15 @@ function FlutterIOSSetupSnippet(): JSX.Element {
}

function FlutterWebSetupSnippet(): JSX.Element {
const { currentTeam } = useValues(teamLogic)
const url = apiHostOrigin()
const jsSnippet = useJsSnippet(4)

return (
<CodeSnippet language={Language.HTML}>
{`<!DOCTYPE html>
<html>
<head>
...
<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".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: '${url}'})
</script>
${jsSnippet}
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/toolbar-launch/ToolbarLaunch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function ToolbarLaunch(): JSX.Element {
</h2>
<p>
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.'}
</p>
<AuthorizedUrlList type={AuthorizedUrlListType.TOOLBAR_URLS} addText="Add authorized URL" />

Expand Down
2 changes: 1 addition & 1 deletion plugin-server/src/utils/posthog.ts
Original file line number Diff line number Diff line change
@@ -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') {
Expand Down
4 changes: 2 additions & 2 deletions posthog/ph_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 1 addition & 21 deletions posthog/year_in_posthog/2023.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,7 @@
<link rel="preload" href="{% static image_webp %}" as="image">
<link rel="preload" href="{% static 'year_in_hog/background.png' %}" as="image">
<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 || []);
!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.replace(".i.posthog.com","-assets.i.posthog.com")+"/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('{{api_token}}', {
api_host: window.location.origin, loaded: function (posthog) {
posthog.capture('year in posthog viewed', {
Expand Down
24 changes: 1 addition & 23 deletions posthog/year_in_posthog/hibernating.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,7 @@


<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 || []);
!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.replace(".i.posthog.com","-assets.i.posthog.com")+"/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('{{api_token}}', {
api_host: window.location.origin, loaded: function (posthog) {
posthog.capture('year in posthog hibernating viewed', {
Expand Down

0 comments on commit a8bcc67

Please sign in to comment.