Skip to content

Commit

Permalink
django
Browse files Browse the repository at this point in the history
  • Loading branch information
Lior539 committed Mar 26, 2024
1 parent 6686f19 commit d437771
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 0 deletions.
7 changes: 7 additions & 0 deletions frontend/src/scenes/onboarding/sdks/allSDKs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ export const allSDKs: SDK[] = [
image: require('./logos/bubble.svg'),
docsLink: 'https://posthog.com/docs/libraries/bubble',
},
{
name: 'Django',
key: SDKKey.DJANGO,
tags: [SDKTag.SERVER],
image: require('./logos/django.svg'),
docsLink: 'https://posthog.com/docs/libraries/django',
},
{
name: 'Elixir',
key: SDKKey.ELIXIR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FeatureFlagsAPIInstructions,
FeatureFlagsAstroInstructions,
FeatureFlagsBubbleInstructions,
FeatureFlagsDjangoInstructions,
FeatureFlagsFlutterInstructions,
FeatureFlagsFramerInstructions,
FeatureFlagsGoInstructions,
Expand Down Expand Up @@ -33,6 +34,7 @@ export const FeatureFlagsSDKInstructions: SDKInstructionsMap = {
[SDKKey.API]: FeatureFlagsAPIInstructions,
[SDKKey.ASTRO]: FeatureFlagsAstroInstructions,
[SDKKey.BUBBLE]: FeatureFlagsBubbleInstructions,
[SDKKey.DJANGO]: FeatureFlagsDjangoInstructions,
[SDKKey.FLUTTER]: FeatureFlagsFlutterInstructions,
[SDKKey.FRAMER]: FeatureFlagsFramerInstructions,
[SDKKey.GO]: FeatureFlagsGoInstructions,
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/scenes/onboarding/sdks/feature-flags/django.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SDKKey } from '~/types'

import { SDKInstallDjangoInstructions } from '../sdk-install-instructions'
import { FlagImplementationSnippet } from './flagImplementationSnippet'

export function FeatureFlagsDjangoInstructions(): JSX.Element {
return (
<>
<SDKInstallDjangoInstructions />
<FlagImplementationSnippet sdkKey={SDKKey.DJANGO} />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './angular'
export * from './api'
export * from './astro'
export * from './bubble'
export * from './django'
export * from './flutter'
export * from './framer'
export * from './go'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ProductAnalyticsAPIInstructions,
ProductAnalyticsAstroInstructions,
ProductAnalyticsBubbleInstructions,
ProductAnalyticsDjangoInstructions,
ProductAnalyticsElixirInstructions,
ProductAnalyticsFlutterInstructions,
ProductAnalyticsFramerInstructions,
Expand All @@ -34,6 +35,7 @@ export const ProductAnalyticsSDKInstructions: SDKInstructionsMap = {
[SDKKey.API]: ProductAnalyticsAPIInstructions,
[SDKKey.ASTRO]: ProductAnalyticsAstroInstructions,
[SDKKey.BUBBLE]: ProductAnalyticsBubbleInstructions,
[SDKKey.DJANGO]: ProductAnalyticsDjangoInstructions,
[SDKKey.ELIXIR]: ProductAnalyticsElixirInstructions,
[SDKKey.FLUTTER]: ProductAnalyticsFlutterInstructions,
[SDKKey.FRAMER]: ProductAnalyticsFramerInstructions,
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/scenes/onboarding/sdks/product-analytics/django.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'

import { SDKInstallDjangoInstructions } from '../sdk-install-instructions'

function DjangoCaptureSnippet(): JSX.Element {
return (
<CodeSnippet language={Language.Python}>{`import posthog
posthog.capture('test-id', 'test-event')`}</CodeSnippet>
)
}

export function ProductAnalyticsDjangoInstructions(): JSX.Element {
return (
<>
<SDKInstallDjangoInstructions />
<h3>Send an Event</h3>
<DjangoCaptureSnippet />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './angular'
export * from './api'
export * from './astro'
export * from './bubble'
export * from './django'
export * from './elixir'
export * from './flutter'
export * from './framer'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useValues } from 'kea'
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
import { apiHostOrigin } from 'lib/utils/apiHost'
import { teamLogic } from 'scenes/teamLogic'

function DjangoInstallSnippet(): JSX.Element {
return <CodeSnippet language={Language.Bash}>pip install posthog</CodeSnippet>
}

function DjangoAppConfigSnippet(): JSX.Element {
const { currentTeam } = useValues(teamLogic)

return (
<CodeSnippet language={Language.Python}>
{`from django.apps import AppConfig
import posthog
class YourAppConfig(AppConfig):
name = "your_app_name"
def ready(self):
posthog.api_key = '${currentTeam?.api_token}'
posthog.host = '${apiHostOrigin()}'`}
</CodeSnippet>
)
}

function DjangoSettingsSnippet(): JSX.Element {
return (
<CodeSnippet language={Language.Python}>
{`INSTALLED_APPS = [
# other apps
'your_app_name.apps.MyAppConfig', # Add your app config
] `}
</CodeSnippet>
)
}

export function SDKInstallDjangoInstructions(): JSX.Element {
return (
<>
<h3>Install</h3>
<DjangoInstallSnippet />
<h3>Configure</h3>
<p>
Set the PostHog API key and host in your <code>AppConfig</code> in <code>apps.py</code> so that's it's
available everywhere:
</p>
<DjangoAppConfigSnippet />
<p />
Next, if you haven't done so already, make sure you add your <code>AppConfig</code> to your{' '}
<code>settings.py</code> under <code>INSTALLED_APPS</code>:
<DjangoSettingsSnippet />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './android'
export * from './angular'
export * from './astro'
export * from './bubble'
export * from './django'
export * from './elixir'
export * from './flutter'
export * from './framer'
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3744,6 +3744,7 @@ export enum SDKKey {
ASTRO = 'astro',
API = 'api',
BUBBLE = 'bubble',
DJANGO = 'django',
DOCUSAURUS = 'docusaurus',
ELIXIR = 'elixir',
FRAMER = 'framer',
Expand Down

0 comments on commit d437771

Please sign in to comment.