@flisk/analyze-tracking 0.2.6 β†’ 0.2.8

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/README.md CHANGED
@@ -1,32 +1,49 @@
1
1
  # @flisk/analyze-tracking
2
2
 
3
- Analyzes tracking code in a project and generates data schemas
3
+ Automatically document your analytics setup by analyzing tracking code and generating data schemas from tools like Segment, Amplitude, Mixpanel, and more πŸš€.
4
4
 
5
5
  [![NPM version](https://img.shields.io/npm/v/@flisk/analyze-tracking.svg)](https://www.npmjs.com/package/@flisk/analyze-tracking)
6
6
 
7
7
 
8
- ## Usage
8
+ ## Why Use @flisk/analyze-tracking?
9
+ πŸ“Š **Understand Your Tracking** – Effortlessly analyze your codebase for `track` calls so you can see all your analytics events, properties, and triggers in one place. No more guessing what’s being tracked!
10
+
11
+ πŸ” **Auto-Document Events** – Generates a complete YAML schema that captures all events and properties, including where they’re implemented in your codebase.
12
+
13
+ πŸ•΅οΈβ€β™‚οΈ **Track Changes Over Time** – Easily spot unintended changes or ensure your analytics setup remains consistent across updates.
14
+
15
+ πŸ“š **Populate Data Catalogs** – Automatically generate structured documentation that can help feed into your data catalog, making it easier for everyone to understand your events.
16
+
17
+
18
+ ## Quick Start
19
+
20
+ Run without installation! Just use:
21
+
9
22
  ```sh
10
23
  npx @flisk/analyze-tracking /path/to/project [options]
11
24
  ```
12
25
 
13
- Optional arguments:
26
+ ### Key Options:
14
27
  - `-o, --output <output_file>`: Name of the output file (default: `tracking-schema.yaml`)
15
- - `-c, --customFunction <function_name>`: Name of your custom tracking function
16
- - `-u, --repositoryUrl <git_url>`: URL to your repository
17
- - `-h, --commitHash <commit_sha>`: Latest commit hash
18
- - `-t, --commitTimestamp <iso_timestamp>`: Timestamp of latest commit
19
-
20
- Note: Custom Functions only support the following format:
21
- ```js
22
- yourCustomTrackFunctionName('<event_name>', {
23
- <event_parameters>
24
- });
25
- ```
28
+ - `-c, --customFunction <function_name>`: Specify a custom tracking function
29
+
30
+ <details>
31
+ <summary>Note on Custom Functions πŸ’‘</summary>
26
32
 
33
+ Use this if you have your own in-house tracker or a wrapper function that calls other tracking libraries.
27
34
 
28
- ## Output Schema
29
- A YAML file with the following structure is generated:
35
+ We currently only support functions that follow the following format:
36
+ ```js
37
+ yourCustomTrackFunctionName('<event_name>', {
38
+ <event_parameters>
39
+ });
40
+ ```
41
+ </details>
42
+
43
+
44
+ ## What’s Generated?
45
+ A clear YAML schema that shows where your events are tracked, their properties, and more.
46
+ Here’s an example:
30
47
 
31
48
  ```yaml
32
49
  version: 1
@@ -44,116 +61,141 @@ events:
44
61
  properties:
45
62
  <property_name>:
46
63
  type: <property_type>
47
- required: <property_required>
48
- description: <property_description>
49
64
  ```
50
65
 
51
- See [schema.json](schema.json) for the output schema.
66
+ Use this to understand where your events live in the code and how they’re being tracked.
52
67
 
68
+ See [schema.json](schema.json) for a JSON Schema of the output.
53
69
 
54
- ## Supported tracking libraries
55
-
56
- #### Google Analytics
57
- ```js
58
- gtag('event', '<event_name>', {
59
- <event_parameters>
60
- });
61
- ```
62
-
63
-
64
- #### Segment
65
- ```js
66
- analytics.track('<event_name>', {
67
- <event_parameters>
68
- });
69
- ```
70
-
71
-
72
- #### Mixpanel
73
- ```js
74
- mixpanel.track('<event_name>', {
75
- <event_parameters>
76
- });
77
- ```
78
-
79
-
80
- #### Amplitude
81
- ```js
82
- amplitude.logEvent('<event_name>', {
83
- <event_parameters>
84
- });
85
- ```
86
70
 
71
+ ## Supported tracking libraries
87
72
 
88
- #### Rudderstack
89
- ```js
90
- rudderanalytics.track('<event_name>', {
91
- <event_parameters>
92
- });
93
- ```
94
-
95
-
96
- #### mParticle
97
- ```js
98
- mParticle.logEvent('<event_name>', {
99
- <event_parameters>
100
- });
101
- ```
102
-
103
-
104
- #### PostHog
105
- ```js
106
- posthog.capture('<event_name>', {
107
- <event_parameters>
108
- });
109
- ```
110
-
111
-
112
- #### Pendo
113
- ```js
114
- pendo.track('<event_name>', {
115
- <event_parameters>
116
- });
117
- ```
118
-
119
-
120
- #### Heap
121
- ```js
122
- heap.track('<event_name>', {
123
- <event_parameters>
124
- });
125
- ```
126
-
127
-
128
- #### Snowplow
129
- ```js
130
- snowplow('trackStructEvent', {
131
- category: '<category>',
132
- action: '<action>',
133
- label: '<label>',
134
- property: '<property>',
135
- value: '<value> '
136
- });
137
- ```
138
-
139
- ```js
140
- trackStructEvent({
141
- category: '<category>',
142
- action: '<action>',
143
- label: '<label>',
144
- property: '<property>',
145
- value: '<value>'
146
- });
147
- ```
148
-
149
- ```js
150
- buildStructEvent({
151
- category: '<category>',
152
- action: '<action>',
153
- label: '<label>',
154
- property: '<property>',
155
- value: '<value>'
156
- });
157
- ```
158
-
159
- _Note: Snowplow Self Describing Events are not supported yet._
73
+ <details>
74
+ <summary>Google Analytics</summary>
75
+
76
+ ```js
77
+ gtag('event', '<event_name>', {
78
+ <event_parameters>
79
+ });
80
+ ```
81
+ </details>
82
+
83
+ <details>
84
+ <summary>Segment</summary>
85
+
86
+ ```js
87
+ analytics.track('<event_name>', {
88
+ <event_parameters>
89
+ });
90
+ ```
91
+ </details>
92
+
93
+ <details>
94
+ <summary>Mixpanel</summary>
95
+
96
+ ```js
97
+ mixpanel.track('<event_name>', {
98
+ <event_parameters>
99
+ });
100
+ ```
101
+ </details>
102
+
103
+ <details>
104
+ <summary>Amplitude</summary>
105
+
106
+ ```js
107
+ amplitude.logEvent('<event_name>', {
108
+ <event_parameters>
109
+ });
110
+ ```
111
+ </details>
112
+
113
+ <details>
114
+ <summary>Rudderstack</summary>
115
+
116
+ ```js
117
+ rudderanalytics.track('<event_name>', {
118
+ <event_parameters>
119
+ });
120
+ ```
121
+ </details>
122
+
123
+ <details>
124
+ <summary>mParticle</summary>
125
+
126
+ ```js
127
+ mParticle.logEvent('<event_name>', {
128
+ <event_parameters>
129
+ });
130
+ ```
131
+ </details>
132
+
133
+ <details>
134
+ <summary>PostHog</summary>
135
+
136
+ ```js
137
+ posthog.capture('<event_name>', {
138
+ <event_parameters>
139
+ });
140
+ ```
141
+ </details>
142
+
143
+ <details>
144
+ <summary>Pendo</summary>
145
+
146
+ ```js
147
+ pendo.track('<event_name>', {
148
+ <event_parameters>
149
+ });
150
+ ```
151
+ </details>
152
+
153
+ <details>
154
+ <summary>Heap</summary>
155
+
156
+ ```js
157
+ heap.track('<event_name>', {
158
+ <event_parameters>
159
+ });
160
+ ```
161
+ </details>
162
+
163
+ <details>
164
+ <summary>Snowplow (struct events)</summary>
165
+
166
+ ```js
167
+ snowplow('trackStructEvent', {
168
+ category: '<category>',
169
+ action: '<action>',
170
+ label: '<label>',
171
+ property: '<property>',
172
+ value: '<value> '
173
+ });
174
+ ```
175
+
176
+ ```js
177
+ trackStructEvent({
178
+ category: '<category>',
179
+ action: '<action>',
180
+ label: '<label>',
181
+ property: '<property>',
182
+ value: '<value>'
183
+ });
184
+ ```
185
+
186
+ ```js
187
+ buildStructEvent({
188
+ category: '<category>',
189
+ action: '<action>',
190
+ label: '<label>',
191
+ property: '<property>',
192
+ value: '<value>'
193
+ });
194
+ ```
195
+
196
+ _Note: Snowplow Self Describing Events are coming soon!_
197
+ </details>
198
+
199
+
200
+ ## Contribute
201
+ We’re actively improving this package. Found a bug? Want to request a feature? Open an issue or contribute directly!
package/bin/cli.js CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require('path');
4
- const commandLineArgs = require('command-line-args')
4
+ const commandLineArgs = require('command-line-args');
5
+ const commandLineUsage = require('command-line-usage');
5
6
  const { run } = require('../src/index');
7
+ const { helpContent } = require('./help');
6
8
 
7
9
  // Parse command-line arguments
8
10
  const optionDefinitions = [
@@ -29,7 +31,7 @@ const optionDefinitions = [
29
31
  },
30
32
  {
31
33
  name: 'commitHash',
32
- alias: 'h',
34
+ alias: 's',
33
35
  type: String,
34
36
  },
35
37
  {
@@ -37,6 +39,11 @@ const optionDefinitions = [
37
39
  alias: 't',
38
40
  type: String,
39
41
  },
42
+ {
43
+ name: 'help',
44
+ alias: 'h',
45
+ type: Boolean,
46
+ },
40
47
  ]
41
48
  const options = commandLineArgs(optionDefinitions);
42
49
  const {
@@ -46,8 +53,14 @@ const {
46
53
  repositoryUrl,
47
54
  commitHash,
48
55
  commitTimestamp,
56
+ help,
49
57
  } = options;
50
58
 
59
+ if (help) {
60
+ console.log(commandLineUsage(helpContent));
61
+ process.exit(0);
62
+ }
63
+
51
64
  const customSourceDetails = {
52
65
  repositoryUrl,
53
66
  commitHash,
@@ -56,6 +69,7 @@ const customSourceDetails = {
56
69
 
57
70
  if (!targetDir) {
58
71
  console.error('Please provide the path to the repository.');
72
+ console.log(commandLineUsage(helpContent));
59
73
  process.exit(1);
60
74
  }
61
75
 
package/bin/help.js ADDED
@@ -0,0 +1,64 @@
1
+ const header =
2
+ `
3
+ \u001b[38;5;2m β–’β–’ \u001b[39m
4
+ \u001b[38;5;2m β–’β–’β–’β–’ \u001b[39m
5
+ \u001b[38;5;2m β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
6
+ \u001b[38;5;2m β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
7
+ \u001b[38;5;2m β–’β–’β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
8
+ \u001b[38;5;2m β–’β–’β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
9
+ \u001b[38;5;2m β–’β–’β–’β–’β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
10
+ \u001b[38;5;2m β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
11
+ \u001b[38;5;2m β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
12
+ \u001b[38;5;2m β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
13
+ \u001b[38;5;2m β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
14
+ \u001b[38;5;2m β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
15
+ \u001b[38;5;2m β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
16
+ \u001b[38;5;2m β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
17
+ \u001b[38;5;2m β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
18
+ \u001b[38;5;2m β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“ \u001b[39m β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
19
+ \u001b[38;5;2m β–“β–“β–“β–“β–“β–“β–“β–“ \u001b[39m
20
+ \u001b[38;5;2m β–“β–“β–“β–“β–“β–“ \u001b[39m
21
+ `;
22
+
23
+ const helpContent = [
24
+ {
25
+ content: header,
26
+ raw: true
27
+ },
28
+ {
29
+ header: '@flisk/analyze-tracking',
30
+ content: 'Automatically document your analytics setup by analyzing tracking code and generating data schemas from tools like Segment, Amplitude, Mixpanel, and more πŸš€'
31
+ },
32
+ {
33
+ header: 'Options',
34
+ optionList: [
35
+ {
36
+ name: 'help',
37
+ alias: 'h',
38
+ description: 'Display this usage guide.',
39
+ type: Boolean
40
+ },
41
+ {
42
+ name: 'output',
43
+ alias: 'o',
44
+ description: 'Name of the output file.',
45
+ type: String,
46
+ defaultOption: true,
47
+ typeLabel: '{underline tracking-schema.yaml}'
48
+ },
49
+ {
50
+ name: 'customFunction',
51
+ alias: 'c',
52
+ description: 'Specify a custom tracking function.',
53
+ type: String,
54
+ typeLabel: '{underline yourCustomFunctionName}'
55
+ }
56
+ ]
57
+ },
58
+ {
59
+ header: 'Project Home',
60
+ content: '{underline https://github.com/fliskdata/analyze-tracking}'
61
+ }
62
+ ];
63
+
64
+ module.exports = { helpContent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flisk/analyze-tracking",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Analyzes tracking code in a project and generates data schemas",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -26,6 +26,7 @@
26
26
  "acorn-jsx-walk": "^2.0.0",
27
27
  "acorn-walk": "^8.3.3",
28
28
  "command-line-args": "^6.0.0",
29
+ "command-line-usage": "^7.0.3",
29
30
  "isomorphic-git": "^1.27.1",
30
31
  "js-yaml": "^4.1.0",
31
32
  "typescript": "^5.5.4"
@@ -139,8 +139,9 @@ function extractJsProperties(node) {
139
139
  function extractTsProperties(checker, node) {
140
140
  const properties = {};
141
141
 
142
- node.properties.forEach((prop) => {
143
- const key = prop.name ? prop.name.text : prop.key.text || prop.key.value;
142
+ for (const prop of node.properties) {
143
+ const key = !!prop.name ? prop.name.text : (!!prop.key ? (prop.key.text || prop.key.value) : undefined);
144
+ if (!key) continue;
144
145
  let valueType = 'any';
145
146
 
146
147
  if (ts.isShorthandPropertyAssignment(prop)) {
@@ -195,7 +196,7 @@ function extractTsProperties(checker, node) {
195
196
  valueType = checker.typeToString(checker.getTypeFromTypeNode(prop.type)) || 'any';
196
197
  properties[key] = { type: valueType };
197
198
  }
198
- });
199
+ }
199
200
 
200
201
  return properties;
201
202
  }