Skip to content

Commit

Permalink
laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
Lior539 committed Mar 21, 2024
1 parent 68b369f commit 3f205a6
Show file tree
Hide file tree
Showing 10 changed files with 100 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 @@ -107,6 +107,13 @@ export const allSDKs: SDK[] = [
image: require('./logos/java.svg'),
docsLink: 'https://posthog.com/docs/libraries/java',
},
{
name: 'Laravel',
key: SDKKey.LARAVEL,
tags: [SDKTag.SERVER],
image: require('./logos/laravel.svg'),
docsLink: 'https://posthog.com/docs/libraries/laravel',
},
{
name: 'Next.js',
key: SDKKey.NEXT_JS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
FeatureFlagsGoInstructions,
FeatureFlagsIOSInstructions,
FeatureFlagsJSWebInstructions,
FeatureFlagsLaravelInstructions,
FeatureFlagsNextJSInstructions,
FeatureFlagsNodeInstructions,
FeatureFlagsPHPInstructions,
Expand All @@ -31,6 +32,7 @@ export const FeatureFlagsSDKInstructions: SDKInstructionsMap = {
[SDKKey.FRAMER]: FeatureFlagsFramerInstructions,
[SDKKey.GO]: FeatureFlagsGoInstructions,
[SDKKey.IOS]: FeatureFlagsIOSInstructions,
[SDKKey.LARAVEL]: FeatureFlagsLaravelInstructions,
[SDKKey.NEXT_JS]: FeatureFlagsNextJSInstructions,
[SDKKey.NODE_JS]: FeatureFlagsNodeInstructions,
[SDKKey.PHP]: FeatureFlagsPHPInstructions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './framer'
export * from './go'
export * from './ios'
export * from './js-web'
export * from './laravel'
export * from './next-js'
export * from './nodejs'
export * from './php'
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/scenes/onboarding/sdks/feature-flags/laravel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { SDKKey } from '~/types'

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

export function FeatureFlagsLaravelInstructions(): JSX.Element {
return (
<>
<SDKInstallLaravelInstructions />
<FlagImplementationSnippet sdkKey={SDKKey.PHP} />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ProductAnalyticsFramerInstructions,
ProductAnalyticsGoInstructions,
ProductAnalyticsIOSInstructions,
ProductAnalyticsLaravelInstructions,
ProductAnalyticsNextJSInstructions,
ProductAnalyticsNodeInstructions,
ProductAnalyticsPHPInstructions,
Expand All @@ -34,6 +35,7 @@ export const ProductAnalyticsSDKInstructions: SDKInstructionsMap = {
[SDKKey.GO]: ProductAnalyticsGoInstructions,
[SDKKey.HTML_SNIPPET]: HTMLSnippetInstructions,
[SDKKey.IOS]: ProductAnalyticsIOSInstructions,
[SDKKey.LARAVEL]: ProductAnalyticsLaravelInstructions,
[SDKKey.NEXT_JS]: ProductAnalyticsNextJSInstructions,
[SDKKey.NODE_JS]: ProductAnalyticsNodeInstructions,
[SDKKey.PHP]: ProductAnalyticsPHPInstructions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './go'
export * from './html-snippet'
export * from './ios'
export * from './js-web'
export * from './laravel'
export * from './next-js'
export * from './nodejs'
export * from './php'
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/scenes/onboarding/sdks/product-analytics/laravel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'

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

function LaravelCaptureSnippet(): JSX.Element {
return (
<CodeSnippet language={Language.PHP}>
{"PostHog::capture(array(\n 'distinctId' => 'test-user',\n 'event' => 'test-event'\n));"}
</CodeSnippet>
)
}

export function ProductAnalyticsLaravelInstructions(): JSX.Element {
return (
<>
<SDKInstallLaravelInstructions />
<h3>Send an Event</h3>
<LaravelCaptureSnippet />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './framer'
export * from './go'
export * from './ios'
export * from './js-web'
export * from './laravel'
export * from './nodejs'
export * from './php'
export * from './python'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useValues } from 'kea'
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
import { apiHostOrigin } from 'lib/utils/apiHost'
import { teamLogic } from 'scenes/teamLogic'

function LaravelConfigSnippet(): JSX.Element {
return <CodeSnippet language={Language.Bash}>composer require posthog/posthog-php</CodeSnippet>
}

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

return (
<CodeSnippet language={Language.PHP}>
{`<?php
namespace App\\Providers;
use Illuminate\\Support\\ServiceProvider;
use PostHog\\PostHog;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
PostHog::init(
'${currentTeam?.api_token}',
[
'host' => '${apiHostOrigin()}'
]
);
}
}
`}
</CodeSnippet>
)
}

export function SDKInstallLaravelInstructions(): JSX.Element {
return (
<>
<h3>Dependency Setup</h3>
<LaravelConfigSnippet />
<h3>Configure</h3>
<p>
Initialize PostHog in the <code>boot</code> method of <code>app/Providers/AppServiceProvider.php</code>
</p>
<LaravelInstallSnippet />
</>
)
}
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3747,6 +3747,7 @@ export enum SDKKey {
IOS = 'ios',
JAVA = 'java',
JS_WEB = 'javascript_web',
LARAVEL = 'laravel',
NEXT_JS = 'nextjs',
NODE_JS = 'nodejs',
NUXT_JS = 'nuxtjs',
Expand Down

0 comments on commit 3f205a6

Please sign in to comment.