Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New doc links + copy for Plugins in Source Editor #4755

Merged
merged 3 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions frontend/src/scenes/plugins/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ export function Plugins({ user }: { user: UserType }): JSX.Element | null {
}
caption={
<>
Plugins enable you to extend PostHog's core data processing functionality. You can also{' '}
<a href="https://posthog.com/docs/plugins/build">build your own.</a>
Plugins enable you to extend PostHog's core data processing functionality.
<br />
Make use of verified plugins from the{' '}
<a href="https://posthog.com/plugins" target="_blank">
Plugin Library
</a>{' '}
– or{' '}
<a href="https://posthog.com/docs/plugins/build" target="_blank">
build your own
</a>
.
</>
}
/>
Expand Down
57 changes: 35 additions & 22 deletions frontend/src/scenes/plugins/edit/PluginSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,42 @@ import SCAFFOLD_errors from '!raw-loader!@posthog/plugin-scaffold/dist/errors.d.
// @ts-ignore
import SCAFFOLD_types from '!raw-loader!@posthog/plugin-scaffold/dist/types.d.ts'

const defaultSource = `// Learn more about plugins at: https://posthog.com/docs/plugins/overview
import { Plugin } from '@posthog/plugin-scaffold'
const defaultSource = `// Learn more about plugins at: https://posthog.com/docs/plugins/build/overview

type MyPluginType = Plugin<{
config: {
username: string
},
global: {},
}>
// Processes each event, optionally transforming it
export function processEvent(event, { config }) {
// Some events (such as $identify) don't have properties
if (event.properties) {
event.properties['hello'] = \`Hello \${config.name}\`
}
// Return the event to be ingested, or return null to discard
return event
}

const MyPlugin: MyPluginType = {
setupPlugin: async (meta) => {

},
onEvent: async (event, meta) => {
console.log(\`Event \${event.event} has been processed!\`)
},
// Runs when the plugin is loaded, allows for preparing it as needed
export function setupPlugin (meta) {
console.log(\`The date is \${new Date().toDateString()}\`)
}

export default MyPlugin
`
// Runs every hour on the hour
async function runEveryHour(meta) {
const response = await fetch('https://palabras-aleatorias-public-api.herokuapp.com/random')
const data = await response.json()
const randomSpanishWord = data.body.Word
console.log(\`¡\${randomSpanishWord.toUpperCase()}!\`)
}`

const defaultConfig = [
{
markdown: 'Specify your config here',
},
{
key: 'username',
key: 'name',
name: 'Person to greet',
type: 'string',
hint: 'Used to personalise the property `hello`',
default: '',
default: 'world',
required: false,
order: 2,
},
]

Expand Down Expand Up @@ -101,9 +103,20 @@ export function PluginSource(): JSX.Element {
{editingSource ? (
<>
<p>
<a href="https://posthog.com/docs/plugins/build" target="_blank">
Read the documentation.
Read our{' '}
<a href="https://posthog.com/docs/plugins/build/overview" target="_blank">
plugin building overview in PostHog Docs
</a>{' '}
for a good grasp of possibilities.
<br />
Once satisfied with your plugin, feel free to{' '}
<a
href="https://posthog.com/docs/plugins/build/tutorial#submitting-your-plugin"
target="_blank"
>
submit it to the official Plugin Library
</a>
.
</p>
<Form.Item label="Name" name="name" required rules={[requiredRule]}>
<Input />
Expand Down