@codeleap/analytics 5.8.21 → 6.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/analytics",
3
- "version": "5.8.21",
3
+ "version": "6.1.2",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -9,15 +9,15 @@
9
9
  "directory": "packages/analytics"
10
10
  },
11
11
  "devDependencies": {
12
- "@codeleap/config": "5.8.21",
12
+ "@codeleap/config": "6.1.2",
13
13
  "ts-node-dev": "1.1.8"
14
14
  },
15
15
  "scripts": {
16
16
  "build": "echo 'No build needed'"
17
17
  },
18
18
  "peerDependencies": {
19
- "@codeleap/utils": "5.8.21",
20
- "@codeleap/types": "5.8.21",
19
+ "@codeleap/utils": "6.1.2",
20
+ "@codeleap/types": "6.1.2",
21
21
  "typescript": "5.5.2"
22
22
  }
23
23
  }
package/package.json.bak CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/analytics",
3
- "version": "5.8.21",
3
+ "version": "6.1.2",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -8,7 +8,7 @@ const defaultConfig: SegmentGeneralConfig<any, SegmentUser, DefaultMode> = {
8
8
  prefix: {
9
9
  'dev': 'dev',
10
10
  'prod': null,
11
- }
11
+ },
12
12
  }
13
13
 
14
14
  export class Segment<C extends SegmentMethods, U extends SegmentUser = SegmentUser, M extends string = DefaultMode> {
@@ -31,6 +31,11 @@ export class Segment<C extends SegmentMethods, U extends SegmentUser = SegmentUs
31
31
  return !modePrefix ? '' : `${modePrefix}_`
32
32
  }
33
33
 
34
+ private get eventSuffix() {
35
+ const modeSuffix = this.config.suffix?.[this.config.mode] ?? null
36
+ return !modeSuffix ? '' : `_${modeSuffix}`
37
+ }
38
+
34
39
  constructor(config: SegmentConfig<C, U, M>) {
35
40
  const {
36
41
  apiKey,
@@ -52,22 +57,26 @@ export class Segment<C extends SegmentMethods, U extends SegmentUser = SegmentUs
52
57
  }
53
58
  }
54
59
 
60
+ private buildEventName(name: string): string {
61
+ return `${this.eventPrefix}${name}${this.eventSuffix}`
62
+ }
63
+
55
64
  public async track<T extends AnyRecord>(eventName: string, properties: T | undefined = undefined) {
56
65
  if (!this.enabled) return
57
66
 
58
- await this.client?.track?.(`${this.eventPrefix}${eventName}`, properties)
67
+ await this.client?.track?.(this.buildEventName(eventName), properties)
59
68
  }
60
69
 
61
70
  public async screen(name: string, options: AnyRecord | undefined = undefined) {
62
71
  if (!this.enabled) return
63
72
 
64
- await this.client?.screen?.(`${this.eventPrefix}${name}`, options)
73
+ await this.client?.screen?.(this.buildEventName(name), options)
65
74
  }
66
75
 
67
76
  public async group(groupId: string, groupTraits: AnyRecord | undefined = undefined) {
68
77
  if (!this.enabled) return
69
78
 
70
- await this.client?.group(`${this.eventPrefix}${groupId}`, groupTraits)
79
+ await this.client?.group(this.buildEventName(groupId), groupTraits)
71
80
  }
72
81
 
73
82
  public async alias(newUserId: string) {
@@ -1,5 +1,5 @@
1
1
  export type AnyRecord = {
2
- [x:string]: any
2
+ [x: string]: any
3
3
  }
4
4
 
5
5
  export type SegmentConfig<C, U extends SegmentUser, M extends string = DefaultMode> = {
@@ -8,6 +8,7 @@ export type SegmentConfig<C, U extends SegmentUser, M extends string = DefaultMo
8
8
  getUserTraits: (user: U) => AnyRecord
9
9
  mode: M
10
10
  prefix?: Record<M, string | null>
11
+ suffix?: Record<M, string | null>
11
12
  createClient: (writeKey: string) => C
12
13
  }
13
14