Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
87 lines (77 loc) · 2 KB
/
Copy pathindex.html
File metadata and controls
87 lines (77 loc) · 2 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>iframe app</title>
<style>
body {
font-family: sans-serif;
display: flex;
flex-direction: column;
}
#config-display {
background-color: #f0f0f0;
border: 1px solid #ccc;
padding: 1rem;
font-family: monospace;
white-space: pre-wrap;
border-radius: 8px;
}
input[type='text'],
button {
border-radius: 8px;
padding: 0.5rem 1rem;
border: 1px solid #ccc;
}
#end-task {
align-self: flex-start;
}
.metric-sender {
display: flex;
gap: 0.5rem;
}
</style>
</head>
<body>
<h3>metrics</h3>
<div class="metric-sender">
<input type="text" id="metric-name" placeholder="name" />
<input type="text" id="metric-value" placeholder="value" />
<button id="send-metric">send Metric</button>
</div>
<h3>task control</h3>
<button id="end-task">end Task</button>
<h3>configuration</h3>
<pre id="config-display">Waiting for configuration...</pre>
<script>
const post = (message) => window.parent.postMessage(message, '*');
const byId = (id) => document.getElementById(id);
byId('end-task').addEventListener('click', () => post({ eventType: 'endTask' }));
byId('send-metric').addEventListener('click', () => {
const name = byId('metric-name').value;
const value = byId('metric-value').value;
if (!name || !value) {
return;
}
post({
eventType: 'metrics',
metricName: name,
metricValue: `${value}`,
adType: 'custom',
elementId: 'basket',
metricType: 'discrete',
});
byId('metric-name').value = '';
byId('metric-value').value = '';
});
window.addEventListener('message', (event) => {
if (event.data.eventType !== 'setConfiguration') {
return;
}
byId('config-display').textContent = JSON.stringify(event.data, null, 2);
});
post({ eventType: 'contentStart' });
</script>
</body>
</html>