-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulate_visit.js
More file actions
65 lines (51 loc) · 2.28 KB
/
simulate_visit.js
File metadata and controls
65 lines (51 loc) · 2.28 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
const { createClient } = require('@supabase/supabase-js');
require('dotenv').config();
const SUPABASE_URL = 'https://rmtyebyzitzgkplxvzxg.supabase.co';
const SUPABASE_KEY = 'sb_publishable_2qDg3Jssg_fTPdXl_3Ku-g_1yOkdJ3i';
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);
// Use a known valid scout ID from admin.html debug output or previous context
// For now, I'll fetch one first
const fs = require('fs');
async function simulateVisit() {
const log = [];
const logFile = 'simulation_log.json';
try {
log.push({ step: 'init', message: 'Starting simulation...' });
// Test 1: Organic Visit (No Scout ID)
log.push({ step: 'test_1', message: 'Inserting with scout_id: null' });
const { error: err1 } = await supabase.from('tracking_events').insert({
event_type: 'page_view',
meta_data: { source: 'test_organic' }
});
if (err1) {
log.push({ step: 'test_1_result', status: 'failed', error: err1 });
} else {
log.push({ step: 'test_1_result', status: 'success' });
}
// Test 2: Scout Visit
log.push({ step: 'test_2', message: 'Fetching valid scout ID...' });
const { data: scouts } = await supabase.from('scouts').select('id').limit(1);
if (scouts && scouts.length > 0) {
const scoutId = scouts[0].id;
log.push({ step: 'test_2_insert', message: `Inserting with scout_id: ${scoutId}` });
const { error: err2 } = await supabase.from('tracking_events').insert({
scout_id: scoutId,
event_type: 'page_view',
meta_data: { source: 'test_scout' }
});
if (err2) {
log.push({ step: 'test_2_result', status: 'failed', error: err2 });
} else {
log.push({ step: 'test_2_result', status: 'success' });
}
} else {
log.push({ step: 'test_2_aborted', message: 'No scouts found' });
}
} catch (e) {
log.push({ step: 'fatal_error', error: e.message });
} finally {
fs.writeFileSync(logFile, JSON.stringify(log, null, 2));
console.log('Simulation complete. Log written to ' + logFile);
}
}
simulateVisit();