Skip to content

Commit 1760fbf

Browse files
neilkakkarTwixes
andauthored
Revamp starter kit to be barebones (#7)
* update docs, remove most files * cherrypick @Twixes changes * Update code TODO * exporttt * Reword README a bit * Fix typo Co-authored-by: Michael Matloka <[email protected]>
1 parent d4c9628 commit 1760fbf

File tree

7 files changed

+37
-3580
lines changed

7 files changed

+37
-3580
lines changed

.gitignore

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,16 @@ logs
44
npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
7-
8-
# Runtime data
9-
pids
10-
*.pid
11-
*.seed
12-
*.pid.lock
13-
14-
# Directory for instrumented libs generated by jscoverage/JSCover
15-
lib-cov
16-
17-
# Coverage directory used by tools like istanbul
18-
coverage
19-
20-
# nyc test coverage
21-
.nyc_output
22-
23-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
24-
.grunt
25-
26-
# Bower dependency directory (https://bower.io/)
27-
bower_components
28-
29-
# node-waf configuration
30-
.lock-wscript
31-
32-
# Compiled binary addons (https://nodejs.org/api/addons.html)
33-
build/
34-
35-
# Dependency directories
367
node_modules/
37-
jspm_packages/
38-
39-
# Typescript v1 declaration files
40-
typings/
41-
42-
# Optional npm cache directory
438
.npm
449

45-
# Optional eslint cache
46-
.eslintcache
47-
48-
# Optional REPL history
49-
.node_repl_history
50-
51-
# Output of 'npm pack'
52-
*.tgz
53-
54-
# Yarn Integrity file
55-
.yarn-integrity
56-
57-
# environment variables file
58-
.env
59-
.environment
60-
61-
# next.js build output
62-
.next
63-
64-
# editors
10+
# Editors
6511
.vscode
6612
.idea
6713

68-
# yalc
14+
# Yalc
6915
.yalc
7016
yalc*
7117

7218
# macOS
73-
.DS_Store
74-
75-
# output
76-
dist/
19+
.DS_Store

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
# PostHog Plugin Starter Kit: Hello World
1+
# PostHog Plugin Starter Kit
22

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

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

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

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

12-
Need more information on developing plugins? Check out [the Plugins Overview](https://posthog.com/docs/plugins/build/overview)
16+
1. [Hello World](https://github.com/PostHog/helloworldplugin) – basic event processing, with tests
17+
1. [S3 Export](https://github.com/PostHog/s3-export-plugin) – event export using the AWS SDK, with TypeScript
18+
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
19+
1. [PagerDuty](https://github.com/PostHog/posthog-pagerduty-plugin) – periodic job using external HTTP API access
20+
21+
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).
22+
For a crash course, read [the Plugins tutorial in PostHog Docs](https://posthog.com/docs/plugins/build/tutorial).
1323

1424
## Installation
1525

1626
1. Open PostHog.
17-
1. Head to the Plugins page from the sidebar.
18-
1. Install from URL using this repository's URL.
27+
1. Go to the Plugins page from the sidebar.
28+
1. Head to the Advanced tab.
29+
1. "Install from GitHub, GitLab or npm" using this repository's URL.
1930

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

2333
### [Join our Slack community.](https://join.slack.com/t/posthogusers/shared_invite/enQtOTY0MzU5NjAwMDY3LTc2MWQ0OTZlNjhkODk3ZDI3NDVjMDE1YjgxY2I4ZjI4MzJhZmVmNjJkN2NmMGJmMzc2N2U3Yjc3ZjI5NGFlZDQ)

index.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1+
// <TODO: your plugin code here - you can base it on the code below, but you don't have to>
2+
13
// Some internal library function
24
async function getRandomNumber() {
3-
return 4 // remove this line to get an actual random number from random.org – caution, rate limited to 10 events/s!
4-
const response = await fetch(
5-
'https://www.random.org/integers/?num=1&min=1&max=1000000000&col=1&base=10&format=plain&rnd=new'
6-
)
7-
return parseInt(await response.text())
5+
return 4
86
}
97

10-
async function setupPlugin({ config }) {
11-
console.log(`Setting up the plugin:\n${config.greeting}`)
8+
// Plugin method that runs on plugin load
9+
export async function setupPlugin({ config }) {
10+
console.log(`Setting up the plugin`)
1211
}
1312

14-
async function processEvent(event, { config, cache }) {
13+
// Plugin method that processes event
14+
export async function processEvent(event, { config, cache }) {
1515
const counterValue = (await cache.get('greeting_counter', 0))
1616
cache.set('greeting_counter', counterValue + 1)
1717
if (!event.properties) event.properties = {}
1818
event.properties['greeting'] = config.greeting
1919
event.properties['greeting_counter'] = counterValue
2020
event.properties['random_number'] = await getRandomNumber()
2121
return event
22-
}
23-
24-
// The famed Hello World plugin itself
25-
module.exports = {
26-
setupPlugin,
27-
processEvent
28-
}
22+
}

index.test.js

Lines changed: 0 additions & 60 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

plugin.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
2-
"name": "Hello World",
3-
"url": "<Your Plugin URL here>",
4-
"description": "<Your Plugin description here>",
2+
"name": "<TODO: your plugin name>",
3+
"url": "<TODO: Your Plugin URL here>",
4+
"description": "<TODO: Your Plugin description here>",
55
"main": "index.js",
66
"posthogVersion": ">= 1.25.0",
77
"config": [
8+
{
9+
"markdown": "<TODO: your plugin config, remove if none>"
10+
},
811
{
912
"key": "greeting",
1013
"name": "What greeting would you like to use?",

0 commit comments

Comments
 (0)