@dotcms/analytics
Version:
Official JavaScript library for Content Analytics with DotCMS.
56 lines (55 loc) • 1.24 kB
JavaScript
import { sendAnalyticsEventToServer as r } from "../shared/dot-content-analytics.http.js";
const s = (a) => {
let n = !1;
return {
name: "dot-analytics",
config: a,
/**
* Initialize the plugin
*/
initialize: (o) => {
const { config: i, payload: t } = o;
if (i.debug && console.warn("DotAnalytics: Initialized with config", i), n = !0, i.autoPageView) {
const e = {
...t.properties,
key: i.apiKey
};
return r(e, i);
}
return Promise.resolve();
},
/**
* Track a page view event
*/
page: (o) => {
const { config: i, payload: t } = o;
if (!n)
throw new Error("DotAnalytics: Plugin not initialized");
const e = {
...t.properties,
key: i.apiKey
};
return r(e, i);
},
/**
* Track a custom event
*/
track: (o) => {
const { config: i, payload: t } = o;
if (!n)
throw new Error("DotAnalytics: Plugin not initialized");
const e = {
...t.properties,
key: i.apiKey
};
return r(e, i);
},
/**
* Check if the plugin is loaded
*/
loaded: () => n
};
};
export {
s as dotAnalytics
};