From 54f21fa926d14130826fedca9cf2a4ac3c335ba4 Mon Sep 17 00:00:00 2001 From: freddyDOTCMS <147462678+freddyDOTCMS@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:39:42 -0600 Subject: [PATCH] #30179 Fixing and improvement several thing (#30181) ### Proposed Changes * Making persona, mode, user_agent and referer able in cubeJS https://github.com/dotCMS/core/pull/30181 * counting total of sessions https://github.com/dotCMS/core/pull/30181/files#diff-c291c8a51311832c67ceb2e3fb2a2d4fe1d9c4e02abda400c156e10bed18200eR224-R227 * Unique Page hits https://github.com/dotCMS/core/pull/30181/files#diff-c291c8a51311832c67ceb2e3fb2a2d4fe1d9c4e02abda400c156e10bed18200eR239-R242 * Unique File hits https://github.com/dotCMS/core/pull/30181/files#diff-c291c8a51311832c67ceb2e3fb2a2d4fe1d9c4e02abda400c156e10bed18200eR254-R258 * Using Average https://github.com/dotCMS/core/pull/30181/files#diff-c291c8a51311832c67ceb2e3fb2a2d4fe1d9c4e02abda400c156e10bed18200eR244-R247 https://github.com/dotCMS/core/pull/30181/files#diff-c291c8a51311832c67ceb2e3fb2a2d4fe1d9c4e02abda400c156e10bed18200eR259-R262 * collecting referer, user_agent, render mode and persona https://github.com/dotCMS/core/pull/30181/files#diff-eb72ea35bd8b223c6a9c3356304e0ab2b2f3daeec34aa1c8ad54964192902a87R49-R62 * fixing isDetailPage attribute https://github.com/dotCMS/core/pull/30181/files#diff-c291c8a51311832c67ceb2e3fb2a2d4fe1d9c4e02abda400c156e10bed18200eR180 --- .../setup/config/dev/cube/schema/Events.js | 53 +++++++++++++++++-- .../collectors/BasicProfileCollector.java | 19 +++++++ 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/docker/docker-compose-examples/analytics/setup/config/dev/cube/schema/Events.js b/docker/docker-compose-examples/analytics/setup/config/dev/cube/schema/Events.js index f6aada775d43..07466ea3b791 100644 --- a/docker/docker-compose-examples/analytics/setup/config/dev/cube/schema/Events.js +++ b/docker/docker-compose-examples/analytics/setup/config/dev/cube/schema/Events.js @@ -157,7 +157,10 @@ cube('request', { MIN(utc_time) as createdAt, MAX(source_ip) as source_ip, MAX(language) as language, - MAX(user_agent) as user_agent, + MAX(useragent) as user_agent, + MAX(persona) as persona, + MAX(rendermode) as rendermode, + MAX(referer) as referer, MAX(host) as host, MAX(CASE WHEN event_type = 'PAGE_REQUEST' THEN object_id ELSE NULL END) as page_id, MAX(CASE WHEN event_type = 'PAGE_REQUEST' THEN object_title ELSE NULL END) as page_title, @@ -174,7 +177,7 @@ cube('request', { MAX(CASE WHEN event_type = 'URL_MAP' THEN object_content_type_id ELSE NULL END) as url_map_content_type_id, MAX(CASE WHEN event_type = 'URL_MAP' THEN object_content_type_name ELSE NULL END) as url_map_content_type_name, MAX(CASE WHEN event_type = 'URL_MAP' THEN object_content_type_var_name ELSE NULL END) as url_map_content_type_var_name, - MAX(CASE WHEN event_type = 'URL_MAP' THEN object_detail_page_url ELSE NULL END) as url_map_detail_page_url, + MAX(object_detail_page_url) as url_map_detail_page_url, MAX(url) AS url, CASE WHEN MAX(CASE WHEN event_type = 'FILE_REQUEST' THEN 1 ELSE 0 END) = 1 THEN 'FILE' @@ -192,6 +195,9 @@ cube('request', { sourceIp: { sql: 'source_ip', type: `string` }, language: { sql: 'language', type: `string` }, userAgent: { sql: 'user_agent', type: `string` }, + referer: { sql: 'referer', type: `string` }, + renderMode: { sql: 'rendermode', type: `string` }, + persona: { sql: 'persona', type: `string` }, host: { sql: 'host', type: `string` }, url: { sql: 'url', type: `string` }, pageId: { sql: 'page_id', type: `string` }, @@ -209,11 +215,52 @@ cube('request', { urlMapContentDetailTitle: { sql: 'url_map_content_detail_title', type: `string` }, urlMapContentId: { sql: 'url_map_content_type_id', type: `string` }, urlMapContentTypeName: { sql: 'url_map_content_type_name', type: `string` }, - urlMapContentTypeVarName: { sql: 'url_map_content_type_var_name', type: `string` }, + urlMapContentTypeVarName: { sql: 'url_map_content_type_var_name', type: `string` } }, measures: { count: { type: "count" + }, + totalSessions: { + sql: 'sessionid', + type: 'countDistinct', + title: 'Total Sessions' + }, + totalRequest: { + sql: 'request_id', + type: 'countDistinct', + title: 'Total Requests' + }, + pageRequest: { + sql: 'page_id', + type: 'count', + title: 'Count of Page request' + }, + uniquePageRequest: { + sql: 'page_id', + type: 'countDistinct', + title: 'Unique Page Ids by Session' + }, + pageRequestAverage: { + sql: `${fileRequest} / NULLIF(${totalRequest}, 0)`, + type: 'number', + title: 'FileRequest Average' + }, + fileRequest: { + sql: 'file_id', + type: 'count', + title: 'Count of File Request' + }, + uniqueFileRequest: { + sql: 'file_id', + type: 'countDistinct', + title: 'Unique Count of File Request' + }, + fileRequestAverage: { + sql: `${fileRequest} / NULLIF(${totalRequest}, 0)`, + type: 'number', + title: 'FileRequest Average' } } }); + diff --git a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java index 3ab4a74277e7..39f0f3f8f8b5 100644 --- a/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java +++ b/dotCMS/src/main/java/com/dotcms/analytics/track/collectors/BasicProfileCollector.java @@ -3,7 +3,11 @@ import com.dotcms.enterprise.cluster.ClusterFactory; import com.dotcms.util.FunctionUtils; import com.dotmarketing.business.APILocator; +import com.dotmarketing.business.web.WebAPILocator; +import com.dotmarketing.util.PageMode; +import com.dotmarketing.util.UtilMethods; +import javax.servlet.http.HttpServletRequest; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -41,6 +45,21 @@ public CollectorPayloadBean collect(final CollectorContextMap collectorContextMa FunctionUtils.getOrDefault(Objects.nonNull(serverId), ()->serverId,()->APILocator.getServerAPI().readServerId())); collectorPayloadBean.put("sessionId", sessionId); collectorPayloadBean.put("sessionNew", sessionNew); + + if (UtilMethods.isSet(collectorContextMap.get("referer"))) { + collectorPayloadBean.put("referer", collectorContextMap.get("referer").toString()); + } + + if (UtilMethods.isSet(collectorContextMap.get("user-agent"))) { + collectorPayloadBean.put("userAgent", collectorContextMap.get("user-agent").toString()); + } + + final HttpServletRequest request = (HttpServletRequest)collectorContextMap.get("request"); + + collectorPayloadBean.put("persona", + WebAPILocator.getPersonalizationWebAPI().getContainerPersonalization(request)); + + collectorPayloadBean.put("renderMode", PageMode.get(request).toString().replace("_MODE", "")); return collectorPayloadBean; }