Skip to content

Commit efa5345

Browse files
author
Kevin Friedman
committed
Fix payload encoding
1 parent 2ec0fb6 commit efa5345

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

api/controllers/send.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ function sendPageView (req, res) {
3636

3737
if (!req.query.page) throw new Error('Page was not specified.')
3838

39-
let payLoad = querystring.stringify({
39+
let payLoad = {
4040
v: 1,
4141
tid: req.query.trackingId,
4242
cid: req.query.clientId,
4343
t: 'pageview',
4444
dh: req.query.host,
4545
dp: req.query.page
46-
});
46+
};
4747

4848
axios({
4949
method: 'post',
5050
url: gaConfig.googleBaseUrl + '/collect',
51-
data: payLoad,
51+
data: querystring.stringify(payLoad),
5252
headers: {}
5353
})
5454
.then(response => {
@@ -80,22 +80,22 @@ function sendEvent (req, res) {
8080
if (!req.query.eventCategory) throw new Error('Event category was not specified.')
8181
if (!req.query.eventAction) throw new Error('Event action was not specified.')
8282

83-
let payLoad = querystring.stringify({
83+
let payLoad = {
8484
v: 1,
8585
tid: req.query.trackingId,
8686
cid: req.query.clientId,
8787
t: 'event',
8888
ec: req.query.eventCategory,
8989
ea: req.query.eventAction
90-
});
90+
};
9191

9292
if (req.query.eventLabel) payLoad.el = req.query.eventLabel
9393
if (req.query.eventValue) payLoad.ev = req.query.eventValue
9494

9595
axios({
9696
method: 'post',
9797
url: gaConfig.googleBaseUrl + '/collect',
98-
data: payLoad,
98+
data: querystring.stringify(payLoad),
9999
headers: {}
100100
})
101101
.then(response => {

app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ app.options('*', function (req, res) {
2828
let router = express.Router();
2929
app.use(process.env.BASE_PATH, router);
3030

31+
router.route('/swagger')
32+
.get(function (req, res) {
33+
res
34+
.status(200)
35+
.header('Access-Control-Allow-Headers', 'Content-Type')
36+
.header('Access-Control-Allow-Origin', '*')
37+
.sendFile(__dirname + '/swagger/v0.1.json');
38+
});
39+
3140
router.route('/javascript/gaproxy.js')
3241
.get(javascript.getJavascript);
3342

0 commit comments

Comments
 (0)