-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add posthog-node to api * Tiny fix on textarea size for AI modal * Add enableAnalytics to the DB * Add posthog client * Add posthog analytics * Remove useless log * Add ability to toggle analytics enabled in settings * Add README language * Add privacy policy * Add NODE_ENV production back to script. Refactor posthog client. Fix copy in settings and README * Update implementation, rename DB column, fix build
- Loading branch information
Showing
21 changed files
with
358 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Privacy Policy | ||
|
||
## Introduction | ||
|
||
Srcbook is committed to protecting your privacy. This policy explains what data we collect, how we collect it, how we use it, and how you can opt-out. | ||
|
||
## Data We Collect | ||
|
||
We collect behavioral data to understand usage patterns and improve our application. This data includes: | ||
|
||
- Usage metrics (e.g., feature interactions, usage frequency) | ||
- Performance metrics (e.g., load times, error rates) | ||
|
||
## What We Do Not Collect | ||
|
||
We do not collect any personal information or personally identifiable information (PII). | ||
|
||
## How We Use the Data | ||
|
||
The data collected is used to: | ||
|
||
- Improve the functionality and performance of Srcbook | ||
- Identify and address issues | ||
- Understand user preferences and usage patterns | ||
|
||
## Opt-Out Option | ||
|
||
We respect your privacy and provide an option to opt-out of data collection. You can disable data collection at any time by going to the settings within the Srcbook application and toggling the data collection option off. | ||
|
||
## Data Storage and Security | ||
|
||
All collected data is stored securely and is only accessible by the development team. | ||
|
||
## Changes to This Policy | ||
|
||
We may update this policy from time to time. Any changes will be reflected in this document. | ||
|
||
## Contact Us | ||
|
||
If you have any questions about this policy, please contact us at [email protected]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE `config` ADD `enabled_analytics` integer DEFAULT true NOT NULL;--> statement-breakpoint | ||
ALTER TABLE `config` ADD `srcbook_installation_id` text DEFAULT '18n70ookj0p2ht8c3aqfu2qjgo' NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"version": "6", | ||
"dialect": "sqlite", | ||
"id": "59446000-b2a1-442d-8cd1-560a6a8fa7bf", | ||
"prevId": "fee9ddc3-ef67-45f3-a415-34fbb0b7779e", | ||
"tables": { | ||
"config": { | ||
"name": "config", | ||
"columns": { | ||
"base_dir": { | ||
"name": "base_dir", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"default_language": { | ||
"name": "default_language", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "'typescript'" | ||
}, | ||
"openai_api_key": { | ||
"name": "openai_api_key", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"enabled_analytics": { | ||
"name": "enabled_analytics", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": true | ||
}, | ||
"srcbook_installation_id": { | ||
"name": "srcbook_installation_id", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "'18n70ookj0p2ht8c3aqfu2qjgo'" | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"secrets": { | ||
"name": "secrets", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "integer", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"value": { | ||
"name": "value", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": { | ||
"secrets_name_unique": { | ||
"name": "secrets_name_unique", | ||
"columns": [ | ||
"name" | ||
], | ||
"isUnique": true | ||
} | ||
}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
} | ||
}, | ||
"enums": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
}, | ||
"internal": { | ||
"indexes": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import app from './server/http.mjs'; | ||
import wss from './server/ws.mjs'; | ||
import { SRCBOOKS_DIR } from './constants.mjs'; | ||
import { posthog } from './posthog-client.mjs'; | ||
|
||
export { app, wss, SRCBOOKS_DIR }; | ||
export { app, wss, SRCBOOKS_DIR, posthog }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { PostHog } from 'posthog-node'; | ||
import { getConfig } from './config.mjs'; | ||
import { IS_PRODUCTION } from './constants.mjs'; | ||
|
||
type QueuedEvent = { | ||
event: string; | ||
properties?: Record<string, any>; | ||
}; | ||
|
||
class PostHogClient { | ||
private installId: string; | ||
private client: PostHog | null = null; | ||
private isEnabled: boolean = false; | ||
private eventQueue: QueuedEvent[] = []; | ||
|
||
constructor(config: { enabledAnalytics: boolean; installId: string }) { | ||
this.isEnabled = config.enabledAnalytics; | ||
this.installId = config.installId; | ||
|
||
if (this.isEnabled) { | ||
this.client = new PostHog( | ||
// We're sending over API key to GitHub and clients, but it's the only way. | ||
'phc_bQjmPYXmbl76j8gW289Qj9XILuu1STRnIfgCSKlxdgu', | ||
{ host: 'https://us.i.posthog.com' }, | ||
); | ||
} | ||
|
||
this.flushQueue(); | ||
} | ||
|
||
private flushQueue(): void { | ||
if (!this.isEnabled || !this.client) { | ||
this.eventQueue = []; // Clear the queue if analytics are disabled | ||
return; | ||
} | ||
|
||
while (this.eventQueue.length > 0) { | ||
const event = this.eventQueue.shift(); | ||
if (event) { | ||
this.client.capture({ ...event, distinctId: this.installId }); | ||
} | ||
} | ||
} | ||
|
||
public capture(event: QueuedEvent): void { | ||
if (this.isEnabled && IS_PRODUCTION) { | ||
if (this.client) { | ||
this.client.capture({ ...event, distinctId: this.installId }); | ||
} | ||
} else { | ||
this.eventQueue.push(event); | ||
} | ||
} | ||
|
||
public async shutdown(): Promise<void> { | ||
this.flushQueue(); | ||
if (this.client) { | ||
await this.client.shutdown(); | ||
} | ||
} | ||
} | ||
|
||
const config = await getConfig(); | ||
export const posthog = new PostHogClient(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.