-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle-apps-script.js
More file actions
181 lines (155 loc) · 5.05 KB
/
google-apps-script.js
File metadata and controls
181 lines (155 loc) · 5.05 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Google Apps Script for MCP Audit Analytics
// Spreadsheet: https://docs.google.com/spreadsheets/d/14az_9cLskCROPs1NvF01nlP5WZaeEsdUDdyhPXsut_U
//
// This script receives analytics events from the MCP Audit web app
// and logs them to separate sheets based on event type.
//
// HOW TO UPDATE:
// 1. Go to https://script.google.com
// 2. Open the project linked to your spreadsheet
// 3. Replace the code with this file's contents
// 4. Click Deploy → Manage deployments → Edit (pencil icon)
// 5. Select "New version" and click Deploy
function doGet(e) {
try {
const params = e.parameter;
const event = params.event || 'unknown';
const timestamp = new Date().toISOString();
const ss = SpreadsheetApp.getActiveSpreadsheet();
// Route to appropriate sheet based on event type
if (event === 'cli_download') {
logCliDownload(ss, timestamp, params);
} else if (event === 'scan_completed') {
logScanCompleted(ss, timestamp, params);
} else if (event === 'scan_started') {
logScanStarted(ss, timestamp, params);
} else if (event === 'scan_error') {
logScanError(ss, timestamp, params);
} else if (event === 'export') {
logExport(ss, timestamp, params);
} else if (event === 'report_sent') {
logReportSent(ss, timestamp, params);
} else {
logGeneralEvent(ss, timestamp, params);
}
return ContentService.createTextOutput('OK');
} catch (error) {
return ContentService.createTextOutput('Error: ' + error.message);
}
}
// ============ CLI Downloads ============
function logCliDownload(ss, timestamp, params) {
let sheet = ss.getSheetByName('CLI Downloads');
// Create sheet if it doesn't exist
if (!sheet) {
sheet = ss.insertSheet('CLI Downloads');
sheet.appendRow(['Timestamp', 'Event', 'Source']);
// Format header row
sheet.getRange(1, 1, 1, 3).setFontWeight('bold');
}
sheet.appendRow([
timestamp,
params.event,
params.source || ''
]);
}
// ============ Scan Events ============
function logScanCompleted(ss, timestamp, params) {
let sheet = ss.getSheetByName('Scans');
if (!sheet) {
sheet = ss.insertSheet('Scans');
sheet.appendRow(['Timestamp', 'Status', 'Source', 'Org/User', 'MCPs Found', 'Known MCPs', 'Unknown MCPs']);
sheet.getRange(1, 1, 1, 7).setFontWeight('bold');
}
sheet.appendRow([
timestamp,
'completed',
params.source || '',
params.org_name || '',
parseInt(params.mcps_found) || 0,
parseInt(params.known_mcps) || 0,
parseInt(params.unknown_mcps) || 0
]);
}
function logScanStarted(ss, timestamp, params) {
let sheet = ss.getSheetByName('Scans');
if (!sheet) {
sheet = ss.insertSheet('Scans');
sheet.appendRow(['Timestamp', 'Status', 'Source', 'Org/User', 'MCPs Found', 'Known MCPs', 'Unknown MCPs']);
sheet.getRange(1, 1, 1, 7).setFontWeight('bold');
}
sheet.appendRow([
timestamp,
'started',
params.source || '',
params.org_name || '',
'', '', ''
]);
}
function logScanError(ss, timestamp, params) {
let sheet = ss.getSheetByName('Scans');
if (!sheet) {
sheet = ss.insertSheet('Scans');
sheet.appendRow(['Timestamp', 'Status', 'Source', 'Org/User', 'MCPs Found', 'Known MCPs', 'Unknown MCPs']);
sheet.getRange(1, 1, 1, 7).setFontWeight('bold');
}
sheet.appendRow([
timestamp,
'error',
params.source || '',
params.org_name || '',
'', '', ''
]);
}
// ============ Exports ============
function logExport(ss, timestamp, params) {
let sheet = ss.getSheetByName('Exports');
if (!sheet) {
sheet = ss.insertSheet('Exports');
sheet.appendRow(['Timestamp', 'Format', 'MCPs Count']);
sheet.getRange(1, 1, 1, 3).setFontWeight('bold');
}
sheet.appendRow([
timestamp,
params.export_format || '',
parseInt(params.mcps_found) || 0
]);
}
// ============ Email Reports (Lead Capture) ============
function logReportSent(ss, timestamp, params) {
let sheet = ss.getSheetByName('Email Reports');
if (!sheet) {
sheet = ss.insertSheet('Email Reports');
sheet.appendRow(['Timestamp', 'Email', 'Source', 'Scan Type', 'MCPs', 'Secrets', 'APIs', 'Models']);
sheet.getRange(1, 1, 1, 8).setFontWeight('bold');
}
sheet.appendRow([
timestamp,
params.email || '',
params.source || '',
params.scan_type || '',
parseInt(params.mcps) || 0,
parseInt(params.secrets) || 0,
parseInt(params.apis) || 0,
parseInt(params.models) || 0
]);
}
// ============ General Events (page views, tab clicks, etc.) ============
function logGeneralEvent(ss, timestamp, params) {
let sheet = ss.getSheetByName('Events');
if (!sheet) {
sheet = ss.insertSheet('Events');
sheet.appendRow(['Timestamp', 'Event', 'Source', 'Details']);
sheet.getRange(1, 1, 1, 4).setFontWeight('bold');
}
// Remove event from params to avoid duplication in details
const detailParams = {...params};
delete detailParams.event;
const details = Object.keys(detailParams).length > 0 ? JSON.stringify(detailParams) : '';
sheet.appendRow([
timestamp,
params.event,
params.source || '',
details
]);
}