Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
640
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/README.md
vendored
Normal file
640
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/README.md
vendored
Normal file
@@ -0,0 +1,640 @@
|
||||
# Ad ROAS (Return on Ad Spend) Tracking Examples
|
||||
|
||||
Comprehensive examples for generating advertising and marketing analytics data using agentic-synth. These examples demonstrate how to create realistic campaign performance data, optimization scenarios, and analytics pipelines for major advertising platforms.
|
||||
|
||||
## Overview
|
||||
|
||||
This directory contains practical examples for:
|
||||
|
||||
- **Campaign Performance Tracking**: Generate realistic ad campaign metrics
|
||||
- **Optimization Simulations**: Test budget allocation and bidding strategies
|
||||
- **Analytics Pipelines**: Build comprehensive marketing analytics systems
|
||||
- **Multi-Platform Integration**: Work with Google Ads, Facebook Ads, TikTok Ads
|
||||
|
||||
## Files
|
||||
|
||||
### 1. campaign-data.ts
|
||||
|
||||
Generates comprehensive ad campaign performance data including:
|
||||
|
||||
- **Platform-Specific Campaigns**
|
||||
- Google Ads (Search, Display, Shopping)
|
||||
- Facebook/Meta Ads (Feed, Stories, Reels)
|
||||
- TikTok Ads (In-Feed, TopView, Branded Effects)
|
||||
|
||||
- **Multi-Channel Attribution**
|
||||
- First-touch, last-touch, linear attribution
|
||||
- Time-decay and position-based models
|
||||
- Data-driven attribution
|
||||
|
||||
- **Customer Journey Tracking**
|
||||
- Touchpoint analysis
|
||||
- Path to conversion
|
||||
- Device and location tracking
|
||||
|
||||
- **A/B Testing Results**
|
||||
- Creative variations
|
||||
- Audience testing
|
||||
- Landing page experiments
|
||||
|
||||
- **Cohort Analysis**
|
||||
- Retention rates
|
||||
- LTV calculations
|
||||
- Payback periods
|
||||
|
||||
### 2. optimization-simulator.ts
|
||||
|
||||
Simulates various optimization scenarios:
|
||||
|
||||
- **Budget Allocation**
|
||||
- Cross-platform budget distribution
|
||||
- ROI-based allocation
|
||||
- Risk-adjusted scenarios
|
||||
|
||||
- **Bid Strategy Testing**
|
||||
- Manual CPC vs automated bidding
|
||||
- Target CPA/ROAS strategies
|
||||
- Maximize conversions/value
|
||||
|
||||
- **Audience Segmentation**
|
||||
- Demographic targeting
|
||||
- Interest-based audiences
|
||||
- Lookalike/similar audiences
|
||||
- Custom and remarketing lists
|
||||
|
||||
- **Creative Optimization**
|
||||
- Ad format testing
|
||||
- Copy variations
|
||||
- Visual element testing
|
||||
|
||||
- **Advanced Optimizations**
|
||||
- Dayparting analysis
|
||||
- Geo-targeting optimization
|
||||
- Multi-variate testing
|
||||
|
||||
### 3. analytics-pipeline.ts
|
||||
|
||||
Marketing analytics and modeling examples:
|
||||
|
||||
- **Attribution Modeling**
|
||||
- Compare attribution models
|
||||
- Channel valuation
|
||||
- Cross-channel interactions
|
||||
|
||||
- **LTV (Lifetime Value) Analysis**
|
||||
- Cohort-based LTV
|
||||
- Predictive LTV models
|
||||
- LTV:CAC ratios
|
||||
|
||||
- **Funnel Analysis**
|
||||
- Conversion funnel stages
|
||||
- Dropout analysis
|
||||
- Bottleneck identification
|
||||
|
||||
- **Predictive Analytics**
|
||||
- Revenue forecasting
|
||||
- Scenario planning
|
||||
- Risk assessment
|
||||
|
||||
- **Marketing Mix Modeling (MMM)**
|
||||
- Channel contribution analysis
|
||||
- Saturation curves
|
||||
- Optimal budget allocation
|
||||
|
||||
- **Incrementality Testing**
|
||||
- Geo holdout tests
|
||||
- PSA (Public Service Announcement) tests
|
||||
- True lift measurement
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Basic Usage
|
||||
|
||||
```typescript
|
||||
import { createSynth } from 'agentic-synth';
|
||||
|
||||
// Initialize with your API key
|
||||
const synth = createSynth({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
|
||||
// Generate Google Ads campaign data
|
||||
const campaigns = await synth.generateStructured({
|
||||
count: 100,
|
||||
schema: {
|
||||
campaignId: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true }
|
||||
},
|
||||
constraints: {
|
||||
impressions: { min: 1000, max: 100000 },
|
||||
roas: { min: 0.5, max: 8.0 }
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Time-Series Campaign Data
|
||||
|
||||
```typescript
|
||||
// Generate daily campaign metrics for 90 days
|
||||
const timeSeries = await synth.generateTimeSeries({
|
||||
count: 90,
|
||||
interval: '1d',
|
||||
metrics: ['impressions', 'clicks', 'conversions', 'spend', 'revenue', 'roas'],
|
||||
trend: 'up',
|
||||
seasonality: true,
|
||||
constraints: {
|
||||
roas: { min: 1.0, max: 10.0 }
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Multi-Platform Batch Generation
|
||||
|
||||
```typescript
|
||||
// Generate data for multiple platforms in parallel
|
||||
const platforms = [
|
||||
{ count: 50, constraints: { platform: 'Google Ads' } },
|
||||
{ count: 50, constraints: { platform: 'Facebook Ads' } },
|
||||
{ count: 50, constraints: { platform: 'TikTok Ads' } }
|
||||
];
|
||||
|
||||
const results = await synth.generateBatch('structured', platforms, 3);
|
||||
```
|
||||
|
||||
## Real-World Use Cases
|
||||
|
||||
### 1. Performance Dashboard Testing
|
||||
|
||||
Generate realistic data for testing marketing dashboards:
|
||||
|
||||
```typescript
|
||||
import { generateTimeSeriesCampaignData } from './campaign-data.js';
|
||||
|
||||
// Generate 6 months of daily metrics
|
||||
const dashboardData = await generateTimeSeriesCampaignData();
|
||||
|
||||
// Use for:
|
||||
// - Frontend dashboard development
|
||||
// - Chart/visualization testing
|
||||
// - Performance optimization
|
||||
// - Demo presentations
|
||||
```
|
||||
|
||||
### 2. Attribution Model Comparison
|
||||
|
||||
Compare different attribution models:
|
||||
|
||||
```typescript
|
||||
import { generateAttributionModels } from './analytics-pipeline.js';
|
||||
|
||||
// Generate attribution data for analysis
|
||||
const attribution = await generateAttributionModels();
|
||||
|
||||
// Compare:
|
||||
// - First-touch vs last-touch
|
||||
// - Linear vs time-decay
|
||||
// - Position-based vs data-driven
|
||||
```
|
||||
|
||||
### 3. Budget Optimization Simulation
|
||||
|
||||
Test budget allocation strategies:
|
||||
|
||||
```typescript
|
||||
import { simulateBudgetAllocation } from './optimization-simulator.js';
|
||||
|
||||
// Generate optimization scenarios
|
||||
const scenarios = await simulateBudgetAllocation();
|
||||
|
||||
// Analyze:
|
||||
// - Risk-adjusted returns
|
||||
// - Diversification benefits
|
||||
// - Scaling opportunities
|
||||
```
|
||||
|
||||
### 4. A/B Test Planning
|
||||
|
||||
Plan and simulate A/B tests:
|
||||
|
||||
```typescript
|
||||
import { generateABTestResults } from './campaign-data.js';
|
||||
|
||||
// Generate A/B test data
|
||||
const tests = await generateABTestResults();
|
||||
|
||||
// Use for:
|
||||
// - Sample size calculations
|
||||
// - Statistical significance testing
|
||||
// - Test design validation
|
||||
```
|
||||
|
||||
### 5. LTV Analysis & Forecasting
|
||||
|
||||
Analyze customer lifetime value:
|
||||
|
||||
```typescript
|
||||
import { generateLTVAnalysis } from './analytics-pipeline.js';
|
||||
|
||||
// Generate cohort LTV data
|
||||
const ltvData = await generateLTVAnalysis();
|
||||
|
||||
// Calculate:
|
||||
// - Payback periods
|
||||
// - LTV:CAC ratios
|
||||
// - Retention curves
|
||||
```
|
||||
|
||||
## Platform-Specific Examples
|
||||
|
||||
### Google Ads
|
||||
|
||||
```typescript
|
||||
// Search campaign with quality score
|
||||
const googleAds = await synth.generateStructured({
|
||||
count: 100,
|
||||
schema: {
|
||||
keyword: { type: 'string' },
|
||||
matchType: { type: 'string' },
|
||||
qualityScore: { type: 'number' },
|
||||
avgPosition: { type: 'number' },
|
||||
impressionShare: { type: 'number' },
|
||||
cpc: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: {
|
||||
matchType: ['exact', 'phrase', 'broad'],
|
||||
qualityScore: { min: 1, max: 10 }
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Facebook/Meta Ads
|
||||
|
||||
```typescript
|
||||
// Facebook campaign with engagement metrics
|
||||
const facebookAds = await synth.generateStructured({
|
||||
count: 100,
|
||||
schema: {
|
||||
objective: { type: 'string' },
|
||||
placement: { type: 'string' },
|
||||
reach: { type: 'number' },
|
||||
frequency: { type: 'number' },
|
||||
engagement: { type: 'number' },
|
||||
relevanceScore: { type: 'number' },
|
||||
cpm: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: {
|
||||
objective: ['conversions', 'traffic', 'engagement'],
|
||||
placement: ['feed', 'stories', 'reels', 'marketplace']
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### TikTok Ads
|
||||
|
||||
```typescript
|
||||
// TikTok campaign with video metrics
|
||||
const tiktokAds = await synth.generateStructured({
|
||||
count: 100,
|
||||
schema: {
|
||||
objective: { type: 'string' },
|
||||
videoViews: { type: 'number' },
|
||||
videoCompletionRate: { type: 'number' },
|
||||
engagement: { type: 'number' },
|
||||
shares: { type: 'number' },
|
||||
follows: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: {
|
||||
objective: ['conversions', 'app_install', 'video_views'],
|
||||
videoCompletionRate: { min: 0.1, max: 0.8 }
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Advanced Features
|
||||
|
||||
### Streaming Real-Time Data
|
||||
|
||||
```typescript
|
||||
// Stream campaign metrics in real-time
|
||||
const synth = createSynth({ streaming: true });
|
||||
|
||||
for await (const metric of synth.generateStream('structured', {
|
||||
count: 100,
|
||||
schema: {
|
||||
timestamp: { type: 'string' },
|
||||
roas: { type: 'number' },
|
||||
alert: { type: 'string' }
|
||||
}
|
||||
})) {
|
||||
console.log('Real-time metric:', metric);
|
||||
|
||||
// Trigger alerts based on ROAS
|
||||
if (metric.roas < 1.0) {
|
||||
console.log('⚠️ ROAS below target!');
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Caching for Performance
|
||||
|
||||
```typescript
|
||||
// Use caching for repeated queries
|
||||
const synth = createSynth({
|
||||
cacheStrategy: 'memory',
|
||||
cacheTTL: 600 // 10 minutes
|
||||
});
|
||||
|
||||
// First call generates data
|
||||
const data1 = await synth.generateStructured({ count: 100, schema });
|
||||
|
||||
// Second call uses cache (much faster)
|
||||
const data2 = await synth.generateStructured({ count: 100, schema });
|
||||
```
|
||||
|
||||
### Custom Constraints
|
||||
|
||||
```typescript
|
||||
// Apply realistic business constraints
|
||||
const campaigns = await synth.generateStructured({
|
||||
count: 50,
|
||||
schema: campaignSchema,
|
||||
constraints: {
|
||||
// Budget constraints
|
||||
spend: { min: 1000, max: 50000 },
|
||||
|
||||
// Performance constraints
|
||||
roas: { min: 2.0, max: 10.0 },
|
||||
cpa: { max: 50.0 },
|
||||
|
||||
// Volume constraints
|
||||
impressions: { min: 10000 },
|
||||
clicks: { min: 100 },
|
||||
conversions: { min: 10 },
|
||||
|
||||
// Platform-specific
|
||||
platform: ['Google Ads', 'Facebook Ads'],
|
||||
status: ['active', 'paused']
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Integration Examples
|
||||
|
||||
### Data Warehouse Pipeline
|
||||
|
||||
```typescript
|
||||
import { generateTimeSeriesCampaignData } from './campaign-data.js';
|
||||
|
||||
async function loadToWarehouse() {
|
||||
const campaigns = await generateTimeSeriesCampaignData();
|
||||
|
||||
// Transform to warehouse schema
|
||||
const rows = campaigns.data.map(campaign => ({
|
||||
date: campaign.timestamp,
|
||||
platform: campaign.platform,
|
||||
metrics: {
|
||||
impressions: campaign.impressions,
|
||||
clicks: campaign.clicks,
|
||||
spend: campaign.spend,
|
||||
revenue: campaign.revenue,
|
||||
roas: campaign.roas
|
||||
}
|
||||
}));
|
||||
|
||||
// Load to BigQuery, Snowflake, Redshift, etc.
|
||||
await warehouse.bulkInsert('campaigns', rows);
|
||||
}
|
||||
```
|
||||
|
||||
### BI Tool Testing
|
||||
|
||||
```typescript
|
||||
import { generateChannelComparison } from './analytics-pipeline.js';
|
||||
|
||||
async function generateBIReport() {
|
||||
const comparison = await generateChannelComparison();
|
||||
|
||||
// Export for Tableau, Looker, Power BI
|
||||
const csv = convertToCSV(comparison.data);
|
||||
await fs.writeFile('channel_performance.csv', csv);
|
||||
}
|
||||
```
|
||||
|
||||
### ML Model Training
|
||||
|
||||
```typescript
|
||||
import { generateLTVAnalysis } from './analytics-pipeline.js';
|
||||
|
||||
async function trainPredictiveModel() {
|
||||
// Generate training data
|
||||
const ltvData = await generateLTVAnalysis();
|
||||
|
||||
// Features for ML model
|
||||
const features = ltvData.data.map(cohort => ({
|
||||
acquisitionChannel: cohort.acquisitionChannel,
|
||||
firstPurchase: cohort.metrics.avgFirstPurchase,
|
||||
frequency: cohort.metrics.purchaseFrequency,
|
||||
retention: cohort.metrics.retentionRate,
|
||||
// Target variable
|
||||
ltv: cohort.ltvCalculations.predictiveLTV
|
||||
}));
|
||||
|
||||
// Train with TensorFlow, scikit-learn, etc.
|
||||
await model.train(features);
|
||||
}
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
### 1. Use Realistic Constraints
|
||||
|
||||
```typescript
|
||||
// ✅ Good: Realistic business constraints
|
||||
const campaigns = await synth.generateStructured({
|
||||
constraints: {
|
||||
roas: { min: 0.5, max: 15.0 }, // Typical range
|
||||
ctr: { min: 0.01, max: 0.15 }, // 1-15%
|
||||
cvr: { min: 0.01, max: 0.20 } // 1-20%
|
||||
}
|
||||
});
|
||||
|
||||
// ❌ Bad: Unrealistic values
|
||||
const bad = await synth.generateStructured({
|
||||
constraints: {
|
||||
roas: { min: 50.0 }, // Too high
|
||||
ctr: { min: 0.5 } // 50% CTR unrealistic
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### 2. Match Platform Characteristics
|
||||
|
||||
```typescript
|
||||
// Different platforms have different metrics
|
||||
const googleAds = {
|
||||
qualityScore: { min: 1, max: 10 },
|
||||
avgPosition: { min: 1.0, max: 5.0 }
|
||||
};
|
||||
|
||||
const facebookAds = {
|
||||
relevanceScore: { min: 1, max: 10 },
|
||||
frequency: { min: 1.0, max: 5.0 }
|
||||
};
|
||||
|
||||
const tiktokAds = {
|
||||
videoCompletionRate: { min: 0.1, max: 0.8 },
|
||||
engagement: { min: 0.02, max: 0.15 }
|
||||
};
|
||||
```
|
||||
|
||||
### 3. Consider Seasonality
|
||||
|
||||
```typescript
|
||||
// Include seasonal patterns for realistic data
|
||||
const seasonal = await synth.generateTimeSeries({
|
||||
count: 365,
|
||||
interval: '1d',
|
||||
seasonality: true, // Includes weekly/monthly patterns
|
||||
trend: 'up', // Long-term growth
|
||||
noise: 0.15 // 15% random variation
|
||||
});
|
||||
```
|
||||
|
||||
### 4. Use Batch Processing
|
||||
|
||||
```typescript
|
||||
// Generate large datasets efficiently
|
||||
const batches = Array.from({ length: 10 }, (_, i) => ({
|
||||
count: 1000,
|
||||
schema: campaignSchema
|
||||
}));
|
||||
|
||||
const results = await synth.generateBatch('structured', batches, 5);
|
||||
// Processes 10,000 records in parallel
|
||||
```
|
||||
|
||||
## Performance Tips
|
||||
|
||||
1. **Enable Caching**: Reuse generated data for similar queries
|
||||
2. **Batch Operations**: Generate multiple datasets in parallel
|
||||
3. **Streaming**: Use for real-time or large datasets
|
||||
4. **Constraints**: Be specific to reduce generation time
|
||||
5. **Schema Design**: Simpler schemas generate faster
|
||||
|
||||
## Testing Scenarios
|
||||
|
||||
### Unit Testing
|
||||
|
||||
```typescript
|
||||
import { generateGoogleAdsCampaign } from './campaign-data.js';
|
||||
|
||||
describe('Campaign Data Generator', () => {
|
||||
it('should generate valid ROAS values', async () => {
|
||||
const result = await generateGoogleAdsCampaign();
|
||||
|
||||
result.data.forEach(campaign => {
|
||||
expect(campaign.roas).toBeGreaterThanOrEqual(0.5);
|
||||
expect(campaign.roas).toBeLessThanOrEqual(8.0);
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Integration Testing
|
||||
|
||||
```typescript
|
||||
import { runAnalyticsExamples } from './analytics-pipeline.js';
|
||||
|
||||
async function testAnalyticsPipeline() {
|
||||
// Generate test data
|
||||
await runAnalyticsExamples();
|
||||
|
||||
// Verify pipeline processes data correctly
|
||||
const processed = await pipeline.run();
|
||||
|
||||
expect(processed.success).toBe(true);
|
||||
}
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### API Key Issues
|
||||
|
||||
```typescript
|
||||
// Ensure API key is set
|
||||
if (!process.env.GEMINI_API_KEY) {
|
||||
throw new Error('GEMINI_API_KEY not found');
|
||||
}
|
||||
|
||||
const synth = createSynth({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
```
|
||||
|
||||
### Rate Limiting
|
||||
|
||||
```typescript
|
||||
// Use retry logic for rate limits
|
||||
const synth = createSynth({
|
||||
maxRetries: 5,
|
||||
timeout: 60000 // 60 seconds
|
||||
});
|
||||
```
|
||||
|
||||
### Memory Management
|
||||
|
||||
```typescript
|
||||
// Use streaming for large datasets
|
||||
const synth = createSynth({ streaming: true });
|
||||
|
||||
for await (const chunk of synth.generateStream('structured', {
|
||||
count: 100000,
|
||||
schema: simpleSchema
|
||||
})) {
|
||||
await processChunk(chunk);
|
||||
// Process in batches to avoid memory issues
|
||||
}
|
||||
```
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- [agentic-synth Documentation](../../README.md)
|
||||
- [API Reference](../../docs/API.md)
|
||||
- [Examples Directory](../)
|
||||
- [Google Ads API](https://developers.google.com/google-ads/api)
|
||||
- [Facebook Marketing API](https://developers.facebook.com/docs/marketing-apis)
|
||||
- [TikTok for Business](https://ads.tiktok.com/marketing_api/docs)
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions welcome! Please see the main repository for guidelines.
|
||||
|
||||
## Support
|
||||
|
||||
For issues or questions:
|
||||
- Open an issue on GitHub
|
||||
- Check existing examples
|
||||
- Review documentation
|
||||
|
||||
## Changelog
|
||||
|
||||
### v0.1.0 (2025-11-22)
|
||||
- Initial release
|
||||
- Campaign data generation
|
||||
- Optimization simulators
|
||||
- Analytics pipelines
|
||||
- Multi-platform support
|
||||
22
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.d.ts
vendored
Normal file
22
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.d.ts
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Marketing Analytics Pipeline Examples
|
||||
*
|
||||
* Generates analytics data including:
|
||||
* - Attribution modeling data
|
||||
* - LTV (Lifetime Value) calculation datasets
|
||||
* - Funnel analysis data
|
||||
* - Seasonal trend simulation
|
||||
*/
|
||||
declare function generateAttributionModels(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateLTVAnalysis(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateFunnelAnalysis(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateSeasonalTrends(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generatePredictiveAnalytics(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateChannelComparison(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateIncrementalityTests(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateMarketingMixModel(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function streamAnalyticsData(): Promise<void>;
|
||||
declare function generateAnalyticsBatch(): Promise<import("../../src/types.js").GenerationResult<unknown>[]>;
|
||||
export declare function runAnalyticsExamples(): Promise<void>;
|
||||
export { generateAttributionModels, generateLTVAnalysis, generateFunnelAnalysis, generateSeasonalTrends, generatePredictiveAnalytics, generateChannelComparison, generateIncrementalityTests, generateMarketingMixModel, streamAnalyticsData, generateAnalyticsBatch };
|
||||
//# sourceMappingURL=analytics-pipeline.d.ts.map
|
||||
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.d.ts.map
vendored
Normal file
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"analytics-pipeline.d.ts","sourceRoot":"","sources":["analytics-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,iBAAe,yBAAyB,oEAmFvC;AAGD,iBAAe,mBAAmB,oEAqGjC;AAGD,iBAAe,sBAAsB,oEA2FpC;AAGD,iBAAe,sBAAsB,oEA2CpC;AAGD,iBAAe,2BAA2B,oEA8EzC;AAGD,iBAAe,yBAAyB,oEA8EvC;AAGD,iBAAe,2BAA2B,oEA0EzC;AAGD,iBAAe,yBAAyB,oEAkFvC;AAGD,iBAAe,mBAAmB,kBA0BjC;AAGD,iBAAe,sBAAsB,sEA+CpC;AAGD,wBAAsB,oBAAoB,kBA2BzC;AAGD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACvB,CAAC"}
|
||||
733
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.js
vendored
Normal file
733
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.js
vendored
Normal file
@@ -0,0 +1,733 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Marketing Analytics Pipeline Examples
|
||||
*
|
||||
* Generates analytics data including:
|
||||
* - Attribution modeling data
|
||||
* - LTV (Lifetime Value) calculation datasets
|
||||
* - Funnel analysis data
|
||||
* - Seasonal trend simulation
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runAnalyticsExamples = runAnalyticsExamples;
|
||||
exports.generateAttributionModels = generateAttributionModels;
|
||||
exports.generateLTVAnalysis = generateLTVAnalysis;
|
||||
exports.generateFunnelAnalysis = generateFunnelAnalysis;
|
||||
exports.generateSeasonalTrends = generateSeasonalTrends;
|
||||
exports.generatePredictiveAnalytics = generatePredictiveAnalytics;
|
||||
exports.generateChannelComparison = generateChannelComparison;
|
||||
exports.generateIncrementalityTests = generateIncrementalityTests;
|
||||
exports.generateMarketingMixModel = generateMarketingMixModel;
|
||||
exports.streamAnalyticsData = streamAnalyticsData;
|
||||
exports.generateAnalyticsBatch = generateAnalyticsBatch;
|
||||
const index_js_1 = require("../../src/index.js");
|
||||
// Example 1: Attribution modeling data
|
||||
async function generateAttributionModels() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
const attributionSchema = {
|
||||
modelId: { type: 'string', required: true },
|
||||
modelType: { type: 'string', required: true },
|
||||
analysisDate: { type: 'string', required: true },
|
||||
timeWindow: { type: 'string', required: true },
|
||||
totalConversions: { type: 'number', required: true },
|
||||
totalRevenue: { type: 'number', required: true },
|
||||
channelAttribution: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
touchpoints: { type: 'number' },
|
||||
firstTouchConversions: { type: 'number' },
|
||||
lastTouchConversions: { type: 'number' },
|
||||
linearConversions: { type: 'number' },
|
||||
timeDecayConversions: { type: 'number' },
|
||||
positionBasedConversions: { type: 'number' },
|
||||
algorithmicConversions: { type: 'number' },
|
||||
attributedRevenue: { type: 'number' },
|
||||
attributedSpend: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
efficiency: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
crossChannelInteractions: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
path: { type: 'array' },
|
||||
conversions: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
avgPathLength: { type: 'number' },
|
||||
avgTimeToConversion: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
insights: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
topPerformingChannels: { type: 'array' },
|
||||
undervaluedChannels: { type: 'array' },
|
||||
overvaluedChannels: { type: 'array' },
|
||||
recommendedBudgetShift: { type: 'object' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: attributionSchema,
|
||||
constraints: {
|
||||
modelType: [
|
||||
'first_touch',
|
||||
'last_touch',
|
||||
'linear',
|
||||
'time_decay',
|
||||
'position_based',
|
||||
'data_driven'
|
||||
],
|
||||
timeWindow: ['7_days', '14_days', '30_days', '60_days', '90_days'],
|
||||
totalConversions: { min: 100, max: 10000 },
|
||||
totalRevenue: { min: 10000, max: 5000000 },
|
||||
channelAttribution: { minLength: 4, maxLength: 10 }
|
||||
}
|
||||
});
|
||||
console.log('Attribution Model Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 2: LTV (Lifetime Value) calculations
|
||||
async function generateLTVAnalysis() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const ltvSchema = {
|
||||
cohortId: { type: 'string', required: true },
|
||||
cohortName: { type: 'string', required: true },
|
||||
acquisitionChannel: { type: 'string', required: true },
|
||||
acquisitionDate: { type: 'string', required: true },
|
||||
cohortSize: { type: 'number', required: true },
|
||||
metrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
avgFirstPurchase: { type: 'number' },
|
||||
avgOrderValue: { type: 'number' },
|
||||
purchaseFrequency: { type: 'number' },
|
||||
customerLifespan: { type: 'number' },
|
||||
retentionRate: { type: 'number' },
|
||||
churnRate: { type: 'number' },
|
||||
marginPerCustomer: { type: 'number' }
|
||||
}
|
||||
},
|
||||
ltvCalculations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
historicLTV: { type: 'number' },
|
||||
predictiveLTV: { type: 'number' },
|
||||
ltv30Days: { type: 'number' },
|
||||
ltv90Days: { type: 'number' },
|
||||
ltv180Days: { type: 'number' },
|
||||
ltv365Days: { type: 'number' },
|
||||
ltv3Years: { type: 'number' }
|
||||
}
|
||||
},
|
||||
acquisition: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
cac: { type: 'number' },
|
||||
ltvCacRatio: { type: 'number' },
|
||||
paybackPeriod: { type: 'number' },
|
||||
roi: { type: 'number' }
|
||||
}
|
||||
},
|
||||
revenueByPeriod: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
period: { type: 'number' },
|
||||
activeCustomers: { type: 'number' },
|
||||
purchases: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
cumulativeRevenue: { type: 'number' },
|
||||
cumulativeLTV: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
segments: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
segmentName: { type: 'string' },
|
||||
percentage: { type: 'number' },
|
||||
avgLTV: { type: 'number' },
|
||||
characteristics: { type: 'array' }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 40,
|
||||
schema: ltvSchema,
|
||||
constraints: {
|
||||
acquisitionChannel: [
|
||||
'google_ads',
|
||||
'facebook_ads',
|
||||
'tiktok_ads',
|
||||
'organic_search',
|
||||
'email',
|
||||
'referral',
|
||||
'direct'
|
||||
],
|
||||
cohortSize: { min: 100, max: 50000 },
|
||||
'metrics.customerLifespan': { min: 3, max: 60 },
|
||||
'acquisition.ltvCacRatio': { min: 0.5, max: 15.0 },
|
||||
revenueByPeriod: { minLength: 12, maxLength: 36 }
|
||||
}
|
||||
});
|
||||
console.log('LTV Analysis Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 3: Marketing funnel analysis
|
||||
async function generateFunnelAnalysis() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const funnelSchema = {
|
||||
funnelId: { type: 'string', required: true },
|
||||
funnelName: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
dateRange: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
start: { type: 'string' },
|
||||
end: { type: 'string' }
|
||||
}
|
||||
},
|
||||
stages: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
stageName: { type: 'string' },
|
||||
stageOrder: { type: 'number' },
|
||||
users: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
conversionRate: { type: 'number' },
|
||||
dropoffRate: { type: 'number' },
|
||||
avgTimeInStage: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
cost: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
overallMetrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
totalUsers: { type: 'number' },
|
||||
totalConversions: { type: 'number' },
|
||||
overallConversionRate: { type: 'number' },
|
||||
totalRevenue: { type: 'number' },
|
||||
totalCost: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
avgTimeToConversion: { type: 'number' }
|
||||
}
|
||||
},
|
||||
dropoffAnalysis: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
fromStage: { type: 'string' },
|
||||
toStage: { type: 'string' },
|
||||
dropoffCount: { type: 'number' },
|
||||
dropoffRate: { type: 'number' },
|
||||
reasons: { type: 'array' },
|
||||
recoveryOpportunities: { type: 'array' }
|
||||
}
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
bottlenecks: { type: 'array' },
|
||||
recommendations: { type: 'array' },
|
||||
expectedImprovement: { type: 'number' },
|
||||
priorityActions: { type: 'array' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 35,
|
||||
schema: funnelSchema,
|
||||
constraints: {
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'email', 'organic'],
|
||||
stages: { minLength: 4, maxLength: 8 },
|
||||
'overallMetrics.overallConversionRate': { min: 0.01, max: 0.25 },
|
||||
'overallMetrics.roas': { min: 0.5, max: 10.0 }
|
||||
}
|
||||
});
|
||||
console.log('Funnel Analysis Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 4: Seasonal trend analysis
|
||||
async function generateSeasonalTrends() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const result = await synth.generateTimeSeries({
|
||||
count: 365,
|
||||
startDate: new Date(Date.now() - 365 * 24 * 60 * 60 * 1000),
|
||||
endDate: new Date(),
|
||||
interval: '1d',
|
||||
metrics: [
|
||||
'impressions',
|
||||
'clicks',
|
||||
'conversions',
|
||||
'spend',
|
||||
'revenue',
|
||||
'roas',
|
||||
'ctr',
|
||||
'cvr',
|
||||
'cpa',
|
||||
'seasonality_index',
|
||||
'trend_index',
|
||||
'day_of_week_effect'
|
||||
],
|
||||
trend: 'up',
|
||||
seasonality: true,
|
||||
noise: 0.12,
|
||||
constraints: {
|
||||
impressions: { min: 50000, max: 500000 },
|
||||
clicks: { min: 500, max: 10000 },
|
||||
conversions: { min: 50, max: 1000 },
|
||||
spend: { min: 500, max: 20000 },
|
||||
revenue: { min: 1000, max: 100000 },
|
||||
roas: { min: 1.0, max: 12.0 },
|
||||
seasonality_index: { min: 0.5, max: 2.0 }
|
||||
}
|
||||
});
|
||||
console.log('Seasonal Trend Data (daily for 1 year):');
|
||||
console.log(result.data.slice(0, 7));
|
||||
console.log('Metadata:', result.metadata);
|
||||
return result;
|
||||
}
|
||||
// Example 5: Predictive analytics
|
||||
async function generatePredictiveAnalytics() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const predictiveSchema = {
|
||||
predictionId: { type: 'string', required: true },
|
||||
predictionDate: { type: 'string', required: true },
|
||||
predictionHorizon: { type: 'string', required: true },
|
||||
model: { type: 'string', required: true },
|
||||
historicalPeriod: { type: 'string', required: true },
|
||||
predictions: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
expectedSpend: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedROAS: { type: 'number' },
|
||||
expectedCAC: { type: 'number' },
|
||||
expectedLTV: { type: 'number' }
|
||||
}
|
||||
},
|
||||
confidenceIntervals: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
spend: { type: 'object' },
|
||||
revenue: { type: 'object' },
|
||||
conversions: { type: 'object' },
|
||||
roas: { type: 'object' }
|
||||
}
|
||||
},
|
||||
scenarios: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
scenarioName: { type: 'string' },
|
||||
probability: { type: 'number' },
|
||||
predictedROAS: { type: 'number' },
|
||||
predictedRevenue: { type: 'number' },
|
||||
factors: { type: 'array' }
|
||||
}
|
||||
}
|
||||
},
|
||||
riskFactors: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
factor: { type: 'string' },
|
||||
impact: { type: 'string' },
|
||||
probability: { type: 'number' },
|
||||
mitigation: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendations: { type: 'array', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 25,
|
||||
schema: predictiveSchema,
|
||||
constraints: {
|
||||
predictionHorizon: ['7_days', '30_days', '90_days', '180_days', '365_days'],
|
||||
model: ['arima', 'prophet', 'lstm', 'random_forest', 'xgboost', 'ensemble'],
|
||||
scenarios: { minLength: 3, maxLength: 5 },
|
||||
'predictions.expectedROAS': { min: 1.0, max: 15.0 }
|
||||
}
|
||||
});
|
||||
console.log('Predictive Analytics Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 6: Channel performance comparison
|
||||
async function generateChannelComparison() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const comparisonSchema = {
|
||||
reportId: { type: 'string', required: true },
|
||||
reportDate: { type: 'string', required: true },
|
||||
dateRange: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
start: { type: 'string' },
|
||||
end: { type: 'string' }
|
||||
}
|
||||
},
|
||||
channels: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
platform: { type: 'string' },
|
||||
campaigns: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpc: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
marketShare: { type: 'number' },
|
||||
efficiency: { type: 'number' },
|
||||
scalability: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
crossChannelMetrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
totalSpend: { type: 'number' },
|
||||
totalRevenue: { type: 'number' },
|
||||
overallROAS: { type: 'number' },
|
||||
channelDiversity: { type: 'number' },
|
||||
portfolioRisk: { type: 'number' }
|
||||
}
|
||||
},
|
||||
recommendations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
scaleUp: { type: 'array' },
|
||||
maintain: { type: 'array' },
|
||||
optimize: { type: 'array' },
|
||||
scaleDown: { type: 'array' },
|
||||
budgetReallocation: { type: 'object' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: comparisonSchema,
|
||||
constraints: {
|
||||
channels: { minLength: 4, maxLength: 10 },
|
||||
'crossChannelMetrics.overallROAS': { min: 2.0, max: 8.0 }
|
||||
}
|
||||
});
|
||||
console.log('Channel Comparison Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 7: Incrementality testing
|
||||
async function generateIncrementalityTests() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const incrementalitySchema = {
|
||||
testId: { type: 'string', required: true },
|
||||
testName: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
testType: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
methodology: { type: 'string', required: true },
|
||||
testGroup: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
size: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
revenue: { type: 'number' }
|
||||
}
|
||||
},
|
||||
controlGroup: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
size: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
revenue: { type: 'number' }
|
||||
}
|
||||
},
|
||||
results: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
incrementalConversions: { type: 'number' },
|
||||
incrementalRevenue: { type: 'number' },
|
||||
incrementalityRate: { type: 'number' },
|
||||
trueROAS: { type: 'number' },
|
||||
reportedROAS: { type: 'number' },
|
||||
overestimation: { type: 'number' },
|
||||
statisticalSignificance: { type: 'boolean' },
|
||||
confidenceLevel: { type: 'number' }
|
||||
}
|
||||
},
|
||||
insights: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
cannibalizedRevenue: { type: 'number' },
|
||||
brandLiftEffect: { type: 'number' },
|
||||
spilloverEffect: { type: 'number' },
|
||||
recommendedAction: { type: 'string' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 20,
|
||||
schema: incrementalitySchema,
|
||||
constraints: {
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'display', 'video'],
|
||||
testType: ['geo_holdout', 'user_holdout', 'time_based', 'psm'],
|
||||
methodology: ['randomized_control', 'quasi_experimental', 'synthetic_control'],
|
||||
'results.incrementalityRate': { min: 0.1, max: 1.0 }
|
||||
}
|
||||
});
|
||||
console.log('Incrementality Test Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 8: Marketing mix modeling
|
||||
async function generateMarketingMixModel() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const mmmSchema = {
|
||||
modelId: { type: 'string', required: true },
|
||||
modelDate: { type: 'string', required: true },
|
||||
timeRange: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
start: { type: 'string' },
|
||||
end: { type: 'string' }
|
||||
}
|
||||
},
|
||||
modelMetrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
rSquared: { type: 'number' },
|
||||
mape: { type: 'number' },
|
||||
rmse: { type: 'number' },
|
||||
decomposition: { type: 'object' }
|
||||
}
|
||||
},
|
||||
channelContributions: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
spend: { type: 'number' },
|
||||
contribution: { type: 'number' },
|
||||
contributionPercent: { type: 'number' },
|
||||
roi: { type: 'number' },
|
||||
saturationLevel: { type: 'number' },
|
||||
carryoverEffect: { type: 'number' },
|
||||
elasticity: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
currentROI: { type: 'number' },
|
||||
optimizedROI: { type: 'number' },
|
||||
improvementPotential: { type: 'number' },
|
||||
optimalAllocation: { type: 'object' },
|
||||
scenarioAnalysis: { type: 'array' }
|
||||
}
|
||||
},
|
||||
externalFactors: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
factor: { type: 'string' },
|
||||
impact: { type: 'number' },
|
||||
significance: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 15,
|
||||
schema: mmmSchema,
|
||||
constraints: {
|
||||
'modelMetrics.rSquared': { min: 0.7, max: 0.95 },
|
||||
channelContributions: { minLength: 5, maxLength: 12 },
|
||||
'optimization.improvementPotential': { min: 0.05, max: 0.5 }
|
||||
}
|
||||
});
|
||||
console.log('Marketing Mix Model Data:');
|
||||
console.log(result.data.slice(0, 1));
|
||||
return result;
|
||||
}
|
||||
// Example 9: Real-time streaming analytics
|
||||
async function streamAnalyticsData() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini',
|
||||
streaming: true
|
||||
});
|
||||
console.log('Streaming real-time analytics:');
|
||||
let count = 0;
|
||||
for await (const metric of synth.generateStream('structured', {
|
||||
count: 15,
|
||||
schema: {
|
||||
timestamp: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true },
|
||||
alert: { type: 'string', required: false }
|
||||
}
|
||||
})) {
|
||||
count++;
|
||||
console.log(`[${count}] Metric received:`, metric);
|
||||
}
|
||||
}
|
||||
// Example 10: Comprehensive analytics batch
|
||||
async function generateAnalyticsBatch() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const analyticsTypes = [
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
type: { type: 'string' },
|
||||
metric: { type: 'string' },
|
||||
value: { type: 'number' },
|
||||
change: { type: 'number' }
|
||||
},
|
||||
constraints: { type: 'attribution' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
type: { type: 'string' },
|
||||
metric: { type: 'string' },
|
||||
value: { type: 'number' },
|
||||
change: { type: 'number' }
|
||||
},
|
||||
constraints: { type: 'ltv' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
type: { type: 'string' },
|
||||
metric: { type: 'string' },
|
||||
value: { type: 'number' },
|
||||
change: { type: 'number' }
|
||||
},
|
||||
constraints: { type: 'funnel' }
|
||||
}
|
||||
];
|
||||
const results = await synth.generateBatch('structured', analyticsTypes, 3);
|
||||
console.log('Analytics Batch Results:');
|
||||
results.forEach((result, i) => {
|
||||
const types = ['Attribution', 'LTV', 'Funnel'];
|
||||
console.log(`${types[i]}: ${result.metadata.count} metrics in ${result.metadata.duration}ms`);
|
||||
});
|
||||
return results;
|
||||
}
|
||||
// Run all examples
|
||||
async function runAnalyticsExamples() {
|
||||
console.log('=== Example 1: Attribution Models ===');
|
||||
await generateAttributionModels();
|
||||
console.log('\n=== Example 2: LTV Analysis ===');
|
||||
await generateLTVAnalysis();
|
||||
console.log('\n=== Example 3: Funnel Analysis ===');
|
||||
await generateFunnelAnalysis();
|
||||
console.log('\n=== Example 4: Seasonal Trends ===');
|
||||
await generateSeasonalTrends();
|
||||
console.log('\n=== Example 5: Predictive Analytics ===');
|
||||
await generatePredictiveAnalytics();
|
||||
console.log('\n=== Example 6: Channel Comparison ===');
|
||||
await generateChannelComparison();
|
||||
console.log('\n=== Example 7: Incrementality Tests ===');
|
||||
await generateIncrementalityTests();
|
||||
console.log('\n=== Example 8: Marketing Mix Model ===');
|
||||
await generateMarketingMixModel();
|
||||
console.log('\n=== Example 10: Analytics Batch ===');
|
||||
await generateAnalyticsBatch();
|
||||
}
|
||||
// Uncomment to run
|
||||
// runAnalyticsExamples().catch(console.error);
|
||||
//# sourceMappingURL=analytics-pipeline.js.map
|
||||
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
791
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.ts
vendored
Normal file
791
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/analytics-pipeline.ts
vendored
Normal file
@@ -0,0 +1,791 @@
|
||||
/**
|
||||
* Marketing Analytics Pipeline Examples
|
||||
*
|
||||
* Generates analytics data including:
|
||||
* - Attribution modeling data
|
||||
* - LTV (Lifetime Value) calculation datasets
|
||||
* - Funnel analysis data
|
||||
* - Seasonal trend simulation
|
||||
*/
|
||||
|
||||
import { AgenticSynth, createSynth } from '../../src/index.js';
|
||||
|
||||
// Example 1: Attribution modeling data
|
||||
async function generateAttributionModels() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
|
||||
const attributionSchema = {
|
||||
modelId: { type: 'string', required: true },
|
||||
modelType: { type: 'string', required: true },
|
||||
analysisDate: { type: 'string', required: true },
|
||||
timeWindow: { type: 'string', required: true },
|
||||
totalConversions: { type: 'number', required: true },
|
||||
totalRevenue: { type: 'number', required: true },
|
||||
channelAttribution: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
touchpoints: { type: 'number' },
|
||||
firstTouchConversions: { type: 'number' },
|
||||
lastTouchConversions: { type: 'number' },
|
||||
linearConversions: { type: 'number' },
|
||||
timeDecayConversions: { type: 'number' },
|
||||
positionBasedConversions: { type: 'number' },
|
||||
algorithmicConversions: { type: 'number' },
|
||||
attributedRevenue: { type: 'number' },
|
||||
attributedSpend: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
efficiency: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
crossChannelInteractions: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
path: { type: 'array' },
|
||||
conversions: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
avgPathLength: { type: 'number' },
|
||||
avgTimeToConversion: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
insights: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
topPerformingChannels: { type: 'array' },
|
||||
undervaluedChannels: { type: 'array' },
|
||||
overvaluedChannels: { type: 'array' },
|
||||
recommendedBudgetShift: { type: 'object' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: attributionSchema,
|
||||
constraints: {
|
||||
modelType: [
|
||||
'first_touch',
|
||||
'last_touch',
|
||||
'linear',
|
||||
'time_decay',
|
||||
'position_based',
|
||||
'data_driven'
|
||||
],
|
||||
timeWindow: ['7_days', '14_days', '30_days', '60_days', '90_days'],
|
||||
totalConversions: { min: 100, max: 10000 },
|
||||
totalRevenue: { min: 10000, max: 5000000 },
|
||||
channelAttribution: { minLength: 4, maxLength: 10 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Attribution Model Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 2: LTV (Lifetime Value) calculations
|
||||
async function generateLTVAnalysis() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const ltvSchema = {
|
||||
cohortId: { type: 'string', required: true },
|
||||
cohortName: { type: 'string', required: true },
|
||||
acquisitionChannel: { type: 'string', required: true },
|
||||
acquisitionDate: { type: 'string', required: true },
|
||||
cohortSize: { type: 'number', required: true },
|
||||
metrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
avgFirstPurchase: { type: 'number' },
|
||||
avgOrderValue: { type: 'number' },
|
||||
purchaseFrequency: { type: 'number' },
|
||||
customerLifespan: { type: 'number' },
|
||||
retentionRate: { type: 'number' },
|
||||
churnRate: { type: 'number' },
|
||||
marginPerCustomer: { type: 'number' }
|
||||
}
|
||||
},
|
||||
ltvCalculations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
historicLTV: { type: 'number' },
|
||||
predictiveLTV: { type: 'number' },
|
||||
ltv30Days: { type: 'number' },
|
||||
ltv90Days: { type: 'number' },
|
||||
ltv180Days: { type: 'number' },
|
||||
ltv365Days: { type: 'number' },
|
||||
ltv3Years: { type: 'number' }
|
||||
}
|
||||
},
|
||||
acquisition: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
cac: { type: 'number' },
|
||||
ltvCacRatio: { type: 'number' },
|
||||
paybackPeriod: { type: 'number' },
|
||||
roi: { type: 'number' }
|
||||
}
|
||||
},
|
||||
revenueByPeriod: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
period: { type: 'number' },
|
||||
activeCustomers: { type: 'number' },
|
||||
purchases: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
cumulativeRevenue: { type: 'number' },
|
||||
cumulativeLTV: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
segments: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
segmentName: { type: 'string' },
|
||||
percentage: { type: 'number' },
|
||||
avgLTV: { type: 'number' },
|
||||
characteristics: { type: 'array' }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 40,
|
||||
schema: ltvSchema,
|
||||
constraints: {
|
||||
acquisitionChannel: [
|
||||
'google_ads',
|
||||
'facebook_ads',
|
||||
'tiktok_ads',
|
||||
'organic_search',
|
||||
'email',
|
||||
'referral',
|
||||
'direct'
|
||||
],
|
||||
cohortSize: { min: 100, max: 50000 },
|
||||
'metrics.customerLifespan': { min: 3, max: 60 },
|
||||
'acquisition.ltvCacRatio': { min: 0.5, max: 15.0 },
|
||||
revenueByPeriod: { minLength: 12, maxLength: 36 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('LTV Analysis Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 3: Marketing funnel analysis
|
||||
async function generateFunnelAnalysis() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const funnelSchema = {
|
||||
funnelId: { type: 'string', required: true },
|
||||
funnelName: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
dateRange: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
start: { type: 'string' },
|
||||
end: { type: 'string' }
|
||||
}
|
||||
},
|
||||
stages: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
stageName: { type: 'string' },
|
||||
stageOrder: { type: 'number' },
|
||||
users: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
conversionRate: { type: 'number' },
|
||||
dropoffRate: { type: 'number' },
|
||||
avgTimeInStage: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
cost: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
overallMetrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
totalUsers: { type: 'number' },
|
||||
totalConversions: { type: 'number' },
|
||||
overallConversionRate: { type: 'number' },
|
||||
totalRevenue: { type: 'number' },
|
||||
totalCost: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
avgTimeToConversion: { type: 'number' }
|
||||
}
|
||||
},
|
||||
dropoffAnalysis: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
fromStage: { type: 'string' },
|
||||
toStage: { type: 'string' },
|
||||
dropoffCount: { type: 'number' },
|
||||
dropoffRate: { type: 'number' },
|
||||
reasons: { type: 'array' },
|
||||
recoveryOpportunities: { type: 'array' }
|
||||
}
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
bottlenecks: { type: 'array' },
|
||||
recommendations: { type: 'array' },
|
||||
expectedImprovement: { type: 'number' },
|
||||
priorityActions: { type: 'array' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 35,
|
||||
schema: funnelSchema,
|
||||
constraints: {
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'email', 'organic'],
|
||||
stages: { minLength: 4, maxLength: 8 },
|
||||
'overallMetrics.overallConversionRate': { min: 0.01, max: 0.25 },
|
||||
'overallMetrics.roas': { min: 0.5, max: 10.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Funnel Analysis Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 4: Seasonal trend analysis
|
||||
async function generateSeasonalTrends() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const result = await synth.generateTimeSeries({
|
||||
count: 365,
|
||||
startDate: new Date(Date.now() - 365 * 24 * 60 * 60 * 1000),
|
||||
endDate: new Date(),
|
||||
interval: '1d',
|
||||
metrics: [
|
||||
'impressions',
|
||||
'clicks',
|
||||
'conversions',
|
||||
'spend',
|
||||
'revenue',
|
||||
'roas',
|
||||
'ctr',
|
||||
'cvr',
|
||||
'cpa',
|
||||
'seasonality_index',
|
||||
'trend_index',
|
||||
'day_of_week_effect'
|
||||
],
|
||||
trend: 'up',
|
||||
seasonality: true,
|
||||
noise: 0.12,
|
||||
constraints: {
|
||||
impressions: { min: 50000, max: 500000 },
|
||||
clicks: { min: 500, max: 10000 },
|
||||
conversions: { min: 50, max: 1000 },
|
||||
spend: { min: 500, max: 20000 },
|
||||
revenue: { min: 1000, max: 100000 },
|
||||
roas: { min: 1.0, max: 12.0 },
|
||||
seasonality_index: { min: 0.5, max: 2.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Seasonal Trend Data (daily for 1 year):');
|
||||
console.log(result.data.slice(0, 7));
|
||||
console.log('Metadata:', result.metadata);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 5: Predictive analytics
|
||||
async function generatePredictiveAnalytics() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const predictiveSchema = {
|
||||
predictionId: { type: 'string', required: true },
|
||||
predictionDate: { type: 'string', required: true },
|
||||
predictionHorizon: { type: 'string', required: true },
|
||||
model: { type: 'string', required: true },
|
||||
historicalPeriod: { type: 'string', required: true },
|
||||
predictions: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
expectedSpend: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedROAS: { type: 'number' },
|
||||
expectedCAC: { type: 'number' },
|
||||
expectedLTV: { type: 'number' }
|
||||
}
|
||||
},
|
||||
confidenceIntervals: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
spend: { type: 'object' },
|
||||
revenue: { type: 'object' },
|
||||
conversions: { type: 'object' },
|
||||
roas: { type: 'object' }
|
||||
}
|
||||
},
|
||||
scenarios: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
scenarioName: { type: 'string' },
|
||||
probability: { type: 'number' },
|
||||
predictedROAS: { type: 'number' },
|
||||
predictedRevenue: { type: 'number' },
|
||||
factors: { type: 'array' }
|
||||
}
|
||||
}
|
||||
},
|
||||
riskFactors: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
factor: { type: 'string' },
|
||||
impact: { type: 'string' },
|
||||
probability: { type: 'number' },
|
||||
mitigation: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendations: { type: 'array', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 25,
|
||||
schema: predictiveSchema,
|
||||
constraints: {
|
||||
predictionHorizon: ['7_days', '30_days', '90_days', '180_days', '365_days'],
|
||||
model: ['arima', 'prophet', 'lstm', 'random_forest', 'xgboost', 'ensemble'],
|
||||
scenarios: { minLength: 3, maxLength: 5 },
|
||||
'predictions.expectedROAS': { min: 1.0, max: 15.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Predictive Analytics Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 6: Channel performance comparison
|
||||
async function generateChannelComparison() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const comparisonSchema = {
|
||||
reportId: { type: 'string', required: true },
|
||||
reportDate: { type: 'string', required: true },
|
||||
dateRange: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
start: { type: 'string' },
|
||||
end: { type: 'string' }
|
||||
}
|
||||
},
|
||||
channels: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
platform: { type: 'string' },
|
||||
campaigns: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpc: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
marketShare: { type: 'number' },
|
||||
efficiency: { type: 'number' },
|
||||
scalability: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
crossChannelMetrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
totalSpend: { type: 'number' },
|
||||
totalRevenue: { type: 'number' },
|
||||
overallROAS: { type: 'number' },
|
||||
channelDiversity: { type: 'number' },
|
||||
portfolioRisk: { type: 'number' }
|
||||
}
|
||||
},
|
||||
recommendations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
scaleUp: { type: 'array' },
|
||||
maintain: { type: 'array' },
|
||||
optimize: { type: 'array' },
|
||||
scaleDown: { type: 'array' },
|
||||
budgetReallocation: { type: 'object' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: comparisonSchema,
|
||||
constraints: {
|
||||
channels: { minLength: 4, maxLength: 10 },
|
||||
'crossChannelMetrics.overallROAS': { min: 2.0, max: 8.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Channel Comparison Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 7: Incrementality testing
|
||||
async function generateIncrementalityTests() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const incrementalitySchema = {
|
||||
testId: { type: 'string', required: true },
|
||||
testName: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
testType: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
methodology: { type: 'string', required: true },
|
||||
testGroup: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
size: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
revenue: { type: 'number' }
|
||||
}
|
||||
},
|
||||
controlGroup: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
size: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
revenue: { type: 'number' }
|
||||
}
|
||||
},
|
||||
results: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
incrementalConversions: { type: 'number' },
|
||||
incrementalRevenue: { type: 'number' },
|
||||
incrementalityRate: { type: 'number' },
|
||||
trueROAS: { type: 'number' },
|
||||
reportedROAS: { type: 'number' },
|
||||
overestimation: { type: 'number' },
|
||||
statisticalSignificance: { type: 'boolean' },
|
||||
confidenceLevel: { type: 'number' }
|
||||
}
|
||||
},
|
||||
insights: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
cannibalizedRevenue: { type: 'number' },
|
||||
brandLiftEffect: { type: 'number' },
|
||||
spilloverEffect: { type: 'number' },
|
||||
recommendedAction: { type: 'string' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 20,
|
||||
schema: incrementalitySchema,
|
||||
constraints: {
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'display', 'video'],
|
||||
testType: ['geo_holdout', 'user_holdout', 'time_based', 'psm'],
|
||||
methodology: ['randomized_control', 'quasi_experimental', 'synthetic_control'],
|
||||
'results.incrementalityRate': { min: 0.1, max: 1.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Incrementality Test Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 8: Marketing mix modeling
|
||||
async function generateMarketingMixModel() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const mmmSchema = {
|
||||
modelId: { type: 'string', required: true },
|
||||
modelDate: { type: 'string', required: true },
|
||||
timeRange: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
start: { type: 'string' },
|
||||
end: { type: 'string' }
|
||||
}
|
||||
},
|
||||
modelMetrics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
rSquared: { type: 'number' },
|
||||
mape: { type: 'number' },
|
||||
rmse: { type: 'number' },
|
||||
decomposition: { type: 'object' }
|
||||
}
|
||||
},
|
||||
channelContributions: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
spend: { type: 'number' },
|
||||
contribution: { type: 'number' },
|
||||
contributionPercent: { type: 'number' },
|
||||
roi: { type: 'number' },
|
||||
saturationLevel: { type: 'number' },
|
||||
carryoverEffect: { type: 'number' },
|
||||
elasticity: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
currentROI: { type: 'number' },
|
||||
optimizedROI: { type: 'number' },
|
||||
improvementPotential: { type: 'number' },
|
||||
optimalAllocation: { type: 'object' },
|
||||
scenarioAnalysis: { type: 'array' }
|
||||
}
|
||||
},
|
||||
externalFactors: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
factor: { type: 'string' },
|
||||
impact: { type: 'number' },
|
||||
significance: { type: 'string' }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 15,
|
||||
schema: mmmSchema,
|
||||
constraints: {
|
||||
'modelMetrics.rSquared': { min: 0.7, max: 0.95 },
|
||||
channelContributions: { minLength: 5, maxLength: 12 },
|
||||
'optimization.improvementPotential': { min: 0.05, max: 0.5 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Marketing Mix Model Data:');
|
||||
console.log(result.data.slice(0, 1));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 9: Real-time streaming analytics
|
||||
async function streamAnalyticsData() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini',
|
||||
streaming: true
|
||||
});
|
||||
|
||||
console.log('Streaming real-time analytics:');
|
||||
|
||||
let count = 0;
|
||||
for await (const metric of synth.generateStream('structured', {
|
||||
count: 15,
|
||||
schema: {
|
||||
timestamp: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true },
|
||||
alert: { type: 'string', required: false }
|
||||
}
|
||||
})) {
|
||||
count++;
|
||||
console.log(`[${count}] Metric received:`, metric);
|
||||
}
|
||||
}
|
||||
|
||||
// Example 10: Comprehensive analytics batch
|
||||
async function generateAnalyticsBatch() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const analyticsTypes = [
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
type: { type: 'string' },
|
||||
metric: { type: 'string' },
|
||||
value: { type: 'number' },
|
||||
change: { type: 'number' }
|
||||
},
|
||||
constraints: { type: 'attribution' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
type: { type: 'string' },
|
||||
metric: { type: 'string' },
|
||||
value: { type: 'number' },
|
||||
change: { type: 'number' }
|
||||
},
|
||||
constraints: { type: 'ltv' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
type: { type: 'string' },
|
||||
metric: { type: 'string' },
|
||||
value: { type: 'number' },
|
||||
change: { type: 'number' }
|
||||
},
|
||||
constraints: { type: 'funnel' }
|
||||
}
|
||||
];
|
||||
|
||||
const results = await synth.generateBatch('structured', analyticsTypes, 3);
|
||||
|
||||
console.log('Analytics Batch Results:');
|
||||
results.forEach((result, i) => {
|
||||
const types = ['Attribution', 'LTV', 'Funnel'];
|
||||
console.log(`${types[i]}: ${result.metadata.count} metrics in ${result.metadata.duration}ms`);
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
// Run all examples
|
||||
export async function runAnalyticsExamples() {
|
||||
console.log('=== Example 1: Attribution Models ===');
|
||||
await generateAttributionModels();
|
||||
|
||||
console.log('\n=== Example 2: LTV Analysis ===');
|
||||
await generateLTVAnalysis();
|
||||
|
||||
console.log('\n=== Example 3: Funnel Analysis ===');
|
||||
await generateFunnelAnalysis();
|
||||
|
||||
console.log('\n=== Example 4: Seasonal Trends ===');
|
||||
await generateSeasonalTrends();
|
||||
|
||||
console.log('\n=== Example 5: Predictive Analytics ===');
|
||||
await generatePredictiveAnalytics();
|
||||
|
||||
console.log('\n=== Example 6: Channel Comparison ===');
|
||||
await generateChannelComparison();
|
||||
|
||||
console.log('\n=== Example 7: Incrementality Tests ===');
|
||||
await generateIncrementalityTests();
|
||||
|
||||
console.log('\n=== Example 8: Marketing Mix Model ===');
|
||||
await generateMarketingMixModel();
|
||||
|
||||
console.log('\n=== Example 10: Analytics Batch ===');
|
||||
await generateAnalyticsBatch();
|
||||
}
|
||||
|
||||
// Export individual functions
|
||||
export {
|
||||
generateAttributionModels,
|
||||
generateLTVAnalysis,
|
||||
generateFunnelAnalysis,
|
||||
generateSeasonalTrends,
|
||||
generatePredictiveAnalytics,
|
||||
generateChannelComparison,
|
||||
generateIncrementalityTests,
|
||||
generateMarketingMixModel,
|
||||
streamAnalyticsData,
|
||||
generateAnalyticsBatch
|
||||
};
|
||||
|
||||
// Uncomment to run
|
||||
// runAnalyticsExamples().catch(console.error);
|
||||
23
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.d.ts
vendored
Normal file
23
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Ad Campaign Performance Data Generation
|
||||
*
|
||||
* Generates realistic ad campaign data including:
|
||||
* - Campaign metrics (impressions, clicks, conversions, spend)
|
||||
* - Multi-channel attribution data
|
||||
* - Customer journey tracking
|
||||
* - A/B test results
|
||||
* - Cohort analysis data
|
||||
*/
|
||||
declare function generateGoogleAdsCampaign(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateFacebookAdsCampaign(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateTikTokAdsCampaign(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateAttributionData(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateCustomerJourneys(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateABTestResults(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateCohortAnalysis(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function generateTimeSeriesCampaignData(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function streamCampaignData(): Promise<void>;
|
||||
declare function generateMultiPlatformBatch(): Promise<import("../../src/types.js").GenerationResult<unknown>[]>;
|
||||
export declare function runCampaignDataExamples(): Promise<void>;
|
||||
export { generateGoogleAdsCampaign, generateFacebookAdsCampaign, generateTikTokAdsCampaign, generateAttributionData, generateCustomerJourneys, generateABTestResults, generateCohortAnalysis, generateTimeSeriesCampaignData, streamCampaignData, generateMultiPlatformBatch };
|
||||
//# sourceMappingURL=campaign-data.d.ts.map
|
||||
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.d.ts.map
vendored
Normal file
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"campaign-data.d.ts","sourceRoot":"","sources":["campaign-data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,iBAAe,yBAAyB,oEA8CvC;AAGD,iBAAe,2BAA2B,oEAiDzC;AAGD,iBAAe,yBAAyB,oEAkDvC;AAGD,iBAAe,uBAAuB,oEA0DrC;AAGD,iBAAe,wBAAwB,oEAoDtC;AAGD,iBAAe,qBAAqB,oEAsDnC;AAGD,iBAAe,sBAAsB,oEAmDpC;AAGD,iBAAe,8BAA8B,oEAwC5C;AAGD,iBAAe,kBAAkB,kBAyBhC;AAGD,iBAAe,0BAA0B,sEAsDxC;AAGD,wBAAsB,uBAAuB,kBA2B5C;AAGD,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,sBAAsB,EACtB,8BAA8B,EAC9B,kBAAkB,EAClB,0BAA0B,EAC3B,CAAC"}
|
||||
510
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.js
vendored
Normal file
510
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.js
vendored
Normal file
@@ -0,0 +1,510 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Ad Campaign Performance Data Generation
|
||||
*
|
||||
* Generates realistic ad campaign data including:
|
||||
* - Campaign metrics (impressions, clicks, conversions, spend)
|
||||
* - Multi-channel attribution data
|
||||
* - Customer journey tracking
|
||||
* - A/B test results
|
||||
* - Cohort analysis data
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runCampaignDataExamples = runCampaignDataExamples;
|
||||
exports.generateGoogleAdsCampaign = generateGoogleAdsCampaign;
|
||||
exports.generateFacebookAdsCampaign = generateFacebookAdsCampaign;
|
||||
exports.generateTikTokAdsCampaign = generateTikTokAdsCampaign;
|
||||
exports.generateAttributionData = generateAttributionData;
|
||||
exports.generateCustomerJourneys = generateCustomerJourneys;
|
||||
exports.generateABTestResults = generateABTestResults;
|
||||
exports.generateCohortAnalysis = generateCohortAnalysis;
|
||||
exports.generateTimeSeriesCampaignData = generateTimeSeriesCampaignData;
|
||||
exports.streamCampaignData = streamCampaignData;
|
||||
exports.generateMultiPlatformBatch = generateMultiPlatformBatch;
|
||||
const index_js_1 = require("../../src/index.js");
|
||||
// Example 1: Google Ads campaign metrics
|
||||
async function generateGoogleAdsCampaign() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
const campaignSchema = {
|
||||
campaignId: { type: 'string', required: true },
|
||||
campaignName: { type: 'string', required: true },
|
||||
date: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
adGroup: { type: 'string', required: true },
|
||||
keyword: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
cost: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
ctr: { type: 'number', required: true },
|
||||
cpc: { type: 'number', required: true },
|
||||
cpa: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true },
|
||||
qualityScore: { type: 'number', required: true },
|
||||
avgPosition: { type: 'number', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 100,
|
||||
schema: campaignSchema,
|
||||
constraints: {
|
||||
platform: 'Google Ads',
|
||||
impressions: { min: 1000, max: 100000 },
|
||||
ctr: { min: 0.01, max: 0.15 },
|
||||
cpc: { min: 0.50, max: 10.00 },
|
||||
roas: { min: 0.5, max: 8.0 },
|
||||
qualityScore: { min: 1, max: 10 },
|
||||
avgPosition: { min: 1.0, max: 5.0 }
|
||||
},
|
||||
format: 'json'
|
||||
});
|
||||
console.log('Google Ads Campaign Data:');
|
||||
console.log(result.data.slice(0, 3));
|
||||
console.log('Metadata:', result.metadata);
|
||||
return result;
|
||||
}
|
||||
// Example 2: Facebook/Meta Ads campaign performance
|
||||
async function generateFacebookAdsCampaign() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const facebookSchema = {
|
||||
adSetId: { type: 'string', required: true },
|
||||
adSetName: { type: 'string', required: true },
|
||||
adId: { type: 'string', required: true },
|
||||
adName: { type: 'string', required: true },
|
||||
date: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
objective: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
reach: { type: 'number', required: true },
|
||||
frequency: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
linkClicks: { type: 'number', required: true },
|
||||
ctr: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
purchases: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
cpc: { type: 'number', required: true },
|
||||
cpm: { type: 'number', required: true },
|
||||
costPerPurchase: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true },
|
||||
addToCarts: { type: 'number', required: true },
|
||||
initiateCheckout: { type: 'number', required: true },
|
||||
relevanceScore: { type: 'number', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 150,
|
||||
schema: facebookSchema,
|
||||
constraints: {
|
||||
platform: 'Facebook Ads',
|
||||
objective: ['conversions', 'traffic', 'brand_awareness', 'video_views'],
|
||||
impressions: { min: 5000, max: 500000 },
|
||||
frequency: { min: 1.0, max: 5.0 },
|
||||
cpm: { min: 5.00, max: 50.00 },
|
||||
roas: { min: 0.8, max: 6.0 },
|
||||
relevanceScore: { min: 1, max: 10 }
|
||||
}
|
||||
});
|
||||
console.log('Facebook Ads Campaign Data:');
|
||||
console.log(result.data.slice(0, 3));
|
||||
return result;
|
||||
}
|
||||
// Example 3: TikTok Ads campaign performance
|
||||
async function generateTikTokAdsCampaign() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const tiktokSchema = {
|
||||
campaignId: { type: 'string', required: true },
|
||||
campaignName: { type: 'string', required: true },
|
||||
adGroupId: { type: 'string', required: true },
|
||||
adId: { type: 'string', required: true },
|
||||
date: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
objective: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
videoViews: { type: 'number', required: true },
|
||||
videoWatchTime: { type: 'number', required: true },
|
||||
videoCompletionRate: { type: 'number', required: true },
|
||||
engagement: { type: 'number', required: true },
|
||||
shares: { type: 'number', required: true },
|
||||
comments: { type: 'number', required: true },
|
||||
likes: { type: 'number', required: true },
|
||||
follows: { type: 'number', required: true },
|
||||
ctr: { type: 'number', required: true },
|
||||
cpc: { type: 'number', required: true },
|
||||
cpm: { type: 'number', required: true },
|
||||
cpa: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 120,
|
||||
schema: tiktokSchema,
|
||||
constraints: {
|
||||
platform: 'TikTok Ads',
|
||||
objective: ['app_promotion', 'conversions', 'traffic', 'video_views'],
|
||||
impressions: { min: 10000, max: 1000000 },
|
||||
videoCompletionRate: { min: 0.1, max: 0.8 },
|
||||
cpm: { min: 3.00, max: 30.00 },
|
||||
roas: { min: 0.6, max: 7.0 }
|
||||
}
|
||||
});
|
||||
console.log('TikTok Ads Campaign Data:');
|
||||
console.log(result.data.slice(0, 3));
|
||||
return result;
|
||||
}
|
||||
// Example 4: Multi-channel attribution data
|
||||
async function generateAttributionData() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const attributionSchema = {
|
||||
userId: { type: 'string', required: true },
|
||||
conversionId: { type: 'string', required: true },
|
||||
conversionDate: { type: 'string', required: true },
|
||||
conversionValue: { type: 'number', required: true },
|
||||
touchpoints: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
campaign: { type: 'string' },
|
||||
timestamp: { type: 'string' },
|
||||
touchpointPosition: { type: 'number' },
|
||||
attributionWeight: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
attributionModel: { type: 'string', required: true },
|
||||
firstTouch: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
value: { type: 'number' }
|
||||
}
|
||||
},
|
||||
lastTouch: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
value: { type: 'number' }
|
||||
}
|
||||
},
|
||||
linearAttribution: { type: 'object', required: false },
|
||||
timeDecayAttribution: { type: 'object', required: false },
|
||||
positionBasedAttribution: { type: 'object', required: false }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 80,
|
||||
schema: attributionSchema,
|
||||
constraints: {
|
||||
attributionModel: ['first_touch', 'last_touch', 'linear', 'time_decay', 'position_based'],
|
||||
touchpoints: { minLength: 2, maxLength: 8 },
|
||||
conversionValue: { min: 10, max: 5000 }
|
||||
}
|
||||
});
|
||||
console.log('Multi-Channel Attribution Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 5: Customer journey tracking
|
||||
async function generateCustomerJourneys() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const journeySchema = {
|
||||
journeyId: { type: 'string', required: true },
|
||||
userId: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
journeyLength: { type: 'number', required: true },
|
||||
touchpointCount: { type: 'number', required: true },
|
||||
events: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
timestamp: { type: 'string' },
|
||||
eventType: { type: 'string' },
|
||||
channel: { type: 'string' },
|
||||
campaign: { type: 'string' },
|
||||
device: { type: 'string' },
|
||||
location: { type: 'string' },
|
||||
pageUrl: { type: 'string' },
|
||||
duration: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
converted: { type: 'boolean', required: true },
|
||||
conversionValue: { type: 'number', required: false },
|
||||
conversionType: { type: 'string', required: false },
|
||||
totalAdSpend: { type: 'number', required: true },
|
||||
roi: { type: 'number', required: false }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 60,
|
||||
schema: journeySchema,
|
||||
constraints: {
|
||||
journeyLength: { min: 1, max: 30 },
|
||||
touchpointCount: { min: 1, max: 15 },
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'email', 'organic_search', 'direct'],
|
||||
device: ['mobile', 'desktop', 'tablet'],
|
||||
conversionType: ['purchase', 'signup', 'download', 'lead']
|
||||
}
|
||||
});
|
||||
console.log('Customer Journey Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 6: A/B test results
|
||||
async function generateABTestResults() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const abTestSchema = {
|
||||
testId: { type: 'string', required: true },
|
||||
testName: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
testType: { type: 'string', required: true },
|
||||
variants: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
variantId: { type: 'string' },
|
||||
variantName: { type: 'string' },
|
||||
trafficAllocation: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
winner: { type: 'string', required: false },
|
||||
confidenceLevel: { type: 'number', required: true },
|
||||
statistically_significant: { type: 'boolean', required: true },
|
||||
liftPercent: { type: 'number', required: false }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 40,
|
||||
schema: abTestSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
testType: ['creative', 'audience', 'bidding', 'landing_page', 'headline', 'cta'],
|
||||
variants: { minLength: 2, maxLength: 4 },
|
||||
confidenceLevel: { min: 0.5, max: 0.99 }
|
||||
}
|
||||
});
|
||||
console.log('A/B Test Results:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 7: Cohort analysis data
|
||||
async function generateCohortAnalysis() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const cohortSchema = {
|
||||
cohortId: { type: 'string', required: true },
|
||||
cohortName: { type: 'string', required: true },
|
||||
acquisitionDate: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
initialUsers: { type: 'number', required: true },
|
||||
retentionData: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
period: { type: 'number' },
|
||||
activeUsers: { type: 'number' },
|
||||
retentionRate: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
avgOrderValue: { type: 'number' },
|
||||
purchaseFrequency: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
totalSpend: { type: 'number', required: true },
|
||||
totalRevenue: { type: 'number', required: true },
|
||||
ltv: { type: 'number', required: true },
|
||||
cac: { type: 'number', required: true },
|
||||
ltvCacRatio: { type: 'number', required: true },
|
||||
paybackPeriod: { type: 'number', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: cohortSchema,
|
||||
constraints: {
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'email', 'organic'],
|
||||
initialUsers: { min: 100, max: 10000 },
|
||||
retentionData: { minLength: 6, maxLength: 12 },
|
||||
ltvCacRatio: { min: 0.5, max: 10.0 },
|
||||
paybackPeriod: { min: 1, max: 24 }
|
||||
}
|
||||
});
|
||||
console.log('Cohort Analysis Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 8: Time-series campaign performance
|
||||
async function generateTimeSeriesCampaignData() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const result = await synth.generateTimeSeries({
|
||||
count: 90,
|
||||
startDate: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000),
|
||||
endDate: new Date(),
|
||||
interval: '1d',
|
||||
metrics: [
|
||||
'impressions',
|
||||
'clicks',
|
||||
'conversions',
|
||||
'spend',
|
||||
'revenue',
|
||||
'roas',
|
||||
'ctr',
|
||||
'cvr'
|
||||
],
|
||||
trend: 'up',
|
||||
seasonality: true,
|
||||
noise: 0.15,
|
||||
constraints: {
|
||||
impressions: { min: 10000, max: 100000 },
|
||||
clicks: { min: 100, max: 5000 },
|
||||
conversions: { min: 10, max: 500 },
|
||||
spend: { min: 100, max: 5000 },
|
||||
revenue: { min: 0, max: 25000 },
|
||||
roas: { min: 0.5, max: 8.0 },
|
||||
ctr: { min: 0.01, max: 0.1 },
|
||||
cvr: { min: 0.01, max: 0.15 }
|
||||
}
|
||||
});
|
||||
console.log('Time-Series Campaign Data:');
|
||||
console.log(result.data.slice(0, 7));
|
||||
console.log('Metadata:', result.metadata);
|
||||
return result;
|
||||
}
|
||||
// Example 9: Streaming real-time campaign data
|
||||
async function streamCampaignData() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini',
|
||||
streaming: true
|
||||
});
|
||||
console.log('Streaming campaign data:');
|
||||
let count = 0;
|
||||
for await (const dataPoint of synth.generateStream('structured', {
|
||||
count: 20,
|
||||
schema: {
|
||||
timestamp: { type: 'string', required: true },
|
||||
campaignId: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true }
|
||||
}
|
||||
})) {
|
||||
count++;
|
||||
console.log(`[${count}] Received:`, dataPoint);
|
||||
}
|
||||
}
|
||||
// Example 10: Batch generation for multiple platforms
|
||||
async function generateMultiPlatformBatch() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const platformConfigs = [
|
||||
{
|
||||
count: 50,
|
||||
schema: {
|
||||
platform: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: { platform: 'Google Ads' }
|
||||
},
|
||||
{
|
||||
count: 50,
|
||||
schema: {
|
||||
platform: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: { platform: 'Facebook Ads' }
|
||||
},
|
||||
{
|
||||
count: 50,
|
||||
schema: {
|
||||
platform: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: { platform: 'TikTok Ads' }
|
||||
}
|
||||
];
|
||||
const results = await synth.generateBatch('structured', platformConfigs, 3);
|
||||
console.log('Multi-Platform Batch Results:');
|
||||
results.forEach((result, i) => {
|
||||
const platforms = ['Google Ads', 'Facebook Ads', 'TikTok Ads'];
|
||||
console.log(`${platforms[i]}: ${result.metadata.count} records in ${result.metadata.duration}ms`);
|
||||
console.log('Sample:', result.data.slice(0, 2));
|
||||
});
|
||||
return results;
|
||||
}
|
||||
// Run all examples
|
||||
async function runCampaignDataExamples() {
|
||||
console.log('=== Example 1: Google Ads Campaign ===');
|
||||
await generateGoogleAdsCampaign();
|
||||
console.log('\n=== Example 2: Facebook Ads Campaign ===');
|
||||
await generateFacebookAdsCampaign();
|
||||
console.log('\n=== Example 3: TikTok Ads Campaign ===');
|
||||
await generateTikTokAdsCampaign();
|
||||
console.log('\n=== Example 4: Multi-Channel Attribution ===');
|
||||
await generateAttributionData();
|
||||
console.log('\n=== Example 5: Customer Journeys ===');
|
||||
await generateCustomerJourneys();
|
||||
console.log('\n=== Example 6: A/B Test Results ===');
|
||||
await generateABTestResults();
|
||||
console.log('\n=== Example 7: Cohort Analysis ===');
|
||||
await generateCohortAnalysis();
|
||||
console.log('\n=== Example 8: Time-Series Campaign Data ===');
|
||||
await generateTimeSeriesCampaignData();
|
||||
console.log('\n=== Example 10: Multi-Platform Batch ===');
|
||||
await generateMultiPlatformBatch();
|
||||
}
|
||||
// Uncomment to run
|
||||
// runCampaignDataExamples().catch(console.error);
|
||||
//# sourceMappingURL=campaign-data.js.map
|
||||
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
568
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.ts
vendored
Normal file
568
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/campaign-data.ts
vendored
Normal file
@@ -0,0 +1,568 @@
|
||||
/**
|
||||
* Ad Campaign Performance Data Generation
|
||||
*
|
||||
* Generates realistic ad campaign data including:
|
||||
* - Campaign metrics (impressions, clicks, conversions, spend)
|
||||
* - Multi-channel attribution data
|
||||
* - Customer journey tracking
|
||||
* - A/B test results
|
||||
* - Cohort analysis data
|
||||
*/
|
||||
|
||||
import { AgenticSynth, createSynth } from '../../src/index.js';
|
||||
|
||||
// Example 1: Google Ads campaign metrics
|
||||
async function generateGoogleAdsCampaign() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
|
||||
const campaignSchema = {
|
||||
campaignId: { type: 'string', required: true },
|
||||
campaignName: { type: 'string', required: true },
|
||||
date: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
adGroup: { type: 'string', required: true },
|
||||
keyword: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
cost: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
ctr: { type: 'number', required: true },
|
||||
cpc: { type: 'number', required: true },
|
||||
cpa: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true },
|
||||
qualityScore: { type: 'number', required: true },
|
||||
avgPosition: { type: 'number', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 100,
|
||||
schema: campaignSchema,
|
||||
constraints: {
|
||||
platform: 'Google Ads',
|
||||
impressions: { min: 1000, max: 100000 },
|
||||
ctr: { min: 0.01, max: 0.15 },
|
||||
cpc: { min: 0.50, max: 10.00 },
|
||||
roas: { min: 0.5, max: 8.0 },
|
||||
qualityScore: { min: 1, max: 10 },
|
||||
avgPosition: { min: 1.0, max: 5.0 }
|
||||
},
|
||||
format: 'json'
|
||||
});
|
||||
|
||||
console.log('Google Ads Campaign Data:');
|
||||
console.log(result.data.slice(0, 3));
|
||||
console.log('Metadata:', result.metadata);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 2: Facebook/Meta Ads campaign performance
|
||||
async function generateFacebookAdsCampaign() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const facebookSchema = {
|
||||
adSetId: { type: 'string', required: true },
|
||||
adSetName: { type: 'string', required: true },
|
||||
adId: { type: 'string', required: true },
|
||||
adName: { type: 'string', required: true },
|
||||
date: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
objective: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
reach: { type: 'number', required: true },
|
||||
frequency: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
linkClicks: { type: 'number', required: true },
|
||||
ctr: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
purchases: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
cpc: { type: 'number', required: true },
|
||||
cpm: { type: 'number', required: true },
|
||||
costPerPurchase: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true },
|
||||
addToCarts: { type: 'number', required: true },
|
||||
initiateCheckout: { type: 'number', required: true },
|
||||
relevanceScore: { type: 'number', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 150,
|
||||
schema: facebookSchema,
|
||||
constraints: {
|
||||
platform: 'Facebook Ads',
|
||||
objective: ['conversions', 'traffic', 'brand_awareness', 'video_views'],
|
||||
impressions: { min: 5000, max: 500000 },
|
||||
frequency: { min: 1.0, max: 5.0 },
|
||||
cpm: { min: 5.00, max: 50.00 },
|
||||
roas: { min: 0.8, max: 6.0 },
|
||||
relevanceScore: { min: 1, max: 10 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Facebook Ads Campaign Data:');
|
||||
console.log(result.data.slice(0, 3));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 3: TikTok Ads campaign performance
|
||||
async function generateTikTokAdsCampaign() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const tiktokSchema = {
|
||||
campaignId: { type: 'string', required: true },
|
||||
campaignName: { type: 'string', required: true },
|
||||
adGroupId: { type: 'string', required: true },
|
||||
adId: { type: 'string', required: true },
|
||||
date: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
objective: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
videoViews: { type: 'number', required: true },
|
||||
videoWatchTime: { type: 'number', required: true },
|
||||
videoCompletionRate: { type: 'number', required: true },
|
||||
engagement: { type: 'number', required: true },
|
||||
shares: { type: 'number', required: true },
|
||||
comments: { type: 'number', required: true },
|
||||
likes: { type: 'number', required: true },
|
||||
follows: { type: 'number', required: true },
|
||||
ctr: { type: 'number', required: true },
|
||||
cpc: { type: 'number', required: true },
|
||||
cpm: { type: 'number', required: true },
|
||||
cpa: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 120,
|
||||
schema: tiktokSchema,
|
||||
constraints: {
|
||||
platform: 'TikTok Ads',
|
||||
objective: ['app_promotion', 'conversions', 'traffic', 'video_views'],
|
||||
impressions: { min: 10000, max: 1000000 },
|
||||
videoCompletionRate: { min: 0.1, max: 0.8 },
|
||||
cpm: { min: 3.00, max: 30.00 },
|
||||
roas: { min: 0.6, max: 7.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('TikTok Ads Campaign Data:');
|
||||
console.log(result.data.slice(0, 3));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 4: Multi-channel attribution data
|
||||
async function generateAttributionData() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const attributionSchema = {
|
||||
userId: { type: 'string', required: true },
|
||||
conversionId: { type: 'string', required: true },
|
||||
conversionDate: { type: 'string', required: true },
|
||||
conversionValue: { type: 'number', required: true },
|
||||
touchpoints: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
campaign: { type: 'string' },
|
||||
timestamp: { type: 'string' },
|
||||
touchpointPosition: { type: 'number' },
|
||||
attributionWeight: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
attributionModel: { type: 'string', required: true },
|
||||
firstTouch: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
value: { type: 'number' }
|
||||
}
|
||||
},
|
||||
lastTouch: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
channel: { type: 'string' },
|
||||
value: { type: 'number' }
|
||||
}
|
||||
},
|
||||
linearAttribution: { type: 'object', required: false },
|
||||
timeDecayAttribution: { type: 'object', required: false },
|
||||
positionBasedAttribution: { type: 'object', required: false }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 80,
|
||||
schema: attributionSchema,
|
||||
constraints: {
|
||||
attributionModel: ['first_touch', 'last_touch', 'linear', 'time_decay', 'position_based'],
|
||||
touchpoints: { minLength: 2, maxLength: 8 },
|
||||
conversionValue: { min: 10, max: 5000 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Multi-Channel Attribution Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 5: Customer journey tracking
|
||||
async function generateCustomerJourneys() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const journeySchema = {
|
||||
journeyId: { type: 'string', required: true },
|
||||
userId: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
journeyLength: { type: 'number', required: true },
|
||||
touchpointCount: { type: 'number', required: true },
|
||||
events: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
timestamp: { type: 'string' },
|
||||
eventType: { type: 'string' },
|
||||
channel: { type: 'string' },
|
||||
campaign: { type: 'string' },
|
||||
device: { type: 'string' },
|
||||
location: { type: 'string' },
|
||||
pageUrl: { type: 'string' },
|
||||
duration: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
converted: { type: 'boolean', required: true },
|
||||
conversionValue: { type: 'number', required: false },
|
||||
conversionType: { type: 'string', required: false },
|
||||
totalAdSpend: { type: 'number', required: true },
|
||||
roi: { type: 'number', required: false }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 60,
|
||||
schema: journeySchema,
|
||||
constraints: {
|
||||
journeyLength: { min: 1, max: 30 },
|
||||
touchpointCount: { min: 1, max: 15 },
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'email', 'organic_search', 'direct'],
|
||||
device: ['mobile', 'desktop', 'tablet'],
|
||||
conversionType: ['purchase', 'signup', 'download', 'lead']
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Customer Journey Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 6: A/B test results
|
||||
async function generateABTestResults() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const abTestSchema = {
|
||||
testId: { type: 'string', required: true },
|
||||
testName: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
testType: { type: 'string', required: true },
|
||||
variants: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
variantId: { type: 'string' },
|
||||
variantName: { type: 'string' },
|
||||
trafficAllocation: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
winner: { type: 'string', required: false },
|
||||
confidenceLevel: { type: 'number', required: true },
|
||||
statistically_significant: { type: 'boolean', required: true },
|
||||
liftPercent: { type: 'number', required: false }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 40,
|
||||
schema: abTestSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
testType: ['creative', 'audience', 'bidding', 'landing_page', 'headline', 'cta'],
|
||||
variants: { minLength: 2, maxLength: 4 },
|
||||
confidenceLevel: { min: 0.5, max: 0.99 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('A/B Test Results:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 7: Cohort analysis data
|
||||
async function generateCohortAnalysis() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const cohortSchema = {
|
||||
cohortId: { type: 'string', required: true },
|
||||
cohortName: { type: 'string', required: true },
|
||||
acquisitionDate: { type: 'string', required: true },
|
||||
channel: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
initialUsers: { type: 'number', required: true },
|
||||
retentionData: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
period: { type: 'number' },
|
||||
activeUsers: { type: 'number' },
|
||||
retentionRate: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
avgOrderValue: { type: 'number' },
|
||||
purchaseFrequency: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
totalSpend: { type: 'number', required: true },
|
||||
totalRevenue: { type: 'number', required: true },
|
||||
ltv: { type: 'number', required: true },
|
||||
cac: { type: 'number', required: true },
|
||||
ltvCacRatio: { type: 'number', required: true },
|
||||
paybackPeriod: { type: 'number', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: cohortSchema,
|
||||
constraints: {
|
||||
channel: ['google_ads', 'facebook_ads', 'tiktok_ads', 'email', 'organic'],
|
||||
initialUsers: { min: 100, max: 10000 },
|
||||
retentionData: { minLength: 6, maxLength: 12 },
|
||||
ltvCacRatio: { min: 0.5, max: 10.0 },
|
||||
paybackPeriod: { min: 1, max: 24 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Cohort Analysis Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 8: Time-series campaign performance
|
||||
async function generateTimeSeriesCampaignData() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const result = await synth.generateTimeSeries({
|
||||
count: 90,
|
||||
startDate: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000),
|
||||
endDate: new Date(),
|
||||
interval: '1d',
|
||||
metrics: [
|
||||
'impressions',
|
||||
'clicks',
|
||||
'conversions',
|
||||
'spend',
|
||||
'revenue',
|
||||
'roas',
|
||||
'ctr',
|
||||
'cvr'
|
||||
],
|
||||
trend: 'up',
|
||||
seasonality: true,
|
||||
noise: 0.15,
|
||||
constraints: {
|
||||
impressions: { min: 10000, max: 100000 },
|
||||
clicks: { min: 100, max: 5000 },
|
||||
conversions: { min: 10, max: 500 },
|
||||
spend: { min: 100, max: 5000 },
|
||||
revenue: { min: 0, max: 25000 },
|
||||
roas: { min: 0.5, max: 8.0 },
|
||||
ctr: { min: 0.01, max: 0.1 },
|
||||
cvr: { min: 0.01, max: 0.15 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Time-Series Campaign Data:');
|
||||
console.log(result.data.slice(0, 7));
|
||||
console.log('Metadata:', result.metadata);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 9: Streaming real-time campaign data
|
||||
async function streamCampaignData() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini',
|
||||
streaming: true
|
||||
});
|
||||
|
||||
console.log('Streaming campaign data:');
|
||||
|
||||
let count = 0;
|
||||
for await (const dataPoint of synth.generateStream('structured', {
|
||||
count: 20,
|
||||
schema: {
|
||||
timestamp: { type: 'string', required: true },
|
||||
campaignId: { type: 'string', required: true },
|
||||
impressions: { type: 'number', required: true },
|
||||
clicks: { type: 'number', required: true },
|
||||
conversions: { type: 'number', required: true },
|
||||
spend: { type: 'number', required: true },
|
||||
revenue: { type: 'number', required: true },
|
||||
roas: { type: 'number', required: true }
|
||||
}
|
||||
})) {
|
||||
count++;
|
||||
console.log(`[${count}] Received:`, dataPoint);
|
||||
}
|
||||
}
|
||||
|
||||
// Example 10: Batch generation for multiple platforms
|
||||
async function generateMultiPlatformBatch() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const platformConfigs = [
|
||||
{
|
||||
count: 50,
|
||||
schema: {
|
||||
platform: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: { platform: 'Google Ads' }
|
||||
},
|
||||
{
|
||||
count: 50,
|
||||
schema: {
|
||||
platform: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: { platform: 'Facebook Ads' }
|
||||
},
|
||||
{
|
||||
count: 50,
|
||||
schema: {
|
||||
platform: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
},
|
||||
constraints: { platform: 'TikTok Ads' }
|
||||
}
|
||||
];
|
||||
|
||||
const results = await synth.generateBatch('structured', platformConfigs, 3);
|
||||
|
||||
console.log('Multi-Platform Batch Results:');
|
||||
results.forEach((result, i) => {
|
||||
const platforms = ['Google Ads', 'Facebook Ads', 'TikTok Ads'];
|
||||
console.log(`${platforms[i]}: ${result.metadata.count} records in ${result.metadata.duration}ms`);
|
||||
console.log('Sample:', result.data.slice(0, 2));
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
// Run all examples
|
||||
export async function runCampaignDataExamples() {
|
||||
console.log('=== Example 1: Google Ads Campaign ===');
|
||||
await generateGoogleAdsCampaign();
|
||||
|
||||
console.log('\n=== Example 2: Facebook Ads Campaign ===');
|
||||
await generateFacebookAdsCampaign();
|
||||
|
||||
console.log('\n=== Example 3: TikTok Ads Campaign ===');
|
||||
await generateTikTokAdsCampaign();
|
||||
|
||||
console.log('\n=== Example 4: Multi-Channel Attribution ===');
|
||||
await generateAttributionData();
|
||||
|
||||
console.log('\n=== Example 5: Customer Journeys ===');
|
||||
await generateCustomerJourneys();
|
||||
|
||||
console.log('\n=== Example 6: A/B Test Results ===');
|
||||
await generateABTestResults();
|
||||
|
||||
console.log('\n=== Example 7: Cohort Analysis ===');
|
||||
await generateCohortAnalysis();
|
||||
|
||||
console.log('\n=== Example 8: Time-Series Campaign Data ===');
|
||||
await generateTimeSeriesCampaignData();
|
||||
|
||||
console.log('\n=== Example 10: Multi-Platform Batch ===');
|
||||
await generateMultiPlatformBatch();
|
||||
}
|
||||
|
||||
// Export individual functions
|
||||
export {
|
||||
generateGoogleAdsCampaign,
|
||||
generateFacebookAdsCampaign,
|
||||
generateTikTokAdsCampaign,
|
||||
generateAttributionData,
|
||||
generateCustomerJourneys,
|
||||
generateABTestResults,
|
||||
generateCohortAnalysis,
|
||||
generateTimeSeriesCampaignData,
|
||||
streamCampaignData,
|
||||
generateMultiPlatformBatch
|
||||
};
|
||||
|
||||
// Uncomment to run
|
||||
// runCampaignDataExamples().catch(console.error);
|
||||
23
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.d.ts
vendored
Normal file
23
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Ad Optimization Simulator
|
||||
*
|
||||
* Generates optimization scenario data including:
|
||||
* - Budget allocation simulations
|
||||
* - Bid strategy testing data
|
||||
* - Audience segmentation data
|
||||
* - Creative performance variations
|
||||
* - ROAS optimization scenarios
|
||||
*/
|
||||
declare function simulateBudgetAllocation(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateBidStrategies(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateAudienceSegmentation(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateCreativePerformance(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateROASOptimization(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateOptimizationImpact(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateMultiVariateTesting(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateDaypartingOptimization(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateGeoTargetingOptimization(): Promise<import("../../src/types.js").GenerationResult<unknown>>;
|
||||
declare function simulateBatchOptimization(): Promise<import("../../src/types.js").GenerationResult<unknown>[]>;
|
||||
export declare function runOptimizationExamples(): Promise<void>;
|
||||
export { simulateBudgetAllocation, simulateBidStrategies, simulateAudienceSegmentation, simulateCreativePerformance, simulateROASOptimization, simulateOptimizationImpact, simulateMultiVariateTesting, simulateDaypartingOptimization, simulateGeoTargetingOptimization, simulateBatchOptimization };
|
||||
//# sourceMappingURL=optimization-simulator.d.ts.map
|
||||
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.d.ts.map
vendored
Normal file
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"optimization-simulator.d.ts","sourceRoot":"","sources":["optimization-simulator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,iBAAe,wBAAwB,oEA0EtC;AAGD,iBAAe,qBAAqB,oEA4EnC;AAGD,iBAAe,4BAA4B,oEA0E1C;AAGD,iBAAe,2BAA2B,oEAuEzC;AAGD,iBAAe,wBAAwB,oEA2EtC;AAGD,iBAAe,0BAA0B,oEAmCxC;AAGD,iBAAe,2BAA2B,oEA8DzC;AAGD,iBAAe,8BAA8B,oEAyD5C;AAGD,iBAAe,gCAAgC,oEA2D9C;AAGD,iBAAe,yBAAyB,sEAgDvC;AAGD,wBAAsB,uBAAuB,kBA8B5C;AAGD,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,4BAA4B,EAC5B,2BAA2B,EAC3B,wBAAwB,EACxB,0BAA0B,EAC1B,2BAA2B,EAC3B,8BAA8B,EAC9B,gCAAgC,EAChC,yBAAyB,EAC1B,CAAC"}
|
||||
662
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.js
vendored
Normal file
662
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.js
vendored
Normal file
@@ -0,0 +1,662 @@
|
||||
"use strict";
|
||||
/**
|
||||
* Ad Optimization Simulator
|
||||
*
|
||||
* Generates optimization scenario data including:
|
||||
* - Budget allocation simulations
|
||||
* - Bid strategy testing data
|
||||
* - Audience segmentation data
|
||||
* - Creative performance variations
|
||||
* - ROAS optimization scenarios
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runOptimizationExamples = runOptimizationExamples;
|
||||
exports.simulateBudgetAllocation = simulateBudgetAllocation;
|
||||
exports.simulateBidStrategies = simulateBidStrategies;
|
||||
exports.simulateAudienceSegmentation = simulateAudienceSegmentation;
|
||||
exports.simulateCreativePerformance = simulateCreativePerformance;
|
||||
exports.simulateROASOptimization = simulateROASOptimization;
|
||||
exports.simulateOptimizationImpact = simulateOptimizationImpact;
|
||||
exports.simulateMultiVariateTesting = simulateMultiVariateTesting;
|
||||
exports.simulateDaypartingOptimization = simulateDaypartingOptimization;
|
||||
exports.simulateGeoTargetingOptimization = simulateGeoTargetingOptimization;
|
||||
exports.simulateBatchOptimization = simulateBatchOptimization;
|
||||
const index_js_1 = require("../../src/index.js");
|
||||
// Example 1: Budget allocation simulation
|
||||
async function simulateBudgetAllocation() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
const budgetSchema = {
|
||||
scenarioId: { type: 'string', required: true },
|
||||
scenarioName: { type: 'string', required: true },
|
||||
totalBudget: { type: 'number', required: true },
|
||||
timeframe: { type: 'string', required: true },
|
||||
allocation: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
googleAds: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
budget: { type: 'number' },
|
||||
percentage: { type: 'number' },
|
||||
expectedImpressions: { type: 'number' },
|
||||
expectedClicks: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedROAS: { type: 'number' }
|
||||
}
|
||||
},
|
||||
facebookAds: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
budget: { type: 'number' },
|
||||
percentage: { type: 'number' },
|
||||
expectedImpressions: { type: 'number' },
|
||||
expectedClicks: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedROAS: { type: 'number' }
|
||||
}
|
||||
},
|
||||
tiktokAds: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
budget: { type: 'number' },
|
||||
percentage: { type: 'number' },
|
||||
expectedImpressions: { type: 'number' },
|
||||
expectedClicks: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedROAS: { type: 'number' }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
projectedROAS: { type: 'number', required: true },
|
||||
projectedRevenue: { type: 'number', required: true },
|
||||
riskScore: { type: 'number', required: true },
|
||||
confidenceInterval: { type: 'object', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 50,
|
||||
schema: budgetSchema,
|
||||
constraints: {
|
||||
totalBudget: { min: 10000, max: 500000 },
|
||||
timeframe: ['daily', 'weekly', 'monthly', 'quarterly'],
|
||||
projectedROAS: { min: 1.0, max: 10.0 },
|
||||
riskScore: { min: 0.1, max: 0.9 }
|
||||
}
|
||||
});
|
||||
console.log('Budget Allocation Simulations:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 2: Bid strategy testing
|
||||
async function simulateBidStrategies() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const bidStrategySchema = {
|
||||
strategyId: { type: 'string', required: true },
|
||||
strategyName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
strategyType: { type: 'string', required: true },
|
||||
configuration: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
targetCPA: { type: 'number' },
|
||||
targetROAS: { type: 'number' },
|
||||
maxCPC: { type: 'number' },
|
||||
bidAdjustments: { type: 'object' }
|
||||
}
|
||||
},
|
||||
historicalPerformance: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
avgCPC: { type: 'number' },
|
||||
avgCPA: { type: 'number' },
|
||||
avgROAS: { type: 'number' },
|
||||
conversionRate: { type: 'number' },
|
||||
impressionShare: { type: 'number' }
|
||||
}
|
||||
},
|
||||
simulatedResults: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
scenario: { type: 'string' },
|
||||
budget: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
cost: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
cpc: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendedBid: { type: 'number', required: true },
|
||||
expectedImprovement: { type: 'number', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 40,
|
||||
schema: bidStrategySchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
strategyType: [
|
||||
'manual_cpc',
|
||||
'enhanced_cpc',
|
||||
'target_cpa',
|
||||
'target_roas',
|
||||
'maximize_conversions',
|
||||
'maximize_conversion_value'
|
||||
],
|
||||
simulatedResults: { minLength: 3, maxLength: 5 },
|
||||
expectedImprovement: { min: -0.2, max: 0.5 }
|
||||
}
|
||||
});
|
||||
console.log('Bid Strategy Simulations:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 3: Audience segmentation testing
|
||||
async function simulateAudienceSegmentation() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const audienceSchema = {
|
||||
segmentId: { type: 'string', required: true },
|
||||
segmentName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
segmentType: { type: 'string', required: true },
|
||||
demographics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
ageRange: { type: 'string' },
|
||||
gender: { type: 'string' },
|
||||
location: { type: 'array' },
|
||||
income: { type: 'string' },
|
||||
education: { type: 'string' }
|
||||
}
|
||||
},
|
||||
interests: { type: 'array', required: true },
|
||||
behaviors: { type: 'array', required: true },
|
||||
size: { type: 'number', required: true },
|
||||
performance: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
ltv: { type: 'number' }
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
recommendedBudget: { type: 'number' },
|
||||
recommendedBid: { type: 'number' },
|
||||
expectedROAS: { type: 'number' },
|
||||
scalingPotential: { type: 'string' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 60,
|
||||
schema: audienceSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
segmentType: [
|
||||
'lookalike',
|
||||
'custom',
|
||||
'remarketing',
|
||||
'interest_based',
|
||||
'behavioral',
|
||||
'demographic'
|
||||
],
|
||||
size: { min: 10000, max: 10000000 },
|
||||
scalingPotential: ['low', 'medium', 'high']
|
||||
}
|
||||
});
|
||||
console.log('Audience Segmentation Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 4: Creative performance variations
|
||||
async function simulateCreativePerformance() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const creativeSchema = {
|
||||
creativeId: { type: 'string', required: true },
|
||||
creativeName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
format: { type: 'string', required: true },
|
||||
elements: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
headline: { type: 'string' },
|
||||
description: { type: 'string' },
|
||||
cta: { type: 'string' },
|
||||
imageUrl: { type: 'string' },
|
||||
videoUrl: { type: 'string' },
|
||||
videoDuration: { type: 'number' }
|
||||
}
|
||||
},
|
||||
variations: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
variationId: { type: 'string' },
|
||||
variationName: { type: 'string' },
|
||||
changeDescription: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
engagementRate: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
bestPerforming: { type: 'string', required: true },
|
||||
performanceLift: { type: 'number', required: true },
|
||||
recommendation: { type: 'string', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 50,
|
||||
schema: creativeSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads', 'Instagram Ads'],
|
||||
format: [
|
||||
'image_ad',
|
||||
'video_ad',
|
||||
'carousel_ad',
|
||||
'collection_ad',
|
||||
'story_ad',
|
||||
'responsive_display'
|
||||
],
|
||||
variations: { minLength: 2, maxLength: 5 },
|
||||
performanceLift: { min: -0.3, max: 2.0 }
|
||||
}
|
||||
});
|
||||
console.log('Creative Performance Variations:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 5: ROAS optimization scenarios
|
||||
async function simulateROASOptimization() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const roasSchema = {
|
||||
optimizationId: { type: 'string', required: true },
|
||||
optimizationName: { type: 'string', required: true },
|
||||
currentState: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
totalSpend: { type: 'number' },
|
||||
totalRevenue: { type: 'number' },
|
||||
currentROAS: { type: 'number' },
|
||||
campaignCount: { type: 'number' },
|
||||
activeChannels: { type: 'array' }
|
||||
}
|
||||
},
|
||||
optimizationScenarios: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
scenarioId: { type: 'string' },
|
||||
scenarioName: { type: 'string' },
|
||||
changes: { type: 'array' },
|
||||
projectedSpend: { type: 'number' },
|
||||
projectedRevenue: { type: 'number' },
|
||||
projectedROAS: { type: 'number' },
|
||||
roasImprovement: { type: 'number' },
|
||||
implementationDifficulty: { type: 'string' },
|
||||
estimatedTimeframe: { type: 'string' },
|
||||
riskLevel: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
primaryRecommendation: { type: 'string' },
|
||||
quickWins: { type: 'array' },
|
||||
longTermStrategies: { type: 'array' },
|
||||
budgetReallocation: { type: 'object' }
|
||||
}
|
||||
},
|
||||
expectedOutcome: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
targetROAS: { type: 'number' },
|
||||
targetRevenue: { type: 'number' },
|
||||
timeToTarget: { type: 'string' },
|
||||
confidenceLevel: { type: 'number' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: roasSchema,
|
||||
constraints: {
|
||||
'currentState.currentROAS': { min: 0.5, max: 5.0 },
|
||||
optimizationScenarios: { minLength: 3, maxLength: 6 },
|
||||
'expectedOutcome.targetROAS': { min: 2.0, max: 10.0 },
|
||||
'expectedOutcome.confidenceLevel': { min: 0.6, max: 0.95 }
|
||||
}
|
||||
});
|
||||
console.log('ROAS Optimization Scenarios:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 6: Time-series optimization impact
|
||||
async function simulateOptimizationImpact() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const result = await synth.generateTimeSeries({
|
||||
count: 90,
|
||||
startDate: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000),
|
||||
endDate: new Date(),
|
||||
interval: '1d',
|
||||
metrics: [
|
||||
'baseline_roas',
|
||||
'optimized_roas',
|
||||
'baseline_revenue',
|
||||
'optimized_revenue',
|
||||
'baseline_cpa',
|
||||
'optimized_cpa',
|
||||
'improvement_percentage'
|
||||
],
|
||||
trend: 'up',
|
||||
seasonality: true,
|
||||
noise: 0.1,
|
||||
constraints: {
|
||||
baseline_roas: { min: 2.0, max: 4.0 },
|
||||
optimized_roas: { min: 2.5, max: 8.0 },
|
||||
baseline_revenue: { min: 5000, max: 50000 },
|
||||
optimized_revenue: { min: 6000, max: 80000 },
|
||||
improvement_percentage: { min: 0, max: 100 }
|
||||
}
|
||||
});
|
||||
console.log('Optimization Impact Time-Series:');
|
||||
console.log(result.data.slice(0, 7));
|
||||
return result;
|
||||
}
|
||||
// Example 7: Multi-variate testing simulation
|
||||
async function simulateMultiVariateTesting() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const mvtSchema = {
|
||||
testId: { type: 'string', required: true },
|
||||
testName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
testFactors: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
factor: { type: 'string' },
|
||||
variations: { type: 'array' }
|
||||
}
|
||||
}
|
||||
},
|
||||
combinations: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
combinationId: { type: 'string' },
|
||||
factors: { type: 'object' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
score: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
winningCombination: { type: 'string', required: true },
|
||||
keyInsights: { type: 'array', required: true },
|
||||
implementationPlan: { type: 'string', required: true }
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 25,
|
||||
schema: mvtSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
testFactors: { minLength: 2, maxLength: 4 },
|
||||
combinations: { minLength: 4, maxLength: 16 }
|
||||
}
|
||||
});
|
||||
console.log('Multi-Variate Testing Results:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
return result;
|
||||
}
|
||||
// Example 8: Dayparting optimization
|
||||
async function simulateDaypartingOptimization() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const daypartingSchema = {
|
||||
analysisId: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
timezone: { type: 'string', required: true },
|
||||
hourlyPerformance: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
hour: { type: 'number' },
|
||||
dayOfWeek: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
competitionLevel: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
peakHours: { type: 'array' },
|
||||
bidAdjustments: { type: 'object' },
|
||||
budgetAllocation: { type: 'object' },
|
||||
expectedImprovement: { type: 'number' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 20,
|
||||
schema: daypartingSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
hourlyPerformance: { minLength: 168, maxLength: 168 }, // 24 hours x 7 days
|
||||
'recommendations.expectedImprovement': { min: 0.05, max: 0.5 }
|
||||
}
|
||||
});
|
||||
console.log('Dayparting Optimization Data:');
|
||||
console.log(result.data.slice(0, 1));
|
||||
return result;
|
||||
}
|
||||
// Example 9: Geo-targeting optimization
|
||||
async function simulateGeoTargetingOptimization() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const geoSchema = {
|
||||
analysisId: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
locationPerformance: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
locationId: { type: 'string' },
|
||||
locationName: { type: 'string' },
|
||||
locationType: { type: 'string' },
|
||||
population: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
marketPotential: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
topPerformingLocations: { type: 'array' },
|
||||
underperformingLocations: { type: 'array' },
|
||||
expansionOpportunities: { type: 'array' },
|
||||
bidAdjustments: { type: 'object' },
|
||||
expectedROASImprovement: { type: 'number' }
|
||||
}
|
||||
}
|
||||
};
|
||||
const result = await synth.generateStructured({
|
||||
count: 15,
|
||||
schema: geoSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
locationPerformance: { minLength: 10, maxLength: 50 },
|
||||
'optimization.expectedROASImprovement': { min: 0.1, max: 1.0 }
|
||||
}
|
||||
});
|
||||
console.log('Geo-Targeting Optimization Data:');
|
||||
console.log(result.data.slice(0, 1));
|
||||
return result;
|
||||
}
|
||||
// Example 10: Batch optimization simulation
|
||||
async function simulateBatchOptimization() {
|
||||
const synth = (0, index_js_1.createSynth)({
|
||||
provider: 'gemini'
|
||||
});
|
||||
const scenarios = [
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
scenarioType: { type: 'string' },
|
||||
currentROAS: { type: 'number' },
|
||||
optimizedROAS: { type: 'number' },
|
||||
improvement: { type: 'number' }
|
||||
},
|
||||
constraints: { scenarioType: 'budget_allocation' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
scenarioType: { type: 'string' },
|
||||
currentROAS: { type: 'number' },
|
||||
optimizedROAS: { type: 'number' },
|
||||
improvement: { type: 'number' }
|
||||
},
|
||||
constraints: { scenarioType: 'bid_strategy' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
scenarioType: { type: 'string' },
|
||||
currentROAS: { type: 'number' },
|
||||
optimizedROAS: { type: 'number' },
|
||||
improvement: { type: 'number' }
|
||||
},
|
||||
constraints: { scenarioType: 'audience_targeting' }
|
||||
}
|
||||
];
|
||||
const results = await synth.generateBatch('structured', scenarios, 3);
|
||||
console.log('Batch Optimization Results:');
|
||||
results.forEach((result, i) => {
|
||||
const types = ['Budget Allocation', 'Bid Strategy', 'Audience Targeting'];
|
||||
console.log(`${types[i]}: ${result.metadata.count} scenarios in ${result.metadata.duration}ms`);
|
||||
console.log('Sample:', result.data.slice(0, 2));
|
||||
});
|
||||
return results;
|
||||
}
|
||||
// Run all examples
|
||||
async function runOptimizationExamples() {
|
||||
console.log('=== Example 1: Budget Allocation ===');
|
||||
await simulateBudgetAllocation();
|
||||
console.log('\n=== Example 2: Bid Strategies ===');
|
||||
await simulateBidStrategies();
|
||||
console.log('\n=== Example 3: Audience Segmentation ===');
|
||||
await simulateAudienceSegmentation();
|
||||
console.log('\n=== Example 4: Creative Performance ===');
|
||||
await simulateCreativePerformance();
|
||||
console.log('\n=== Example 5: ROAS Optimization ===');
|
||||
await simulateROASOptimization();
|
||||
console.log('\n=== Example 6: Optimization Impact ===');
|
||||
await simulateOptimizationImpact();
|
||||
console.log('\n=== Example 7: Multi-Variate Testing ===');
|
||||
await simulateMultiVariateTesting();
|
||||
console.log('\n=== Example 8: Dayparting Optimization ===');
|
||||
await simulateDaypartingOptimization();
|
||||
console.log('\n=== Example 9: Geo-Targeting Optimization ===');
|
||||
await simulateGeoTargetingOptimization();
|
||||
console.log('\n=== Example 10: Batch Optimization ===');
|
||||
await simulateBatchOptimization();
|
||||
}
|
||||
// Uncomment to run
|
||||
// runOptimizationExamples().catch(console.error);
|
||||
//# sourceMappingURL=optimization-simulator.js.map
|
||||
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.js.map
vendored
Normal file
1
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
723
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.ts
vendored
Normal file
723
vendor/ruvector/npm/packages/agentic-synth/examples/ad-roas/optimization-simulator.ts
vendored
Normal file
@@ -0,0 +1,723 @@
|
||||
/**
|
||||
* Ad Optimization Simulator
|
||||
*
|
||||
* Generates optimization scenario data including:
|
||||
* - Budget allocation simulations
|
||||
* - Bid strategy testing data
|
||||
* - Audience segmentation data
|
||||
* - Creative performance variations
|
||||
* - ROAS optimization scenarios
|
||||
*/
|
||||
|
||||
import { AgenticSynth, createSynth } from '../../src/index.js';
|
||||
|
||||
// Example 1: Budget allocation simulation
|
||||
async function simulateBudgetAllocation() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini',
|
||||
apiKey: process.env.GEMINI_API_KEY
|
||||
});
|
||||
|
||||
const budgetSchema = {
|
||||
scenarioId: { type: 'string', required: true },
|
||||
scenarioName: { type: 'string', required: true },
|
||||
totalBudget: { type: 'number', required: true },
|
||||
timeframe: { type: 'string', required: true },
|
||||
allocation: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
googleAds: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
budget: { type: 'number' },
|
||||
percentage: { type: 'number' },
|
||||
expectedImpressions: { type: 'number' },
|
||||
expectedClicks: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedROAS: { type: 'number' }
|
||||
}
|
||||
},
|
||||
facebookAds: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
budget: { type: 'number' },
|
||||
percentage: { type: 'number' },
|
||||
expectedImpressions: { type: 'number' },
|
||||
expectedClicks: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedROAS: { type: 'number' }
|
||||
}
|
||||
},
|
||||
tiktokAds: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
budget: { type: 'number' },
|
||||
percentage: { type: 'number' },
|
||||
expectedImpressions: { type: 'number' },
|
||||
expectedClicks: { type: 'number' },
|
||||
expectedConversions: { type: 'number' },
|
||||
expectedRevenue: { type: 'number' },
|
||||
expectedROAS: { type: 'number' }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
projectedROAS: { type: 'number', required: true },
|
||||
projectedRevenue: { type: 'number', required: true },
|
||||
riskScore: { type: 'number', required: true },
|
||||
confidenceInterval: { type: 'object', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 50,
|
||||
schema: budgetSchema,
|
||||
constraints: {
|
||||
totalBudget: { min: 10000, max: 500000 },
|
||||
timeframe: ['daily', 'weekly', 'monthly', 'quarterly'],
|
||||
projectedROAS: { min: 1.0, max: 10.0 },
|
||||
riskScore: { min: 0.1, max: 0.9 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Budget Allocation Simulations:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 2: Bid strategy testing
|
||||
async function simulateBidStrategies() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const bidStrategySchema = {
|
||||
strategyId: { type: 'string', required: true },
|
||||
strategyName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
strategyType: { type: 'string', required: true },
|
||||
configuration: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
targetCPA: { type: 'number' },
|
||||
targetROAS: { type: 'number' },
|
||||
maxCPC: { type: 'number' },
|
||||
bidAdjustments: { type: 'object' }
|
||||
}
|
||||
},
|
||||
historicalPerformance: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
avgCPC: { type: 'number' },
|
||||
avgCPA: { type: 'number' },
|
||||
avgROAS: { type: 'number' },
|
||||
conversionRate: { type: 'number' },
|
||||
impressionShare: { type: 'number' }
|
||||
}
|
||||
},
|
||||
simulatedResults: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
scenario: { type: 'string' },
|
||||
budget: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
cost: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
cpc: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendedBid: { type: 'number', required: true },
|
||||
expectedImprovement: { type: 'number', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 40,
|
||||
schema: bidStrategySchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
strategyType: [
|
||||
'manual_cpc',
|
||||
'enhanced_cpc',
|
||||
'target_cpa',
|
||||
'target_roas',
|
||||
'maximize_conversions',
|
||||
'maximize_conversion_value'
|
||||
],
|
||||
simulatedResults: { minLength: 3, maxLength: 5 },
|
||||
expectedImprovement: { min: -0.2, max: 0.5 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Bid Strategy Simulations:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 3: Audience segmentation testing
|
||||
async function simulateAudienceSegmentation() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const audienceSchema = {
|
||||
segmentId: { type: 'string', required: true },
|
||||
segmentName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
segmentType: { type: 'string', required: true },
|
||||
demographics: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
ageRange: { type: 'string' },
|
||||
gender: { type: 'string' },
|
||||
location: { type: 'array' },
|
||||
income: { type: 'string' },
|
||||
education: { type: 'string' }
|
||||
}
|
||||
},
|
||||
interests: { type: 'array', required: true },
|
||||
behaviors: { type: 'array', required: true },
|
||||
size: { type: 'number', required: true },
|
||||
performance: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
ltv: { type: 'number' }
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
recommendedBudget: { type: 'number' },
|
||||
recommendedBid: { type: 'number' },
|
||||
expectedROAS: { type: 'number' },
|
||||
scalingPotential: { type: 'string' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 60,
|
||||
schema: audienceSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
segmentType: [
|
||||
'lookalike',
|
||||
'custom',
|
||||
'remarketing',
|
||||
'interest_based',
|
||||
'behavioral',
|
||||
'demographic'
|
||||
],
|
||||
size: { min: 10000, max: 10000000 },
|
||||
scalingPotential: ['low', 'medium', 'high']
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Audience Segmentation Data:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 4: Creative performance variations
|
||||
async function simulateCreativePerformance() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const creativeSchema = {
|
||||
creativeId: { type: 'string', required: true },
|
||||
creativeName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
format: { type: 'string', required: true },
|
||||
elements: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
headline: { type: 'string' },
|
||||
description: { type: 'string' },
|
||||
cta: { type: 'string' },
|
||||
imageUrl: { type: 'string' },
|
||||
videoUrl: { type: 'string' },
|
||||
videoDuration: { type: 'number' }
|
||||
}
|
||||
},
|
||||
variations: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
variationId: { type: 'string' },
|
||||
variationName: { type: 'string' },
|
||||
changeDescription: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
engagementRate: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
bestPerforming: { type: 'string', required: true },
|
||||
performanceLift: { type: 'number', required: true },
|
||||
recommendation: { type: 'string', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 50,
|
||||
schema: creativeSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads', 'Instagram Ads'],
|
||||
format: [
|
||||
'image_ad',
|
||||
'video_ad',
|
||||
'carousel_ad',
|
||||
'collection_ad',
|
||||
'story_ad',
|
||||
'responsive_display'
|
||||
],
|
||||
variations: { minLength: 2, maxLength: 5 },
|
||||
performanceLift: { min: -0.3, max: 2.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Creative Performance Variations:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 5: ROAS optimization scenarios
|
||||
async function simulateROASOptimization() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const roasSchema = {
|
||||
optimizationId: { type: 'string', required: true },
|
||||
optimizationName: { type: 'string', required: true },
|
||||
currentState: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
totalSpend: { type: 'number' },
|
||||
totalRevenue: { type: 'number' },
|
||||
currentROAS: { type: 'number' },
|
||||
campaignCount: { type: 'number' },
|
||||
activeChannels: { type: 'array' }
|
||||
}
|
||||
},
|
||||
optimizationScenarios: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
scenarioId: { type: 'string' },
|
||||
scenarioName: { type: 'string' },
|
||||
changes: { type: 'array' },
|
||||
projectedSpend: { type: 'number' },
|
||||
projectedRevenue: { type: 'number' },
|
||||
projectedROAS: { type: 'number' },
|
||||
roasImprovement: { type: 'number' },
|
||||
implementationDifficulty: { type: 'string' },
|
||||
estimatedTimeframe: { type: 'string' },
|
||||
riskLevel: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
primaryRecommendation: { type: 'string' },
|
||||
quickWins: { type: 'array' },
|
||||
longTermStrategies: { type: 'array' },
|
||||
budgetReallocation: { type: 'object' }
|
||||
}
|
||||
},
|
||||
expectedOutcome: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
targetROAS: { type: 'number' },
|
||||
targetRevenue: { type: 'number' },
|
||||
timeToTarget: { type: 'string' },
|
||||
confidenceLevel: { type: 'number' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 30,
|
||||
schema: roasSchema,
|
||||
constraints: {
|
||||
'currentState.currentROAS': { min: 0.5, max: 5.0 },
|
||||
optimizationScenarios: { minLength: 3, maxLength: 6 },
|
||||
'expectedOutcome.targetROAS': { min: 2.0, max: 10.0 },
|
||||
'expectedOutcome.confidenceLevel': { min: 0.6, max: 0.95 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('ROAS Optimization Scenarios:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 6: Time-series optimization impact
|
||||
async function simulateOptimizationImpact() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const result = await synth.generateTimeSeries({
|
||||
count: 90,
|
||||
startDate: new Date(Date.now() - 90 * 24 * 60 * 60 * 1000),
|
||||
endDate: new Date(),
|
||||
interval: '1d',
|
||||
metrics: [
|
||||
'baseline_roas',
|
||||
'optimized_roas',
|
||||
'baseline_revenue',
|
||||
'optimized_revenue',
|
||||
'baseline_cpa',
|
||||
'optimized_cpa',
|
||||
'improvement_percentage'
|
||||
],
|
||||
trend: 'up',
|
||||
seasonality: true,
|
||||
noise: 0.1,
|
||||
constraints: {
|
||||
baseline_roas: { min: 2.0, max: 4.0 },
|
||||
optimized_roas: { min: 2.5, max: 8.0 },
|
||||
baseline_revenue: { min: 5000, max: 50000 },
|
||||
optimized_revenue: { min: 6000, max: 80000 },
|
||||
improvement_percentage: { min: 0, max: 100 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Optimization Impact Time-Series:');
|
||||
console.log(result.data.slice(0, 7));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 7: Multi-variate testing simulation
|
||||
async function simulateMultiVariateTesting() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const mvtSchema = {
|
||||
testId: { type: 'string', required: true },
|
||||
testName: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
startDate: { type: 'string', required: true },
|
||||
endDate: { type: 'string', required: true },
|
||||
testFactors: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
factor: { type: 'string' },
|
||||
variations: { type: 'array' }
|
||||
}
|
||||
}
|
||||
},
|
||||
combinations: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
combinationId: { type: 'string' },
|
||||
factors: { type: 'object' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
score: { type: 'number' }
|
||||
}
|
||||
}
|
||||
},
|
||||
winningCombination: { type: 'string', required: true },
|
||||
keyInsights: { type: 'array', required: true },
|
||||
implementationPlan: { type: 'string', required: true }
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 25,
|
||||
schema: mvtSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
testFactors: { minLength: 2, maxLength: 4 },
|
||||
combinations: { minLength: 4, maxLength: 16 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Multi-Variate Testing Results:');
|
||||
console.log(result.data.slice(0, 2));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 8: Dayparting optimization
|
||||
async function simulateDaypartingOptimization() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const daypartingSchema = {
|
||||
analysisId: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
timezone: { type: 'string', required: true },
|
||||
hourlyPerformance: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
hour: { type: 'number' },
|
||||
dayOfWeek: { type: 'string' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
competitionLevel: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
recommendations: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
peakHours: { type: 'array' },
|
||||
bidAdjustments: { type: 'object' },
|
||||
budgetAllocation: { type: 'object' },
|
||||
expectedImprovement: { type: 'number' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 20,
|
||||
schema: daypartingSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
hourlyPerformance: { minLength: 168, maxLength: 168 }, // 24 hours x 7 days
|
||||
'recommendations.expectedImprovement': { min: 0.05, max: 0.5 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Dayparting Optimization Data:');
|
||||
console.log(result.data.slice(0, 1));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 9: Geo-targeting optimization
|
||||
async function simulateGeoTargetingOptimization() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const geoSchema = {
|
||||
analysisId: { type: 'string', required: true },
|
||||
campaign: { type: 'string', required: true },
|
||||
platform: { type: 'string', required: true },
|
||||
locationPerformance: {
|
||||
type: 'array',
|
||||
required: true,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
locationId: { type: 'string' },
|
||||
locationName: { type: 'string' },
|
||||
locationType: { type: 'string' },
|
||||
population: { type: 'number' },
|
||||
impressions: { type: 'number' },
|
||||
clicks: { type: 'number' },
|
||||
conversions: { type: 'number' },
|
||||
spend: { type: 'number' },
|
||||
revenue: { type: 'number' },
|
||||
ctr: { type: 'number' },
|
||||
cvr: { type: 'number' },
|
||||
cpa: { type: 'number' },
|
||||
roas: { type: 'number' },
|
||||
marketPotential: { type: 'string' }
|
||||
}
|
||||
}
|
||||
},
|
||||
optimization: {
|
||||
type: 'object',
|
||||
required: true,
|
||||
properties: {
|
||||
topPerformingLocations: { type: 'array' },
|
||||
underperformingLocations: { type: 'array' },
|
||||
expansionOpportunities: { type: 'array' },
|
||||
bidAdjustments: { type: 'object' },
|
||||
expectedROASImprovement: { type: 'number' }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await synth.generateStructured({
|
||||
count: 15,
|
||||
schema: geoSchema,
|
||||
constraints: {
|
||||
platform: ['Google Ads', 'Facebook Ads', 'TikTok Ads'],
|
||||
locationPerformance: { minLength: 10, maxLength: 50 },
|
||||
'optimization.expectedROASImprovement': { min: 0.1, max: 1.0 }
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Geo-Targeting Optimization Data:');
|
||||
console.log(result.data.slice(0, 1));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Example 10: Batch optimization simulation
|
||||
async function simulateBatchOptimization() {
|
||||
const synth = createSynth({
|
||||
provider: 'gemini'
|
||||
});
|
||||
|
||||
const scenarios = [
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
scenarioType: { type: 'string' },
|
||||
currentROAS: { type: 'number' },
|
||||
optimizedROAS: { type: 'number' },
|
||||
improvement: { type: 'number' }
|
||||
},
|
||||
constraints: { scenarioType: 'budget_allocation' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
scenarioType: { type: 'string' },
|
||||
currentROAS: { type: 'number' },
|
||||
optimizedROAS: { type: 'number' },
|
||||
improvement: { type: 'number' }
|
||||
},
|
||||
constraints: { scenarioType: 'bid_strategy' }
|
||||
},
|
||||
{
|
||||
count: 20,
|
||||
schema: {
|
||||
scenarioType: { type: 'string' },
|
||||
currentROAS: { type: 'number' },
|
||||
optimizedROAS: { type: 'number' },
|
||||
improvement: { type: 'number' }
|
||||
},
|
||||
constraints: { scenarioType: 'audience_targeting' }
|
||||
}
|
||||
];
|
||||
|
||||
const results = await synth.generateBatch('structured', scenarios, 3);
|
||||
|
||||
console.log('Batch Optimization Results:');
|
||||
results.forEach((result, i) => {
|
||||
const types = ['Budget Allocation', 'Bid Strategy', 'Audience Targeting'];
|
||||
console.log(`${types[i]}: ${result.metadata.count} scenarios in ${result.metadata.duration}ms`);
|
||||
console.log('Sample:', result.data.slice(0, 2));
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
// Run all examples
|
||||
export async function runOptimizationExamples() {
|
||||
console.log('=== Example 1: Budget Allocation ===');
|
||||
await simulateBudgetAllocation();
|
||||
|
||||
console.log('\n=== Example 2: Bid Strategies ===');
|
||||
await simulateBidStrategies();
|
||||
|
||||
console.log('\n=== Example 3: Audience Segmentation ===');
|
||||
await simulateAudienceSegmentation();
|
||||
|
||||
console.log('\n=== Example 4: Creative Performance ===');
|
||||
await simulateCreativePerformance();
|
||||
|
||||
console.log('\n=== Example 5: ROAS Optimization ===');
|
||||
await simulateROASOptimization();
|
||||
|
||||
console.log('\n=== Example 6: Optimization Impact ===');
|
||||
await simulateOptimizationImpact();
|
||||
|
||||
console.log('\n=== Example 7: Multi-Variate Testing ===');
|
||||
await simulateMultiVariateTesting();
|
||||
|
||||
console.log('\n=== Example 8: Dayparting Optimization ===');
|
||||
await simulateDaypartingOptimization();
|
||||
|
||||
console.log('\n=== Example 9: Geo-Targeting Optimization ===');
|
||||
await simulateGeoTargetingOptimization();
|
||||
|
||||
console.log('\n=== Example 10: Batch Optimization ===');
|
||||
await simulateBatchOptimization();
|
||||
}
|
||||
|
||||
// Export individual functions
|
||||
export {
|
||||
simulateBudgetAllocation,
|
||||
simulateBidStrategies,
|
||||
simulateAudienceSegmentation,
|
||||
simulateCreativePerformance,
|
||||
simulateROASOptimization,
|
||||
simulateOptimizationImpact,
|
||||
simulateMultiVariateTesting,
|
||||
simulateDaypartingOptimization,
|
||||
simulateGeoTargetingOptimization,
|
||||
simulateBatchOptimization
|
||||
};
|
||||
|
||||
// Uncomment to run
|
||||
// runOptimizationExamples().catch(console.error);
|
||||
Reference in New Issue
Block a user