Skip to content

Commit

Permalink
New doc links + copy for Plugins in Source Editor (#4755)
Browse files Browse the repository at this point in the history
* fix merge

* copy update + links

* Proposed updates to #4755 (#4792)

* Reword Plugins header caption a bit

* Update `defaultSource` slightly (functioning `runEveryHour`)

* Update source editor help wording

Co-authored-by: Michael Matloka <[email protected]>
  • Loading branch information
neilkakkar and Twixes authored Jun 18, 2021
1 parent 85c90fa commit 4097b7b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 24 deletions.
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

0 comments on commit 4097b7b

Please sign in to comment.