@arabam/collect
v1.0.30
Published
arabam.com collect
Downloads
242
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: {}
autoPageview: true; // default: true
};
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
If you need to send the pageview yourself (for example on the listing detail page, after your own view condition is met), pass autoPageview: false. Then no pageview request is sent while the instance is being created, and you send it manually via record. window.collectInstance and the arabamCollect-initialized event behave exactly the same in both cases.
new Collect({ apiKey: "123456", visitorId: "654321", autoPageview: false });
// later, when your own condition is met
window.collectInstance?.record({
Action: "pageview",
Label: "listing",
Type: "navigate",
url: window.location.href.replace(window.location.origin, ""),
});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 | {},
autoPageview?: boolean; // default: true
}
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
referrer?: string | null; // default: document.referrer
}
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'})
