-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
64 lines (57 loc) · 1.99 KB
/
index.js
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
var express = require('express')
var app = express()
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }))
var html = '<div class="field required">' +
'<form action="/" method="post">' +
'<label for="id_gabatch">Gabatch</label>' +
'<textarea name="gabatch" cols="40" rows="5"></textarea>' +
'<input type="submit" value="Submit">' +
'</form>' +
'</div>'
app.get('/', function (req, res) {
res.send(html)
})
app.post('/', function(req, res) {
var gaevents = req.body.gabatch
var processedGaEvents = processGAEvents(gaevents)
// console.log(gaevents)
res.send(processedGaEvents)
})
function processGAEvents(originalGaEvents) {
var result = []
var splitEvents = originalGaEvents.split('\n').forEach(function(gaRow) {
var dataSetRow = {}
gaRow.split('&').forEach(function(gaDataSet) {
var arr = gaDataSet.split('=')
switch (arr[0]) {
case 'cd':
arr[1] && (dataSetRow['Screen Name'] = arr[1]);
break
case 't':
arr[1] && (dataSetRow['Hit Type'] = arr[1]);
break
case 'ea':
arr[1] && (dataSetRow['Event Action'] = arr[1]);
break
case 'ec':
arr[1] && (dataSetRow['Event Cateory'] = arr[1]);
break
case '_s':
arr[1] && (dataSetRow['Hit Sequence'] = arr[1]);
break
case 'ht':
// console.log(new Date(parseInt(arr[1])))
arr[1] && (dataSetRow['Hit Time'] = new Date(parseInt(arr[1])));
break
default:
// arr[1] && (dataSetRow[arr[0]] = arr[1]);
}
})
result.push(dataSetRow)
})
return result
}
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})