@arabam/collect
v1.0.27
Published
arabam.com collect
Keywords
Readme
Arabam Collect
Installation
npm install @arabam/collectInitialize
import Collect from "@arabam/collect";
const options : ICollectOptions = {
apiKey: "123456";
visitorId: "654321";
userId: "123";
debug: true; // default: false
dimension: {}
};
new Collect(options);Note: in development and staging modes you must set true value for debug option
After initialization, collect sends PageView request to server and sends arabamCollect-initialized event to page automatically
window.addEventListener("arabamCollect-initialized", () => {
// Do somethings
});Methods
| Name | Description | Parameters |
| -------------- | ------------------------------------------------------------------------- | --------- |
| record | send client events to collect server (pageView, click, etc.) | IEventRecord |
| updateDimension | Update dimension data | Object |
| stopRecord | Stop recording client events |
| startRecord | Start recording client events |
| destroy | Destroy Collect instance from DOM |
Interfaces
interface ICollectOptions {
apiKey: string;
visitorId: string;
userId?: string;
debug?: boolean | false;
dimension?: Object | {},
}
interface ICollectInstance {
record(data: IEventRecord): void;
updateDimension(dimension: Object): void;
stopRecord(): void;
startRecord(): void;
destroy(): void;
userId: string;
visitorId: string;
}
interface IEventRecord {
Label?: string;
Action?: string;
value?: string | boolean;
url?: string | null;
Category?: string | null;
BreadCrumb?: string | null;
Type?: string | null
}
Example
import Collect from "@arabam/collect";
let options = {
apiKey: "123456";
visitorId: "654321";
userId: "123";
debug: true; // default: false
dimension: {}
}
new Collect({ options });
// for test collect
console.log(window.collectInstance)
window.collectInstance.updateDimension({
productID:"123",
color:"red",
price:"100000"
})
// for virtual page view
window.collectInstance?.record({
Action: "pageview",
url: window.location.href.replace(window.location.origin, ""),
});
window.collectInstance.record({Label:'label for record',Action:'click'})
