feat: Add grouping based on source

And a formatter for source column
This commit is contained in:
Suraj Shetty 2023-02-28 13:37:04 +05:30
parent 540bf5a984
commit c4e31f435b
2 changed files with 27 additions and 1 deletions

View file

@ -36,8 +36,28 @@ frappe.query_reports["Website Analytics"] = {
{ value: "path", label: __("Path") },
{ value: "browser", label: __("Browser") },
{ value: "referrer", label: __("Referrer") },
{ value: "source", label: __("Source") },
],
default: "path",
},
],
formatter: function (value, row, column, data, default_formatter) {
if (
frappe.query_report.get_filter_value("group_by") === "source" &&
column.id === "source"
) {
if (value) {
try {
let doctype = value.split(">")[0].trim();
let name = value.split(">")[1].trim();
return frappe.utils.get_form_link(doctype, name, true, value);
} catch (e) {
// skip and return with default formatter
}
} else {
return `<i>${__("Unknown")}</i>`;
}
}
return default_formatter(value, row, column, data);
},
};

View file

@ -42,7 +42,13 @@ class WebsiteAnalytics:
meta = frappe.get_meta("Web Page View")
group_by = meta.get_field(self.group_by)
return [
{"fieldname": group_by.fieldname, "label": group_by.label, "fieldtype": "Data", "width": 300},
{
"fieldname": group_by.fieldname,
"label": group_by.label,
"fieldtype": "Data",
"width": 500,
"align": "left",
},
{"fieldname": "count", "label": "Page Views", "fieldtype": "Int", "width": 150},
{"fieldname": "unique_count", "label": "Unique Visitors", "fieldtype": "Int", "width": 150},
]