argus-discord-analytics 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -21,6 +21,7 @@
21
21
  * argus.trackRevenue({ source: 'patreon', amount: 500, tier: 'Premium' });
22
22
  * ```
23
23
  */
24
+ declare const SDK_VERSION = "0.2.1";
24
25
  interface ArgusConfig {
25
26
  /** Your Argus API key (starts with arg_live_ or arg_test_) */
26
27
  apiKey: string;
@@ -93,7 +94,7 @@ declare class Argus {
93
94
  private startFlushTimer;
94
95
  /**
95
96
  * Track a Discord.js interaction automatically
96
- * Extracts command name, server ID, and user ID from the interaction
97
+ * Extracts command name (including subcommands), server ID, and user ID from the interaction
97
98
  */
98
99
  track(interaction: {
99
100
  commandName?: string;
@@ -103,6 +104,7 @@ declare class Argus {
103
104
  id: string;
104
105
  };
105
106
  type?: number;
107
+ options?: unknown;
106
108
  }): void;
107
109
  /**
108
110
  * Track a custom event
@@ -114,16 +116,30 @@ declare class Argus {
114
116
  }): void;
115
117
  /**
116
118
  * Track a command (convenience method)
119
+ * Accepts either a command name string or a Discord.js interaction object
117
120
  *
118
121
  * @example
119
122
  * ```typescript
123
+ * // Option 1: Pass the interaction directly (recommended)
124
+ * // Automatically extracts subcommands: /show profile -> "show profile"
125
+ * argus.trackCommand(interaction);
126
+ *
127
+ * // Option 2: Pass command name as string
120
128
  * argus.trackCommand('ban', {
121
129
  * serverId: interaction.guildId,
122
130
  * userId: interaction.user.id
123
131
  * });
124
132
  * ```
125
133
  */
126
- trackCommand(commandName: string, options?: {
134
+ trackCommand(commandOrInteraction: string | {
135
+ commandName?: string;
136
+ customId?: string;
137
+ guildId?: string | null;
138
+ user?: {
139
+ id: string;
140
+ };
141
+ options?: unknown;
142
+ }, options?: {
127
143
  serverId?: string;
128
144
  userId?: string;
129
145
  metadata?: Record<string, unknown>;
@@ -240,6 +256,7 @@ declare class Argus {
240
256
  startTimer(id: string): string;
241
257
  /**
242
258
  * End timing and track the command with latency
259
+ * Automatically extracts subcommands from the interaction
243
260
  */
244
261
  endTimer(timerId: string, interaction: {
245
262
  commandName?: string;
@@ -249,6 +266,7 @@ declare class Argus {
249
266
  id: string;
250
267
  };
251
268
  type?: number;
269
+ options?: unknown;
252
270
  }): void;
253
271
  /**
254
272
  * Track an event with latency measurement
@@ -264,4 +282,4 @@ declare class Argus {
264
282
  shutdown(): Promise<void>;
265
283
  }
266
284
 
267
- export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, type ServerEvent, type TrackEvent, Argus as default };
285
+ export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, SDK_VERSION, type ServerEvent, type TrackEvent, Argus as default };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@
21
21
  * argus.trackRevenue({ source: 'patreon', amount: 500, tier: 'Premium' });
22
22
  * ```
23
23
  */
24
+ declare const SDK_VERSION = "0.2.1";
24
25
  interface ArgusConfig {
25
26
  /** Your Argus API key (starts with arg_live_ or arg_test_) */
26
27
  apiKey: string;
@@ -93,7 +94,7 @@ declare class Argus {
93
94
  private startFlushTimer;
94
95
  /**
95
96
  * Track a Discord.js interaction automatically
96
- * Extracts command name, server ID, and user ID from the interaction
97
+ * Extracts command name (including subcommands), server ID, and user ID from the interaction
97
98
  */
98
99
  track(interaction: {
99
100
  commandName?: string;
@@ -103,6 +104,7 @@ declare class Argus {
103
104
  id: string;
104
105
  };
105
106
  type?: number;
107
+ options?: unknown;
106
108
  }): void;
107
109
  /**
108
110
  * Track a custom event
@@ -114,16 +116,30 @@ declare class Argus {
114
116
  }): void;
115
117
  /**
116
118
  * Track a command (convenience method)
119
+ * Accepts either a command name string or a Discord.js interaction object
117
120
  *
118
121
  * @example
119
122
  * ```typescript
123
+ * // Option 1: Pass the interaction directly (recommended)
124
+ * // Automatically extracts subcommands: /show profile -> "show profile"
125
+ * argus.trackCommand(interaction);
126
+ *
127
+ * // Option 2: Pass command name as string
120
128
  * argus.trackCommand('ban', {
121
129
  * serverId: interaction.guildId,
122
130
  * userId: interaction.user.id
123
131
  * });
124
132
  * ```
125
133
  */
126
- trackCommand(commandName: string, options?: {
134
+ trackCommand(commandOrInteraction: string | {
135
+ commandName?: string;
136
+ customId?: string;
137
+ guildId?: string | null;
138
+ user?: {
139
+ id: string;
140
+ };
141
+ options?: unknown;
142
+ }, options?: {
127
143
  serverId?: string;
128
144
  userId?: string;
129
145
  metadata?: Record<string, unknown>;
@@ -240,6 +256,7 @@ declare class Argus {
240
256
  startTimer(id: string): string;
241
257
  /**
242
258
  * End timing and track the command with latency
259
+ * Automatically extracts subcommands from the interaction
243
260
  */
244
261
  endTimer(timerId: string, interaction: {
245
262
  commandName?: string;
@@ -249,6 +266,7 @@ declare class Argus {
249
266
  id: string;
250
267
  };
251
268
  type?: number;
269
+ options?: unknown;
252
270
  }): void;
253
271
  /**
254
272
  * Track an event with latency measurement
@@ -264,4 +282,4 @@ declare class Argus {
264
282
  shutdown(): Promise<void>;
265
283
  }
266
284
 
267
- export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, type ServerEvent, type TrackEvent, Argus as default };
285
+ export { Argus, type ArgusConfig, type HeartbeatConfig, type RevenueEvent, SDK_VERSION, type ServerEvent, type TrackEvent, Argus as default };
package/dist/index.js CHANGED
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  Argus: () => Argus,
24
+ SDK_VERSION: () => SDK_VERSION,
24
25
  default: () => index_default
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
28
+ var SDK_VERSION = "0.2.1";
27
29
  function hashString(str) {
28
30
  let hash = 0;
29
31
  for (let i = 0; i < str.length; i++) {
@@ -33,6 +35,25 @@ function hashString(str) {
33
35
  }
34
36
  return Math.abs(hash).toString(36);
35
37
  }
38
+ function extractFullCommandName(interaction) {
39
+ let command = interaction.commandName || interaction.customId || "unknown";
40
+ const options = interaction.options;
41
+ if (options && typeof options.getSubcommandGroup === "function") {
42
+ try {
43
+ const group = options.getSubcommandGroup(false);
44
+ if (group) command += ` ${group}`;
45
+ } catch {
46
+ }
47
+ }
48
+ if (options && typeof options.getSubcommand === "function") {
49
+ try {
50
+ const sub = options.getSubcommand(false);
51
+ if (sub) command += ` ${sub}`;
52
+ } catch {
53
+ }
54
+ }
55
+ return command;
56
+ }
36
57
  var Argus = class {
37
58
  constructor(apiKeyOrConfig) {
38
59
  this.queue = [];
@@ -73,10 +94,10 @@ var Argus = class {
73
94
  }
74
95
  /**
75
96
  * Track a Discord.js interaction automatically
76
- * Extracts command name, server ID, and user ID from the interaction
97
+ * Extracts command name (including subcommands), server ID, and user ID from the interaction
77
98
  */
78
99
  track(interaction) {
79
- const name = interaction.commandName || interaction.customId || "unknown";
100
+ const name = extractFullCommandName(interaction);
80
101
  const serverId = interaction.guildId || void 0;
81
102
  const userId = interaction.user?.id;
82
103
  this.trackEvent("command", name, {
@@ -111,17 +132,36 @@ var Argus = class {
111
132
  }
112
133
  /**
113
134
  * Track a command (convenience method)
135
+ * Accepts either a command name string or a Discord.js interaction object
114
136
  *
115
137
  * @example
116
138
  * ```typescript
139
+ * // Option 1: Pass the interaction directly (recommended)
140
+ * // Automatically extracts subcommands: /show profile -> "show profile"
141
+ * argus.trackCommand(interaction);
142
+ *
143
+ * // Option 2: Pass command name as string
117
144
  * argus.trackCommand('ban', {
118
145
  * serverId: interaction.guildId,
119
146
  * userId: interaction.user.id
120
147
  * });
121
148
  * ```
122
149
  */
123
- trackCommand(commandName, options) {
124
- this.trackEvent("command", commandName, options);
150
+ trackCommand(commandOrInteraction, options) {
151
+ let commandName;
152
+ let extractedOptions = options;
153
+ if (typeof commandOrInteraction === "string") {
154
+ commandName = commandOrInteraction;
155
+ } else {
156
+ commandName = extractFullCommandName(commandOrInteraction);
157
+ if (!extractedOptions) {
158
+ extractedOptions = {
159
+ serverId: commandOrInteraction.guildId || void 0,
160
+ userId: commandOrInteraction.user?.id
161
+ };
162
+ }
163
+ }
164
+ this.trackEvent("command", commandName, extractedOptions);
125
165
  }
126
166
  /**
127
167
  * Track an error
@@ -233,7 +273,7 @@ var Argus = class {
233
273
  "Content-Type": "application/json",
234
274
  "Authorization": `Bearer ${this.apiKey}`
235
275
  },
236
- body: JSON.stringify({ events })
276
+ body: JSON.stringify({ events, sdkVersion: SDK_VERSION })
237
277
  });
238
278
  if (!response.ok) {
239
279
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
@@ -391,6 +431,7 @@ var Argus = class {
391
431
  }
392
432
  /**
393
433
  * End timing and track the command with latency
434
+ * Automatically extracts subcommands from the interaction
394
435
  */
395
436
  endTimer(timerId, interaction) {
396
437
  const startTime = this.commandStartTimes.get(timerId);
@@ -401,7 +442,7 @@ var Argus = class {
401
442
  }
402
443
  const latencyMs = Date.now() - startTime;
403
444
  this.commandStartTimes.delete(timerId);
404
- const name = interaction.commandName || interaction.customId || "unknown";
445
+ const name = extractFullCommandName(interaction);
405
446
  const serverId = interaction.guildId || void 0;
406
447
  const userId = interaction.user?.id;
407
448
  this.trackEventWithLatency("command", name, latencyMs, {
@@ -454,5 +495,6 @@ var Argus = class {
454
495
  var index_default = Argus;
455
496
  // Annotate the CommonJS export names for ESM import in node:
456
497
  0 && (module.exports = {
457
- Argus
498
+ Argus,
499
+ SDK_VERSION
458
500
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ var SDK_VERSION = "0.2.1";
2
3
  function hashString(str) {
3
4
  let hash = 0;
4
5
  for (let i = 0; i < str.length; i++) {
@@ -8,6 +9,25 @@ function hashString(str) {
8
9
  }
9
10
  return Math.abs(hash).toString(36);
10
11
  }
12
+ function extractFullCommandName(interaction) {
13
+ let command = interaction.commandName || interaction.customId || "unknown";
14
+ const options = interaction.options;
15
+ if (options && typeof options.getSubcommandGroup === "function") {
16
+ try {
17
+ const group = options.getSubcommandGroup(false);
18
+ if (group) command += ` ${group}`;
19
+ } catch {
20
+ }
21
+ }
22
+ if (options && typeof options.getSubcommand === "function") {
23
+ try {
24
+ const sub = options.getSubcommand(false);
25
+ if (sub) command += ` ${sub}`;
26
+ } catch {
27
+ }
28
+ }
29
+ return command;
30
+ }
11
31
  var Argus = class {
12
32
  constructor(apiKeyOrConfig) {
13
33
  this.queue = [];
@@ -48,10 +68,10 @@ var Argus = class {
48
68
  }
49
69
  /**
50
70
  * Track a Discord.js interaction automatically
51
- * Extracts command name, server ID, and user ID from the interaction
71
+ * Extracts command name (including subcommands), server ID, and user ID from the interaction
52
72
  */
53
73
  track(interaction) {
54
- const name = interaction.commandName || interaction.customId || "unknown";
74
+ const name = extractFullCommandName(interaction);
55
75
  const serverId = interaction.guildId || void 0;
56
76
  const userId = interaction.user?.id;
57
77
  this.trackEvent("command", name, {
@@ -86,17 +106,36 @@ var Argus = class {
86
106
  }
87
107
  /**
88
108
  * Track a command (convenience method)
109
+ * Accepts either a command name string or a Discord.js interaction object
89
110
  *
90
111
  * @example
91
112
  * ```typescript
113
+ * // Option 1: Pass the interaction directly (recommended)
114
+ * // Automatically extracts subcommands: /show profile -> "show profile"
115
+ * argus.trackCommand(interaction);
116
+ *
117
+ * // Option 2: Pass command name as string
92
118
  * argus.trackCommand('ban', {
93
119
  * serverId: interaction.guildId,
94
120
  * userId: interaction.user.id
95
121
  * });
96
122
  * ```
97
123
  */
98
- trackCommand(commandName, options) {
99
- this.trackEvent("command", commandName, options);
124
+ trackCommand(commandOrInteraction, options) {
125
+ let commandName;
126
+ let extractedOptions = options;
127
+ if (typeof commandOrInteraction === "string") {
128
+ commandName = commandOrInteraction;
129
+ } else {
130
+ commandName = extractFullCommandName(commandOrInteraction);
131
+ if (!extractedOptions) {
132
+ extractedOptions = {
133
+ serverId: commandOrInteraction.guildId || void 0,
134
+ userId: commandOrInteraction.user?.id
135
+ };
136
+ }
137
+ }
138
+ this.trackEvent("command", commandName, extractedOptions);
100
139
  }
101
140
  /**
102
141
  * Track an error
@@ -208,7 +247,7 @@ var Argus = class {
208
247
  "Content-Type": "application/json",
209
248
  "Authorization": `Bearer ${this.apiKey}`
210
249
  },
211
- body: JSON.stringify({ events })
250
+ body: JSON.stringify({ events, sdkVersion: SDK_VERSION })
212
251
  });
213
252
  if (!response.ok) {
214
253
  throw new Error(`HTTP ${response.status}: ${response.statusText}`);
@@ -366,6 +405,7 @@ var Argus = class {
366
405
  }
367
406
  /**
368
407
  * End timing and track the command with latency
408
+ * Automatically extracts subcommands from the interaction
369
409
  */
370
410
  endTimer(timerId, interaction) {
371
411
  const startTime = this.commandStartTimes.get(timerId);
@@ -376,7 +416,7 @@ var Argus = class {
376
416
  }
377
417
  const latencyMs = Date.now() - startTime;
378
418
  this.commandStartTimes.delete(timerId);
379
- const name = interaction.commandName || interaction.customId || "unknown";
419
+ const name = extractFullCommandName(interaction);
380
420
  const serverId = interaction.guildId || void 0;
381
421
  const userId = interaction.user?.id;
382
422
  this.trackEventWithLatency("command", name, latencyMs, {
@@ -429,5 +469,6 @@ var Argus = class {
429
469
  var index_default = Argus;
430
470
  export {
431
471
  Argus,
472
+ SDK_VERSION,
432
473
  index_default as default
433
474
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argus-discord-analytics",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "The all-seeing analytics SDK for Discord bots - track commands, errors, servers, and more",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",