Skip to content

Commit

Permalink
feat: split snippet sdks into JS web and HTML snippet (#20023)
Browse files Browse the repository at this point in the history
* split JS snippet into package and HTML

* do for replay

* do for surveys

* clarify that it's a manual event

* Update UI snapshots for `chromium` (1)

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
raquelmsmith and github-actions[bot] authored Jan 30, 2024
1 parent 285b9d8 commit 437f9ed
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 16 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions frontend/src/scenes/onboarding/sdks/allSDKs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ export const allSDKs: SDK[] = [
image: require('./logos/javascript_web.svg'),
docsLink: 'https://posthog.com/docs/libraries/js',
},
{
name: 'HTML snippet',
key: SDKKey.HTML_SNIPPET,
recommended: true,
tags: [SDKTag.RECOMMENDED, SDKTag.WEB],
image: require('./logos/html.svg'),
docsLink: 'https://posthog.com/docs/libraries/js',
},
{
name: 'React',
key: SDKKey.REACT,
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/scenes/onboarding/sdks/logos/html.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SDKInstructionsMap, SDKKey } from '~/types'

import {
HTMLSnippetInstructions,
JSWebInstructions,
ProductAnalyticsAndroidInstructions,
ProductAnalyticsAPIInstructions,
Expand All @@ -17,6 +18,7 @@ import {

export const ProductAnalyticsSDKInstructions: SDKInstructionsMap = {
[SDKKey.JS_WEB]: JSWebInstructions,
[SDKKey.HTML_SNIPPET]: HTMLSnippetInstructions,
// add next, getsby, and others here
[SDKKey.IOS]: ProductAnalyticsIOSInstructions,
[SDKKey.REACT_NATIVE]: ProductAnalyticsRNInstructions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { LemonDivider } from '@posthog/lemon-ui'
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'

import { SDKHtmlSnippetInstructions } from '../sdk-install-instructions/html-snippet'

function JSEventSnippet(): JSX.Element {
return (
<CodeSnippet language={Language.JavaScript}>{`posthog.capture('my event', { property: 'value' })`}</CodeSnippet>
)
}

export function HTMLSnippetInstructions(): JSX.Element {
return (
<>
<SDKHtmlSnippetInstructions />
<LemonDivider thick dashed className="my-4" />
<h4>Optional: Send a manual event</h4>
<p>Our snippet will autocapture events for you, but you can manually define events, too!</p>
<JSEventSnippet />
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './api'
export * from './elixir'
export * from './flutter'
export * from './go'
export * from './html-snippet'
export * from './ios'
export * from './js-web'
export * from './nodejs'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function JSWebInstructions(): JSX.Element {
<>
<SDKInstallJSWebInstructions />
<LemonDivider thick dashed className="my-4" />
<h4>Send your first event</h4>
<h4>Optional: Send a manual event</h4>
<p>Our package will autocapture events for you, but you can manually define events, too!</p>
<JSEventSnippet />
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export function ProductAnalyticsRNInstructions(): JSX.Element {
return (
<>
<SDKInstallRNInstructions />
<h3 className="mt-4">Send an Event</h3>
<h3 className="mt-4">Optional: Send a manual event</h3>
<p>Our package will autocapture events for you, but you can manually define events, too!</p>
<CodeSnippet language={Language.JSX}>{`// With hooks
import { usePostHog } from 'posthog-react-native'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { JSSnippet } from 'lib/components/JSSnippet'

export function SDKHtmlSnippetInstructions(): JSX.Element {
return (
<>
<h3>Install</h3>
<p>
Just add this snippet to your website within the <code>&lt;head&gt;</code> tag and you'll be ready to
start using PostHog. This can also be used in services like Google Tag Manager.
</p>
<JSSnippet />
</>
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useValues } from 'kea'
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
import { JSSnippet } from 'lib/components/JSSnippet'
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { teamLogic } from 'scenes/teamLogic'

export function JSInstallSnippet(): JSX.Element {
Expand Down Expand Up @@ -29,17 +27,9 @@ export function JSSetupSnippet(): JSX.Element {
export function SDKInstallJSWebInstructions(): JSX.Element {
return (
<>
<h3>Option 1. Code snippet</h3>
<p>
Just add this snippet to your website within the <code>&lt;head&gt;</code> tag and you'll be ready to
start using PostHog.{' '}
</p>
<JSSnippet />
<LemonDivider thick dashed className="my-4" />
<h3>Option 2. Javascript Library</h3>
<h4>Install the package</h4>
<h3>Install</h3>
<JSInstallSnippet />
<h4>Initialize</h4>
<h3>Initialize</h3>
<JSSetupSnippet />
</>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { SDKInstructionsMap, SDKKey } from '~/types'

import { JSWebInstructions, NextJSInstructions, ReactInstructions } from '.'
import { HTMLSnippetInstructions, JSWebInstructions, NextJSInstructions, ReactInstructions } from '.'

export const SessionReplaySDKInstructions: SDKInstructionsMap = {
[SDKKey.JS_WEB]: JSWebInstructions,
[SDKKey.HTML_SNIPPET]: HTMLSnippetInstructions,
[SDKKey.NEXT_JS]: NextJSInstructions,
[SDKKey.REACT]: ReactInstructions,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'

import { SDKHtmlSnippetInstructions } from '../sdk-install-instructions/html-snippet'
import { SessionReplayFinalSteps } from '../shared-snippets'

export function HTMLSnippetInstructions(): JSX.Element {
return (
<>
<SDKHtmlSnippetInstructions />
<LemonDivider thick dashed className="my-4" />
<h3>Final steps</h3>
<SessionReplayFinalSteps />
</>
)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './html-snippet'
export * from './js-web'
export * from './next-js'
export * from './react'
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { SDKInstructionsMap, SDKKey } from '~/types'

import { JSWebInstructions, NextJSInstructions, ReactInstructions } from '.'
import { HTMLSnippetInstructions, JSWebInstructions, NextJSInstructions, ReactInstructions } from '.'

export const SurveysSDKInstructions: SDKInstructionsMap = {
[SDKKey.JS_WEB]: JSWebInstructions,
[SDKKey.HTML_SNIPPET]: HTMLSnippetInstructions,
[SDKKey.NEXT_JS]: NextJSInstructions,
[SDKKey.REACT]: ReactInstructions,
}
14 changes: 14 additions & 0 deletions frontend/src/scenes/onboarding/sdks/surveys/html-snippet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'

import { SDKHtmlSnippetInstructions } from '../sdk-install-instructions/html-snippet'
import { SurveysFinalSteps } from './SurveysFinalSteps'

export function HTMLSnippetInstructions(): JSX.Element {
return (
<>
<SDKHtmlSnippetInstructions />
<LemonDivider thick dashed className="my-4" />
<SurveysFinalSteps />
</>
)
}
1 change: 1 addition & 0 deletions frontend/src/scenes/onboarding/sdks/surveys/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './html-snippet'
export * from './js-web'
export * from './next-js'
export * from './react'
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3683,6 +3683,7 @@ export enum SDKKey {
WORDPRESS = 'wordpress',
SENTRY = 'sentry',
RETOOL = 'retool',
HTML_SNIPPET = 'html',
}

export enum SDKTag {
Expand Down

0 comments on commit 437f9ed

Please sign in to comment.