Skip to content

Commit

Permalink
chore: Make Android SDK v3 GA - update code snippes (#19074)
Browse files Browse the repository at this point in the history
* Chore: Make Android SDK v3 GA - update code snippes

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (1)

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
marandaneto and github-actions[bot] authored Dec 6, 2023
1 parent d0de79a commit 6d6725a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
3 changes: 3 additions & 0 deletions frontend/src/lib/components/CodeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import java from 'react-syntax-highlighter/dist/esm/languages/prism/java'
import javascript from 'react-syntax-highlighter/dist/esm/languages/prism/javascript'
import json from 'react-syntax-highlighter/dist/esm/languages/prism/json'
import jsx from 'react-syntax-highlighter/dist/esm/languages/prism/jsx'
import kotlin from 'react-syntax-highlighter/dist/esm/languages/prism/kotlin'
import markup from 'react-syntax-highlighter/dist/esm/languages/prism/markup'
import objectiveC from 'react-syntax-highlighter/dist/esm/languages/prism/objectivec'
import php from 'react-syntax-highlighter/dist/esm/languages/prism/php'
Expand Down Expand Up @@ -52,6 +53,7 @@ export enum Language {
HTTP = 'http',
Markup = 'markup',
SQL = 'sql',
Kotlin = 'kotlin',
}

SyntaxHighlighter.registerLanguage(Language.Bash, bash)
Expand All @@ -73,6 +75,7 @@ SyntaxHighlighter.registerLanguage(Language.XML, markup)
SyntaxHighlighter.registerLanguage(Language.Markup, markup)
SyntaxHighlighter.registerLanguage(Language.HTTP, http)
SyntaxHighlighter.registerLanguage(Language.SQL, sql)
SyntaxHighlighter.registerLanguage(Language.Kotlin, kotlin)

export interface Action {
icon: React.ReactElement
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/feature-flags/FeatureFlagSnippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,13 @@ if ${conditional}:
}

export function AndroidSnippet({ flagKey, multivariant }: FeatureFlagSnippet): JSX.Element {
const clientSuffix = 'PostHog.with(this).'
const clientSuffix = 'PostHog.'
const flagFunction = multivariant ? 'getFeatureFlag' : 'isFeatureEnabled'

const variantSuffix = multivariant ? ` == 'example-variant'` : ''
const variantSuffix = multivariant ? ` == "example-variant"` : ''
return (
<CodeSnippet language={Language.Java} wrap>
{`if (${clientSuffix}${flagFunction}('${flagKey}') ${variantSuffix}) {
<CodeSnippet language={Language.Kotlin} wrap>
{`if (${clientSuffix}${flagFunction}("${flagKey}") ${variantSuffix}) {
// do something
}
`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
import { SDKInstallAndroidInstructions } from '../sdk-install-instructions'

function AndroidCaptureSnippet(): JSX.Element {
return <CodeSnippet language={Language.Java}>PostHog.with(this).capture("test-event");</CodeSnippet>
return <CodeSnippet language={Language.Kotlin}>PostHog.capture(event = "test-event")</CodeSnippet>
}

export function ProductAnalyticsAndroidInstructions(): JSX.Element {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { teamLogic } from 'scenes/teamLogic'

function AndroidInstallSnippet(): JSX.Element {
return (
<CodeSnippet language={Language.Java}>
<CodeSnippet language={Language.Kotlin}>
{`dependencies {
implementation 'com.posthog.android:posthog:1.+'
implementation("com.posthog:posthog-android:3.+")
}`}
</CodeSnippet>
)
Expand All @@ -16,24 +16,25 @@ function AndroidSetupSnippet(): JSX.Element {
const { currentTeam } = useValues(teamLogic)

return (
<CodeSnippet language={Language.Java}>
{`public class SampleApp extends Application {
private static final String POSTHOG_API_KEY = "${currentTeam?.api_token}";
private static final String POSTHOG_HOST = "${window.location.origin}";
@Override
public void onCreate() {
// Create a PostHog client with the given context, API key and host
PostHog posthog = new PostHog.Builder(this, POSTHOG_API_KEY, POSTHOG_HOST)
.captureApplicationLifecycleEvents() // Record certain application events automatically!
.recordScreenViews() // Record screen views automatically!
.build();
// Set the initialized instance as a globally accessible instance
PostHog.setSingletonInstance(posthog);
// Now any time you call PostHog.with, the custom instance will be returned
PostHog posthog = PostHog.with(this);
<CodeSnippet language={Language.Kotlin}>
{`class SampleApp : Application() {
companion object {
const val POSTHOG_API_KEY = "${currentTeam?.api_token}"
const val POSTHOG_HOST = "${window.location.origin}"
}
override fun onCreate() {
super.onCreate()
// Create a PostHog Config with the given API key and host
val config = PostHogAndroidConfig(
apiKey = POSTHOG_API_KEY,
host = POSTHOG_HOST
)
// Setup PostHog with the given Context and Config
PostHogAndroid.setup(this, config)
}`}
</CodeSnippet>
)
Expand Down

0 comments on commit 6d6725a

Please sign in to comment.