A repository demonstrating the power of GitHub Workflows for automated Segment Tracking Plan management.
git clone https://github.com/YOUR_USERNAME/trackings-plans.git
cd trackings-plans
This project requires GitHub repository secrets for authentication with the Segment API.
Secret Name | Description |
---|---|
SEGMENT_PUBLIC_API_TOKEN |
API Token for Segment Public API |
DEV_SEGMENT_TRACKING_PLAN_ID_<TP_NAME> |
Segment Tracking Plan ID for Dev |
PROD_SEGMENT_TRACKING_PLAN_ID_<TP_NAME> |
Segment Tracking Plan ID for Prod |
Hint:
https://app.segment.com/<your_workspace>/protocols/tracking-plans/<tracking_plan_id>
This repository manages two tracking plans:
✅ Webflow
✅ Designer
So, it requires 5 GitHub Secrets:
- 1 API token (
SEGMENT_PUBLIC_API_TOKEN
) - 2 Webflow tracking plan IDs (Dev & Prod)
- 2 Designer tracking plan IDs (Dev & Prod)
- Configure your tracking plans in
config/tracking-plans-config.json
- Create a GitHub release with the title "initialize"
- This triggers the
initialize-tracking-plans
workflow - It pulls tracking plans from Segment, saves them as JSON, generates YAML, and creates the markdown dictionary.
- This triggers the
🔹 Trigger:
- Pushing changes to
tracking-rules/webflow/**.yml
ortracking-rules/designer/**.yml
on a new branch - This triggers the Dev workflow (
Update Development Tracking Plans
)
🔹 What Happens?
- Converts the modified YAML rule(s) to JSON
- Updates the Dev tracking plan using a
PATCH
request - Fetches the updated rules from Segment & saves to
plans/dev/<TP_NAME>/current-rules.json
- Adds, commits, and pushes the changes
🔹 Trigger:
- Merging a branch with tracking rule updates into
main
- This triggers the Prod workflow (
Update Production Tracking Plans and Generate Markdown
)
🔹 What Happens?
- Converts the updated YAML to JSON
- Updates the Prod tracking plan using a
PATCH
request - Fetches updated rules from Segment & saves to
plans/prod/<TP_NAME>/current-rules.json
- Generates a Markdown data dictionary (
docs/<TP_NAME>.md
) - Commits & pushes updates to
main
- Triggered by creating a release named
RESET_DEV
- Fetches rules from Prod
- Replaces all rules in Dev tracking plan with Prod
- Updates
plans/dev/<TP_NAME>/current-rules.json
- Ensures docs stay up to date
- Fetches latest
PROD
rules - Runs
render-tp.js
to regenerate Markdown
This project interacts with Segment's Tracking Plan API for managing tracking plans. Below are the key API endpoints used:
The save-tracking-plans.js
script retrieves the latest rules from the Segment API and saves them to the repository.
🔗 List Rules from Tracking Plan API
Used in: scripts/save-tracking-plans.js
The update-tracking-plan.js
script updates tracking plan rules in Segment using the API.
🔗 Update Rules in Tracking Plan API
Used in: scripts/update-tracking-plan.js
These endpoints ensure that the tracking plans stay in sync between Segment and this repository.
✅ This setup automates the full tracking plan lifecycle from YAML to Segment to Markdown! 🎯