@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 +165 -123
- package/bin/cli.js +16 -2
- package/bin/help.js +64 -0
- package/package.json +2 -1
- package/src/analyze/helpers.js +4 -3
package/README.md
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
1
|
# @flisk/analyze-tracking
|
|
2
2
|
|
|
3
|
-
|
|
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
|
[](https://www.npmjs.com/package/@flisk/analyze-tracking)
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
##
|
|
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
|
-
|
|
26
|
+
### Key Options:
|
|
14
27
|
- `-o, --output <output_file>`: Name of the output file (default: `tracking-schema.yaml`)
|
|
15
|
-
- `-c, --customFunction <function_name>`:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
```js
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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: '
|
|
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.
|
|
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"
|
package/src/analyze/helpers.js
CHANGED
|
@@ -139,8 +139,9 @@ function extractJsProperties(node) {
|
|
|
139
139
|
function extractTsProperties(checker, node) {
|
|
140
140
|
const properties = {};
|
|
141
141
|
|
|
142
|
-
node.properties
|
|
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
|
}
|