-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Custom events & optimizations #159
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
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
f9c5d54
feat: Add new error codes and implement AnalyticsBase class for track…
ValDesign22 e5b3cd2
feat: Enhance documentation for events and trackGuilds methods in Ana…
ValDesign22 e26a091
feat: Refactor AnalyticsBase and DiscordAnalytics classes for improve…
ValDesign22 b578178
feat: Add documentation for trackInteractions method in DiscordAnalyt…
ValDesign22 9a294fe
feat: Add updateOrInsert method and refactor interaction tracking in …
ValDesign22 05da160
fix: Correct locale type handling in calculateGuildMembersRepartition…
ValDesign22 b434099
feat: Add calculateGuildMembers method and refactor guild members han…
ValDesign22 c7dc161
refactor: Simplify initialization and tracking methods in DiscordAnal…
ValDesign22 2708d5c
fix: Update documentation links in README for consistency
ValDesign22 0eb6793
feat: Initialize analytics before tracking events in usage examples
ValDesign22 d4af7e5
chore: Bump version to 3.5.0 in package.json
ValDesign22 381a4ae
refactor: Update import statements and improve debug logging in Disco…
ValDesign22 34022c8
feat: Add client_id property and improve error handling in AnalyticsB…
ValDesign22 84366d5
feat: Add ensure method call in CustomEvent constructor for validation
ValDesign22 1a8b1e8
feat: Enhance user type tracking in trackInteractions method (eris)
ValDesign22 f05acc3
refactor: Remove redundant ensure method calls in CustomEvent class
ValDesign22 29a978a
feat: add Discord Analytics packages for various libraries (discord.j…
ValDesign22 2362984
refactor: Refactor code structure for improved readability and mainta…
ValDesign22 dd035ba
chore: Update GitHub Actions workflow to use pnpm and latest action v…
ValDesign22 00bfda9
chore: Update Node.js version matrix in GitHub Actions workflow
ValDesign22 388fcee
refactor: Remove commented-out steps from TypeScript test workflow fo…
ValDesign22 041755a
chore: Update GitHub Actions workflow to use latest action versions a…
ValDesign22 a9ad012
refactor: Change API call method from POST to GET for event tracking …
ValDesign22 6b3fac0
feat: Add tests for AnalyticsBase and example implementations for Dis…
ValDesign22 b1e5a1f
refactor: Remove redundant comment from DiscordAnalytics initialization
ValDesign22 1cd73db
feat: Add sharding example using ShardingManager
ValDesign22 f54fe30
feat: Add example for DiscordAnalytics (discordjs-light) with interac…
ValDesign22 32ec1a9
feat(eris): Add example implementation for DiscordAnalytics with inte…
ValDesign22 6d0f58d
feat(oceanic): Implement DiscordAnalytics example with interaction ha…
ValDesign22 4d38ded
fix: Update package installation and import paths for DiscordAnalytic…
ValDesign22 7eb6827
fix: Fixed some typos and bugs
ValDesign22 c00f17a
fix: Fixed a problem in increment function
ValDesign22 1749133
refactor: Removed unecessary condition
ValDesign22 bf83ff9
chore: Remove obsolete test workflow and add new CI workflow with bui…
ValDesign22 c8ac478
fix: Corrected string escaping in error messages and labels
ValDesign22 895c68a
test: Add test for updating event value in AnalyticsBase
ValDesign22 d079fa4
feat: Add coverage configuration to Vitest for package source files
ValDesign22 9da565a
feat: Added README for every package
ValDesign22 f9bdb57
fix: Replace error throwing with console error logging for better err…
ValDesign22 2a998fc
feat!: skip Discord Analytics initialization if NODE_ENV is not "prod…
Nonolanlan1007 ddd4af0
refactor!: --dev argument renamed to --fast to enhance comprehension
Nonolanlan1007 5ff785c
fix: custom events
Nonolanlan1007 273a459
Merge branch 'master' into feat/custom-events
Nonolanlan1007 6821ceb
refactor: removed useless file but required to merge
Nonolanlan1007 a636b53
fix(tests): fixed test error on core package
ValDesign22 5902a0b
chore: fix README file name
Nonolanlan1007 f1fe949
refactor: removed useless import
Nonolanlan1007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,32 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [18.x, 19.x, 20.x, 21.x, 22.x] | ||
| fail-fast: true | ||
|
|
||
| name: Test TypeScript build | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 10 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| cache: 'pnpm' | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| - name: Build the package | ||
| run: pnpm build | ||
| - name: Run tests | ||
| run: pnpm run coverage |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| node_modules | ||
| dist | ||
| coverage | ||
| .idea | ||
|
|
||
| # Files | ||
|
|
||
This file contains hidden or 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,6 +1,9 @@ | ||
| node_modules | ||
| src | ||
| dist/test | ||
| test | ||
| examples | ||
| coverage | ||
| tsconfig.json | ||
| *.ts | ||
| .idea | ||
| .github | ||
| test | ||
| .github |
This file contains hidden or 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,110 +1,22 @@ | ||
| # Discord Analytics | ||
|
|
||
| ## Installing the package | ||
| ## Overview | ||
| Discord Analytics is a powerful tool that allows you to track and analyze your Discord bot's performance and user engagement. This repository contains packages for different Discord libraries, including Discord.js, Eris, Oceanic.js, and Discord.js-light. | ||
| These packages provide a simple and efficient way to integrate Discord Analytics into your bot, enabling you to gather valuable insights and improve your bot's functionality. | ||
|
|
||
| ## Installing the packages | ||
| > **Note:** Use the package manager of your choice (npm, yarn, pnpm) to install the packages. | ||
|
|
||
| ```bash | ||
| npm install discord-analytics | ||
| npm install @discordanalytics/core # Core package | ||
| npm install @discordanalytics/discordjs # For Discord.js | ||
| npm install @discordanalytics/discordjs-light # For Discord.js-light | ||
| npm install @discordanalytics/eris # For Eris | ||
| npm install @discordanalytics/oceanic # For Oceanic.js | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| > **Note:** To use Discord Analytics, you need to have an API token. Check the docs for more informations : https://docs.discordanalytics.xyz/get-started/bot-registration | ||
|
|
||
| **With Discord.js:** | ||
|
|
||
| ```js | ||
| // Import Discord.js's client and intents | ||
| const { Client, IntentsBitField } = require("discord.js") | ||
| // import discord-analytics | ||
| const { default: DiscordAnalytics } = require("discord-analytics/discordjs") | ||
|
|
||
| // Create Discord client | ||
| const client = new Client({ | ||
| intents: [IntentsBitField.Flags.Guilds] // This intent is required | ||
| }); | ||
|
|
||
| // Create Discord Analytics instance | ||
| // Don't forget to replace YOUR_API_TOKEN by your Discord Analytics token ! | ||
| const analytics = new DiscordAnalytics({ | ||
| client: client, | ||
| apiToken: 'YOUR_API_TOKEN', | ||
| sharded: false // Set it to true if your bot use shards | ||
| }); | ||
|
|
||
| // start tracking selected events | ||
| analytics.trackEvents(); | ||
|
|
||
| // When Discord client is ready | ||
| client.on('ready', () => { | ||
| console.log("Bot is ready!"); | ||
| }); | ||
|
|
||
| // Login to Discord | ||
| // Don't forget to replace token by your Discord bot token ! | ||
| client.login('token'); | ||
| ``` | ||
|
|
||
| **With Eris:** | ||
|
|
||
| ```js | ||
| const {Client} = require("eris"); | ||
| const {default: DiscordAnalytics} = require("discord-analytics/eris"); | ||
|
|
||
| // Create Eris client. | ||
| // Don't forget to replace token by your Discord bot token ! | ||
| const bot = new Client("token"); | ||
|
|
||
| bot.on("ready", () => { | ||
| // Create Discord Analytics instance | ||
| // Don't forget to replace YOUR_API_TOKEN by your Discord Analytics token ! | ||
| const analytics = new DiscordAnalytics({ | ||
| client: client, | ||
| apiToken: 'YOUR_API_TOKEN' | ||
| }); | ||
|
|
||
| // start tracking selected events | ||
| analytics.trackEvents(); | ||
|
|
||
| console.log("Ready!"); | ||
| }); | ||
|
|
||
| // Login to Discord | ||
| bot.connect(); | ||
| ``` | ||
|
|
||
| **With Oceanic.js:** | ||
| ```js | ||
| // Import Discord.js's client and intents | ||
| const { Client } = require("oceanic.js") | ||
| // import discord-analytics | ||
| const { default: DiscordAnalytics } = require("discord-analytics/oceanic") | ||
|
|
||
| // Create Discord client | ||
| const client = new Client({ | ||
| auth: "Bot <YOUR_BOT_TOKEN>", | ||
| gateway: { | ||
| intents: ["GUILDS"] // This intent is required | ||
| } | ||
| }) | ||
|
|
||
| // Create Discord Analytics instance | ||
| // Don't forget to replace YOUR_API_TOKEN by your Discord Analytics token ! | ||
| const analytics = new DiscordAnalytics({ | ||
| client: client, | ||
| apiToken: 'YOUR_API_TOKEN' | ||
| }); | ||
|
|
||
| // start tracking selected events | ||
| analytics.trackEvents(); | ||
|
|
||
| // When Discord client is ready | ||
| client.on('ready', () => { | ||
| console.log("Bot is ready!"); | ||
| }); | ||
|
|
||
| // Login to Discord | ||
| // Don't forget to replace token by your Discord bot token ! | ||
| client.login('token'); | ||
| ``` | ||
| [Discord.js](./packages/discordjs/README.md) | [Discord.js-light](./packages/discordjs-light/README.md) | [Eris](./packages/eris/README.md) | [Oceanic.js](./packages/oceanic/README.md) | ||
|
|
||
| > For advanced usages and updated docs, please check https://docs.discordanalytics.xyz/get-started/installation | ||
| > For advanced usages and updated docs, please check https://discordanalytics.xyz/docs/main/get-started/advanced-usage |
This file contains hidden or 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,55 +1,30 @@ | ||
| { | ||
| "name": "discord-analytics", | ||
| "version": "2.5.0", | ||
| "description": "A discord bot analytics to send your bot data", | ||
| "main": "dist/index.js", | ||
| "version": "0.0.0", | ||
| "author": "Discord Analytics", | ||
| "homepage": "https://discordanalytics.xyz", | ||
| "license": "MIT", | ||
| "private": true, | ||
| "workspaces": [ | ||
| "packages/*" | ||
| ], | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "init": "tsc --init", | ||
| "test:djs": "nodemon src/test/discordjs/index.ts --dev", | ||
| "test:eris": "nodemon src/test/eris/index.ts --dev", | ||
| "test:oceanic": "nodemon src/test/oceanic/index.ts --dev", | ||
| "build": "tsc" | ||
| "build": "pnpm -r run build", | ||
| "test": "vitest", | ||
| "coverage": "vitest run --coverage" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/DiscordAnalytics/node-package.git" | ||
| }, | ||
| "keywords": [ | ||
| "Javascript", | ||
| "Discord", | ||
| "Discord.js", | ||
| "Discord.js-Light", | ||
| "Eris", | ||
| "API", | ||
| "Analytics", | ||
| "Oceanic" | ||
| ], | ||
| "author": "Discord Analytics", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/DiscordAnalytics/node-package/issues" | ||
| }, | ||
| "homepage": "https://discordanalytics.xyz", | ||
| "devDependencies": { | ||
| "@types/node": "^20.17.11", | ||
| "@types/node-fetch": "^2.6.12", | ||
| "discord.js": "^14.17.2", | ||
| "discord.js-light": "^4.10.0", | ||
| "dotenv": "^16.4.7", | ||
| "eris": "^0.17.2", | ||
| "nodemon": "^3.1.9", | ||
| "oceanic.js": "^1.11.2", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5.7.2" | ||
| }, | ||
| "dependencies": { | ||
| "node-fetch": "^2.7.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "discord.js": "14.x", | ||
| "discord.js-light": "4.10.0", | ||
| "eris": ">=0.17.2", | ||
| "oceanic.js": ">= 1.11.0 < 1.12.0" | ||
| "@types/node": "^22.15.2", | ||
| "@vitest/coverage-v8": "3.1.2", | ||
| "dotenv": "^16.5.0", | ||
| "typescript": "^5.8.3", | ||
| "vitest": "^3.1.2" | ||
| } | ||
| } | ||
This file contains hidden or 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,24 @@ | ||
| # Discord Analytics | ||
Nonolanlan1007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Overview | ||
| This package is a wrapper for the Discord Analytics API. It allows you to track events and send them to the Discord Analytics API. | ||
|
|
||
| ## Installation | ||
| You can install the package using npm: | ||
|
|
||
| ```bash | ||
| npm install @discordanalytics/core | ||
| # or | ||
| yarn add @discordanalytics/core | ||
| # or | ||
| pnpm add @discordanalytics/core | ||
| ``` | ||
|
|
||
| ### Usage | ||
| Discord Analytics core package is used by other packages like `@discordanalytics/discordjs`, `@discordanalytics/discordjs-light`, `@discordanalytics/eris`, and `@discordanalytics/oceanic`. You don't need to use this package directly unless you want to use the core features without any wrapper. | ||
|
|
||
| ## API | ||
| ### `AnalyticsBase` | ||
| The main class of the package. It is used to track events and send them to the Discord Analytics API. | ||
| ### `CustomEvent` | ||
| A class that represents a custom event. It is used to track custom events and send them to the Discord Analytics API. | ||
This file contains hidden or 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,27 @@ | ||
| { | ||
| "name": "@discordanalytics/core", | ||
| "version": "3.5.0", | ||
ValDesign22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "description": "Core package to work with Discord Analytics", | ||
| "main": "dist/index.js", | ||
| "author": "Discord Analytics", | ||
| "homepage": "https://discordanalytics.xyz", | ||
| "readme": "README.md", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/DiscordAnalytics/node-package.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/DiscordAnalytics/node-package/issues" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc" | ||
| }, | ||
| "dependencies": { | ||
| "node-fetch": "^2.7.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "*", | ||
| "@types/node-fetch": "2.6.12", | ||
| "typescript": "*" | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.