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

Proposed updates to #4755 #4792

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
11 changes: 9 additions & 2 deletions frontend/src/scenes/plugins/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +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 even{' '}
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.
build your own
</a>
.
</>
}
/>
Expand Down
37 changes: 20 additions & 17 deletions frontend/src/scenes/plugins/edit/PluginSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@ 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/build/overview
const defaultSource = `// Learn more about plugins at: https://posthog.com/docs/plugins/build/overview

/* Runs on every event */
// Processes each event, optionally transforming it
export function processEvent(event, { config }) {
// Some events (like $identify) don't have properties
// Some events (such as $identify) don't have properties
if (event.properties) {
event.properties['hello'] = \`Hello \${config.name}\`
}
// Return the event to ingest, return nothing to discard
// Return the event to be ingested, or return null to discard
return event
}

/* Runs once on plugin installation */
// Runs when the plugin is loaded, allows for preparing it as needed
export function setupPlugin (meta) {

console.log(\`The date is \${new Date().toDateString()}\`)
}

/* Runs once every full hour */
// function runEveryHour(meta) {
// const weather = await (await fetch('https://weather.example.api/?city=New+York')).json()
// posthog.capture('weather', { degrees: weather.deg, fahrenheit: weather.us })
// }`
// 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 = [
{
Expand Down Expand Up @@ -102,18 +103,20 @@ export function PluginSource(): JSX.Element {
{editingSource ? (
<>
<p>
Feeling lost?{' '}
Read our{' '}
<a href="https://posthog.com/docs/plugins/build/overview" target="_blank">
Read the documentation.
</a>
plugin building overview in PostHog Docs
</a>{' '}
for a good grasp of possibilities.
<br />
Happy with your plugin?{' '}
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 repository.
submit it to the official Plugin Library
</a>
.
</p>
<Form.Item label="Name" name="name" required rules={[requiredRule]}>
<Input />
Expand Down