Skip to content

Commit ff98f71

Browse files
committedDec 15, 2018
heatmaps additional resolution options added
1 parent b80cee3 commit ff98f71

File tree

2 files changed

+69
-40
lines changed

2 files changed

+69
-40
lines changed
 

‎plugins/views/api/api.js

+13-32
Original file line numberDiff line numberDiff line change
@@ -192,38 +192,19 @@ var pluginOb = {},
192192
*/
193193
function getHeatmap(params) {
194194
var result = {types: [], data: []};
195-
var devices = [
196-
{
197-
type: "all",
198-
displayText: "All",
199-
minWidth: 0,
200-
maxWidth: 10240
201-
},
202-
{
203-
type: "mobile",
204-
minWidth: 0,
205-
maxWidth: 767
206-
},
207-
{
208-
type: "tablet",
209-
minWidth: 767,
210-
maxWidth: 1024
211-
},
212-
{
213-
type: "desktop",
214-
minWidth: 1024,
215-
maxWidth: 10240
216-
},
217-
];
218-
219-
var deviceType = params.qstring.deviceType;
195+
196+
var device = {};
197+
try {
198+
device = JSON.parse(params.qstring.device);
199+
}
200+
catch (SyntaxError) {
201+
console.log('Parse device failed: ', params.qstring.device);
202+
}
203+
220204
var actionType = params.qstring.actionType;
221-
var device = devices.filter((obj) => {
222-
return obj.type === deviceType;
223-
});
224205

225-
if (!device.length) {
226-
common.returnMessage(params, 400, 'Bad request parameter: device type');
206+
if (!(device.minWidth >= 0) || !(device.maxWidth >= 0)) {
207+
common.returnMessage(params, 400, 'Bad request parameter: device');
227208
return false;
228209
}
229210
var collectionName = "drill_events" + crypto.createHash('sha1').update("[CLY]_action" + params.qstring.app_id).digest('hex');
@@ -345,8 +326,8 @@ var pluginOb = {},
345326
queryObject.ts.$lt = queryObject.ts.$lt.getTime() + queryObject.ts.$lt.getTimezoneOffset() * 60000;
346327

347328
queryObject["sg.width"] = {};
348-
queryObject["sg.width"].$gt = device[0].minWidth;
349-
queryObject["sg.width"].$lte = device[0].maxWidth;
329+
queryObject["sg.width"].$gt = device.minWidth;
330+
queryObject["sg.width"].$lte = device.maxWidth;
350331
queryObject["sg.type"] = actionType;
351332

352333
var projections = {

‎plugins/views/frontend/public/heatmap.js

+56-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
document.body.style.position = "relative";
1313
var origtop = document.body.style.top;
1414
var toppx = 59;
15-
var devices = [
15+
var allDevices = [
1616
{
1717
type: "all",
1818
displayText: "All",
@@ -32,13 +32,39 @@
3232
maxWidth: 1024
3333
},
3434
{
35-
type: "desktop",
36-
displayText: "Desktop",
35+
type: "desktop-1366",
36+
displayText: "Desktop - 1366",
3737
minWidth: 1024,
38-
maxWidth: 10240
38+
maxWidth: 1366
39+
},
40+
{
41+
type: "desktop-1440",
42+
displayText: "Desktop - 1440",
43+
minWidth: 1366,
44+
maxWidth: 1440
45+
},
46+
{
47+
type: "desktop-1600",
48+
displayText: "Desktop - 1600",
49+
minWidth: 1440,
50+
maxWidth: 1600
51+
},
52+
{
53+
type: "desktop-1920",
54+
displayText: "Desktop - 1920",
55+
minWidth: 1600,
56+
maxWidth: 1920
3957
},
58+
{
59+
type: "desktop-other",
60+
displayText: "Desktop - Other",
61+
minWidth: null,
62+
maxWidth: 10240
63+
}
4064
];
4165

66+
var devices = [];
67+
4268
if (origtop) {
4369
toppx += parseInt(origtop);
4470
}
@@ -49,8 +75,6 @@
4975
topbar.setAttribute("id", "cly-heatmap-topbar");
5076
document.body.appendChild(topbar);
5177

52-
53-
5478
if (currentDevice.length) {
5579
pageWidth = Countly._internals.getDocWidth();
5680
pageWidth = Math.min(currentDevice[0].maxWidth, pageWidth);
@@ -62,6 +86,24 @@
6286
else {
6387
pageWidth = Countly._internals.getDocWidth();
6488
pageHeight = Countly._internals.getDocHeight() - toppx;
89+
}
90+
91+
for (var i = 0; i < allDevices.length; i++) {
92+
if (allDevices[i].type == "all") {
93+
devices.push(allDevices[i]);
94+
}
95+
96+
if (allDevices[i].maxWidth <= pageWidth) {
97+
devices.push(allDevices[i]);
98+
}
99+
100+
if (allDevices[i].type === "desktop-other") {
101+
devices.push(allDevices[i]);
102+
devices[devices.length - 1].minWidth = devices[devices.length - 2].maxWidth;
103+
}
104+
}
105+
106+
if (!currentDevice.length) {
65107
currentDevice = devices.filter((deviceObj) => {
66108
return deviceObj.minWidth < pageWidth && deviceObj.maxWidth >= pageWidth && deviceObj.type != "all";
67109
});
@@ -205,6 +247,9 @@
205247
if (device.type == "all") {
206248
return deviceObj.type == "all";
207249
}
250+
else if (device.type == "desktop-other") {
251+
return deviceObj.type == "desktop-other";
252+
}
208253
else {
209254
return deviceObj.minWidth < pageWidth && deviceObj.maxWidth >= pageWidth && deviceObj.type != "all";
210255
}
@@ -305,6 +350,9 @@
305350
if (currentDevice[0].type == "all") {
306351
return deviceObj.type == "all";
307352
}
353+
else if (currentDevice[0].type == "desktop-other") {
354+
return deviceObj.type == "desktop-other";
355+
}
308356
else {
309357
return deviceObj.minWidth < pageWidth && deviceObj.maxWidth >= pageWidth && deviceObj.type != "all";
310358
}
@@ -473,7 +521,7 @@
473521
}
474522

475523
function loadData() {
476-
sendXmlHttpRequest({ app_key: Countly.app_key, view: Countly._internals.getLastView() || window.location.pathname, period: period, deviceType: currentDevice[0].type, actionType: actionType }, apiPath, function(err, clicks) {
524+
sendXmlHttpRequest({ app_key: Countly.app_key, view: Countly._internals.getLastView() || window.location.pathname, period: period, device: JSON.stringify(currentDevice[0]), actionType: actionType }, apiPath, function(err, clicks) {
477525
if (!err) {
478526
dataCache[currentDevice[0].type] = clicks.data;
479527
drawData();
@@ -538,7 +586,7 @@
538586
}
539587

540588
function loadData() {
541-
sendXmlHttpRequest({ app_key: Countly.app_key, view: Countly._internals.getLastView() || window.location.pathname, period: period, deviceType: currentDevice[0].type, actionType: actionType }, apiPath, function(err, scrolls) {
589+
sendXmlHttpRequest({ app_key: Countly.app_key, view: Countly._internals.getLastView() || window.location.pathname, period: period, device: JSON.stringify(currentDevice[0]), actionType: actionType }, apiPath, function(err, scrolls) {
542590
if (!err) {
543591
dataCache[currentDevice[0].type] = scrolls.data;
544592
drawData();

0 commit comments

Comments
 (0)
Please sign in to comment.