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

Revamp starter kit to be barebones #7

Merged
merged 6 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
63 changes: 3 additions & 60 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,16 @@ logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# environment variables file
.env
.environment

# next.js build output
.next

# editors
# Editors
.vscode
.idea

# yalc
# Yalc
.yalc
yalc*

# macOS
.DS_Store

# output
dist/
.DS_Store
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
# PostHog Plugin Starter Kit: Hello World
# PostHog Plugin Starter Kit

[![npm package](https://img.shields.io/npm/v/posthog-plugin-hello-world?style=flat-square)](https://www.npmjs.com/package/posthog-plugin-hello-world)
[![License: MIT](https://img.shields.io/badge/License-MIT-red.svg?style=flat-square)](https://opensource.org/licenses/MIT)

This is an exemplary PostHog plugin. It adds property `"greeting"` to every event, with a configurable value (by default: `"Hello world!"`).
This is a PostHog plugin template.

Feel free to use it as a base for your own plugins!
The existing sample code adds property `"greeting"` to every event with a configurable value (default: `"Hello world!"`).
But that is just to help you get started! To make it your own:
- [ ] Add your own code to `index.js`.
- [ ] Add your own metadat and configuration schema to `plugin.json`.
- [ ] Search for `<TODO:`, make sure none are left!
- [ ] Optional: Add a `logo.png` file to give this plugin its own logo.

You can also add a `logo.png` file to give this plugin its own logo.
If you're looking for inspiration, here are a few exemplary plugins:

Need more information on developing plugins? Check out [the Plugins Overview](https://posthog.com/docs/plugins/build/overview)
1. [Hello World](https://github.com/PostHog/helloworldplugin) – basic event processing, with tests
1. [S3 Export](https://github.com/PostHog/s3-export-plugin) – event export using the AWS SDK, with TypeScript
1. [GeoIP](https://github.com/PostHog/posthog-plugin-geoip) – advanced event processing using the GeoIP feature, with tests, formatting, linting, TypeScript, and GitHub Actions CI
1. [PagerDuty](https://github.com/PostHog/posthog-pagerduty-plugin) – periodic job using external HTTP API access

To get up to speed with the environment of plugins, check out [our Plugins overview in PostHog Docs](https://posthog.com/docs/plugins/build/overview).
For a crash course, read [the Plugins tutorial in PostHog Docs](https://posthog.com/docs/plugins/build/tutorial).

## Installation

1. Open PostHog.
1. Head to the Plugins page from the sidebar.
1. Install from URL using this repository's URL.
1. Go to the Plugins page from the sidebar.
1. Head to the Advanced tab.
1. "Install from GitHub, GitLab or npm" using this repository's URL.

More information in [the Plugins Tutorial](https://posthog.com/docs/plugins/build/tutorial)
## Questions?

### [Join our Slack community.](https://join.slack.com/t/posthogusers/shared_invite/enQtOTY0MzU5NjAwMDY3LTc2MWQ0OTZlNjhkODk3ZDI3NDVjMDE1YjgxY2I4ZjI4MzJhZmVmNjJkN2NmMGJmMzc2N2U3Yjc3ZjI5NGFlZDQ)
Expand Down
24 changes: 9 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
// <TODO: your plugin code here - you can base it on the code below, but you don't have to>

// Some internal library function
async function getRandomNumber() {
return 4 // remove this line to get an actual random number from random.org – caution, rate limited to 10 events/s!
const response = await fetch(
'https://www.random.org/integers/?num=1&min=1&max=1000000000&col=1&base=10&format=plain&rnd=new'
)
return parseInt(await response.text())
return 4
}

async function setupPlugin({ config }) {
console.log(`Setting up the plugin:\n${config.greeting}`)
// Plugin method that runs on plugin load
export async function setupPlugin({ config }) {
console.log(`Setting up the plugin`)
}

async function processEvent(event, { config, cache }) {
// Plugin method that processes event
export async function processEvent(event, { config, cache }) {
const counterValue = (await cache.get('greeting_counter', 0))
cache.set('greeting_counter', counterValue + 1)
if (!event.properties) event.properties = {}
event.properties['greeting'] = config.greeting
event.properties['greeting_counter'] = counterValue
event.properties['random_number'] = await getRandomNumber()
return event
}

// The famed Hello World plugin itself
module.exports = {
setupPlugin,
processEvent
}
}
60 changes: 0 additions & 60 deletions index.test.js

This file was deleted.

28 changes: 0 additions & 28 deletions package.json

This file was deleted.

9 changes: 6 additions & 3 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "Hello World",
"url": "<Your Plugin URL here>",
"description": "<Your Plugin description here>",
"name": "<TODO: your plugin name>",
"url": "<TODO: Your Plugin URL here>",
"description": "<TODO: Your Plugin description here>",
"main": "index.js",
"posthogVersion": ">= 1.25.0",
"config": [
{
"markdown": "<TODO: your plugin config, remove if none>"
},
{
"key": "greeting",
"name": "What greeting would you like to use?",
Expand Down
Loading