@dotcms/analytics
Version:
Official JavaScript library for Content Analytics with DotCMS.
45 lines (44 loc) • 1.35 kB
JavaScript
import { DotCMSPredefinedEventType as r } from "../../shared/constants/dot-analytics.constants.js";
import { getLocalTime as i, enrichPagePayloadOptimized as o } from "../../shared/utils/dot-analytics.utils.js";
const l = () => ({
name: "enrich-dot-analytics",
/**
* PAGE VIEW ENRICHMENT - Runs after identity context injection
* Returns enriched payload with page, utm, and custom data added
* @returns {EnrichedAnalyticsPayload} Enriched payload ready for event creation
*/
"page:dot-analytics": ({
payload: e
}) => {
const t = o(e);
if (!t.page)
throw new Error("DotCMS Analytics: Missing required page data");
return t;
},
/**
* TRACK EVENT ENRICHMENT - Runs after identity context injection
* Adds page data and timestamp for predefined content events.
* For custom events, only adds timestamp.
*
* @returns {EnrichedTrackPayload} Enriched payload ready for event structuring
*/
"track:dot-analytics": ({
payload: e
}) => {
const { event: t } = e, n = i();
return t === r.CONTENT_IMPRESSION || t === r.CONTENT_CLICK || t === r.CONVERSION ? {
...e,
page: {
title: document.title,
url: window.location.href
},
local_time: n
} : {
...e,
local_time: n
};
}
});
export {
l as dotAnalyticsEnricherPlugin
};