-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-start.js
More file actions
79 lines (66 loc) · 2.5 KB
/
quick-start.js
File metadata and controls
79 lines (66 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Trillboards Partner API - Node.js Quick Start
*
* This example demonstrates the 3-step integration:
* 1. Get VAST configuration (cache for 1 hour)
* 2. Fetch VAST from Google Ad Manager (Trillboards not in critical path)
* 3. Report impressions after ad completion
*
* Usage:
* TRILLBOARDS_API_KEY=trb_partner_xxx node quick-start.js
*/
const TRILLBOARDS_API = process.env.TRILLBOARDS_API_URL || 'https://api.trillboards.com';
const API_KEY = process.env.TRILLBOARDS_API_KEY;
if (!API_KEY) {
console.error('Error: Set TRILLBOARDS_API_KEY environment variable');
process.exit(1);
}
const headers = {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
};
async function main() {
try {
// Step 1: Get VAST configuration (cache this for 1 hour)
console.log('1. Fetching VAST configuration...');
const configResponse = await fetch(`${TRILLBOARDS_API}/v1/partner/vast/config`, {
headers
});
const config = await configResponse.json();
if (!config.success) {
throw new Error(`Config failed: ${config.message}`);
}
console.log(' VAST tag URL:', config.data.vast_tag_template);
console.log(' Fill rate:', config.data.estimated_fill_rate);
// Step 2: In production, your player fetches VAST directly from Google
// This keeps Trillboards out of the critical ad serving path
const vastUrl = config.data.vast_tag_template
.replace('[DEVICE_ID]', 'demo-device-001')
.replace('[TIMESTAMP]', Date.now());
console.log('\n2. Your player would fetch VAST from:', vastUrl);
console.log(' (Google IMA SDK handles this automatically)');
// Step 3: After ad completes, report the impression
console.log('\n3. Reporting impression after ad completion...');
const trackingResponse = await fetch(`${TRILLBOARDS_API}/v1/partner/tracking/batch`, {
method: 'POST',
headers,
body: JSON.stringify({
impressions: [{
device_id: 'demo-device-001',
ad_id: 'ima_demo_ad_123',
event: 'complete',
timestamp: new Date().toISOString(),
duration_ms: 15000
}]
})
});
const result = await trackingResponse.json();
console.log(' Processed:', result.data?.processed || 0);
console.log(' Proofs:', result.data?.proofs?.length || 0, 'Ed25519 signatures');
console.log('\nIntegration complete! Your screens are now monetized.');
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
}
main();