Skip to content

fliskdata/analyze-tracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@flisk/analyze-tracking

Automatically document your analytics setup by analyzing tracking code and generating data schemas from tools like Segment, Amplitude, Mixpanel, and more πŸš€

NPM version Tests

Why Use @flisk/analyze-tracking?

πŸ“Š 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!

πŸ” Auto-Document Events – Generates a complete YAML schema that captures all events and properties, including where they're implemented in your codebase.

πŸ•΅οΈβ€β™‚οΈ Track Changes Over Time – Easily spot unintended changes or ensure your analytics setup remains consistent across updates.

πŸ“š Populate Data Catalogs – Automatically generate structured documentation that can help feed into your data catalog, making it easier for everyone to understand your events.

Quick Start

Run without installation! Just use:

npx @flisk/analyze-tracking /path/to/project [options]

Key Options:

  • -g, --generateDescription: Generate descriptions of fields (default: false)
  • -p, --provider <provider>: Specify a provider (options: openai, gemini)
  • -m, --model <model>: Specify a model (ex: gpt-4.1-nano, gpt-4o-mini, gemini-2.0-flash-lite-001)
  • -o, --output <output_file>: Name of the output file (default: tracking-schema.yaml)
  • -c, --customFunction <function_name>: Specify a custom tracking function

πŸ”‘Β  Important: If you are using generateDescription, you must set the appropriate credentials for the LLM provider you are using as an environment variable. OpenAI uses OPENAI_API_KEY and Google Vertex AI uses GOOGLE_APPLICATION_CREDENTIALS.

Note on Custom Functions πŸ’‘

Use this if you have your own in-house tracker or a wrapper function that calls other tracking libraries.

We currently only support functions that follow the following format:

JavaScript/TypeScript/Python/Ruby:

yourCustomTrackFunctionName('<event_name>', {
  <event_parameters>
});

Go:

yourCustomTrackFunctionName("<event_name>", map[string]any{}{
  "<property_name>": "<property_value>",
})

What's Generated?

A clear YAML schema that shows where your events are tracked, their properties, and more. Here's an example:

version: 1
source:
  repository: <repository_url>
  commit: <commit_sha>
  timestamp: <commit_timestamp>
events:
  <event_name>:
    description: <ai_generated_description>
    implementations:
      - description: <ai_generated_description>
        path: <path_to_file>
        line: <line_number>
        function: <function_name>
        destination: <platform_name>
    properties:
      <property_name>:
        description: <ai_generated_description>
        type: <property_type>

Use this to understand where your events live in the code and how they're being tracked.

Your LLM of choice is used for generating descriptions of events, properties, and implementations.

See schema.json for a JSON Schema of the output.

Supported tracking libraries & languages

Library JavaScript/TypeScript Python Ruby Go
Google Analytics βœ… ❌ ❌ ❌
Segment βœ… βœ… βœ… βœ…
Mixpanel βœ… βœ… βœ… βœ…
Amplitude βœ… βœ… ❌ βœ…
Rudderstack βœ… βœ… ✳️ ✳️
mParticle βœ… ❌ ❌ ❌
PostHog βœ… βœ… βœ… βœ…
Pendo βœ… ❌ ❌ ❌
Heap βœ… ❌ ❌ ❌
Snowplow βœ… βœ… βœ… βœ…
Custom Function βœ… βœ… βœ… βœ…

✳️ Rudderstack's SDKs often use the same format as Segment, so Rudderstack events may be detected as Segment events.

SDKs for supported libraries

Google Analytics

JavaScript/TypeScript

gtag('event', '<event_name>', {
  '<property_name>': '<property_value>'
});
Segment

JavaScript/TypeScript

analytics.track('<event_name>', {
  '<property_name>': '<property_value>'
});

Python

analytics.track('<event_name>', {
  '<property_name>': '<property_value>'
})

Ruby

Analytics.track(
  event: '<event_name>',
  properties: {
    '<property_name>': '<property_value>'
  }
)

Go

client.Enqueue(analytics.Track{
  UserId: "user-id",
  Event:  "<event_name>",
  Properties: analytics.NewProperties().
    Set("<property_name>", "<property_value>"),
})
Mixpanel

JavaScript/TypeScript

mixpanel.track('<event_name>', {
  '<property_name>': '<property_value>'
});

Python

mixpanel.track('<event_name>', {
  '<property_name>': '<property_value>'
})

Ruby

tracker.track('<distinct_id>', '<event_name>', {
  '<property_name>': '<property_value>'
})

Go

ctx := context.Background()
mp := mixpanel.NewApiClient("YOUR_PROJECT_TOKEN")
mp.Track(ctx, []*mixpanel.Event{
  mp.NewEvent("<event_name>", "", map[string]any{}{
    "<property_name>": "<property_value>",
  }),
})
Amplitude

JavaScript/TypeScript

amplitude.track('<event_name>', {
  <event_parameters>
});

Python

client.track(
  BaseEvent(
    event_type="<event_name>",
    user_id="<user_id>",
    event_properties={
      "<property_name>": "<property_value>",
    },
  )
)

Go

client.Track(amplitude.Event{
  UserID:    "<user_id>",
  EventType: "<event_name>",
  EventProperties: map[string]any{}{
    "<property_name>": "<property_value>",
  },
})
Rudderstack

JavaScript/TypeScript

rudderanalytics.track('<event_name>', {
  <event_parameters>
});

Python

rudder_analytics.track('<event_name>', {
  '<property_name>': '<property_value>'
})

Ruby

analytics.track(
  user_id: '<user_id>',
  event: '<event_name>',
  properties: {
    '<property_name>': '<property_value>'
  }
)

Go

client.Enqueue(analytics.Track{
  UserId: "<user_id>",
  Event:  "<event_name>",
  Properties: analytics.NewProperties().
    Set("<property_name>", "<property_value>"),
})
mParticle

JavaScript/TypeScript

mParticle.logEvent('<event_name>', mParticle.EventType.<event_type>, {
  '<property_name>': '<property_value>'
});
PostHog

JavaScript/TypeScript

posthog.capture('<event_name>', {
  '<property_name>': '<property_value>'
});

Python

posthog.capture('distinct_id', '<event_name>', {
  '<property_name>': '<property_value>'
})
# Or
posthog.capture(
  'distinct_id',
  event='<event_name>',
  properties={
    '<property_name>': '<property_value>'
  }
)

Ruby

posthog.capture({
  distinct_id: '<distinct_id>',
  event: '<event_name>',
  properties: {
    '<property_name>': '<property_value>'
  }
})

Go

client.Enqueue(posthog.Capture{
  DistinctId: "<distinct_id>",
  Event:      "<event_name>",
  Properties: posthog.NewProperties().
    Set("<property_name>", "<property_value>"),
})
Pendo

JavaScript/TypeScript

pendo.track('<event_name>', {
  <event_parameters>
});

Python

pendo.track('<event_name>', {
  '<property_name>': '<property_value>'
})
Heap

JavaScript/TypeScript

heap.track('<event_name>', {
  <event_parameters>
});

Python

heap.track('<event_name>', {
  '<property_name>': '<property_value>'
})
Snowplow (Structured Events)

JavaScript/TypeScript

tracker.track(buildStructEvent({
  action: '<event_name>',
  category: '<category>',
  label: '<label>',
  property: '<property>',
  value: <value>
}));

Python

tracker.track(StructuredEvent(
  action="<event_name>",
  category="<category>",
  label="<label>",
  property_="<property>",
  value=<value>,
))

Ruby

tracker.track_struct_event(
  action: '<event_name>',
  category: '<category>',
  label: '<label>',
  property: '<property>',
  value: <value>
)

Go

tracker.TrackStructEvent(sp.StructuredEvent{
  	Action:   sp.NewString("<event_name>"),
  	Category: sp.NewString("<category>"),
  	Label:    sp.NewString("<label>"),
  	Property: sp.NewString("<property>"),
  	Value:    sp.NewFloat64(<value>),
  })

Contribute

We're actively improving this package. Found a bug? Have a feature request? Open an issue or submit a pull request!