Add time aggregation to insights tools with total as default - #10
Merged
Merged
Conversation
Implement client-side time aggregation for all insights tools to dramatically reduce token usage. All 7 insights tools now default to returning a single aggregated total value instead of daily data points. Features: - Add aggregation parameter with 7 options: daily, weekly, monthly, quarterly, half-yearly, yearly, total (default) - Implement aggregateMetrics() function in helpers.ts with ISO week calculation and proper date grouping - Update all Google, Facebook, and Apple insights tools with aggregation support - Default to 'total' aggregation for maximum token efficiency - Provide ~99%+ token reduction for typical date ranges Changes: - src/helpers.ts: Add AggregationPeriod type and aggregation logic - src/tools/networks/google.ts: Add aggregation to 2 insights tools - src/tools/networks/facebook.ts: Add aggregation to 3 insights tools - src/tools/networks/apple.ts: Add aggregation to 2 insights tools - README.md: Document time aggregation feature with examples - manifest.js: Support VERSION_POSTFIX for test builds - package.json: Add build:test and pack:test scripts - update-build-version.js: Script to update build package version - tests/server-response-examples/: Add 5 example API response files Users can now get total metrics by default (single value) or request different granularity levels as needed. This ensures optimal token usage while maintaining full flexibility for detailed analysis.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds time aggregation functionality to all insights tools (Google, Facebook, and Apple) to dramatically reduce token usage. By default, all insights are now aggregated to a single total value, providing maximum token efficiency while maintaining flexibility for detailed analysis.
Key Features
Changes
Core Implementation:
src/helpers.ts: AddedAggregationPeriodtype andaggregateMetrics()function with ISO week calculationTools Updated:
src/tools/networks/google.ts: 2 insights tools (location, all locations)src/tools/networks/facebook.ts: 3 insights tools (location, all locations, brandpage)src/tools/networks/apple.ts: 2 insights tools (location, all locations)Documentation & Build:
README.md: Comprehensive documentation with examples and token savings breakdownmanifest.js: Added VERSION_POSTFIX support for test buildspackage.json: Addedbuild:testandpack:testconvenience scriptsupdate-build-version.js: Script to update build package.json versionTesting Assets:
tests/server-response-examples/: Added 5 real API response examples for testingToken Savings
Usage Examples
Default behavior (maximum token reduction):
{ "from": "2024-01-01", "to": "2024-12-31" }Returns: Single aggregated total
Request detailed data when needed:
{ "from": "2024-01-01", "to": "2024-12-31", "aggregation": "monthly" }Returns: 12 monthly data points
Test Plan
Breaking Changes
None - this is fully backwards compatible. Users who don't specify the
aggregationparameter will now get aggregated totals instead of daily data, which provides better token efficiency by default. Users can always requestaggregation: "daily"to get the previous behavior.