UNPKG

clean-insights-sdk

Version:

A privacy-preserving measurement framework.

78 lines (77 loc) 3.5 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Event = void 0; var DataPoint_1 = require("./DataPoint"); var Event = /** @class */ (function (_super) { __extends(Event, _super); /** * @param {string|EventData} category * The event category or an object containing all arguments. Must not be empty. (eg. Videos, Music, Games...) * * @param {string=} action * The event action. Must not be empty. (eg. Play, Pause, Duration, Add Playlist, Downloaded, Clicked...) * OPTIONAL if provided via an object as first argument. * * @param {string=} name * The event name. OPTIONAL. * * @param {number=} value * The event value. OPTIONAL. * * @param {string=} campaignId * The campaign ID this data point is for. * OPTIONAL if constructed with an object instead. * * @param {number=} times=1 * Number of times this data point has arisen between `first` and `last`. OPTIONAL. * * @param {dayjs.Dayjs=} first=NOW * The first time this data point has arisen. OPTIONAL. * * @param {dayjs.Dayjs=} last=NOW * The last time this data point has arisen. OPTIONAL. */ function Event(category, action, name, value, campaignId, times, first, last) { var _this = this; if (typeof category === 'string') { if (typeof campaignId === 'string' && typeof action === 'string') { _this = _super.call(this, campaignId, times, first, last) || this; _this.category = category; _this.action = action; _this.name = name; _this.value = value; } else { throw TypeError('You either need to provide all non-optional arguments in their place or in an object as the first argument.'); } } else { _this = _super.call(this, category.campaignId, category.times, category.first, category.last) || this; _this.category = category.category; _this.action = category.action; _this.name = category.name; _this.value = category.value; } return _this; } Event.prototype.toString = function () { return "[".concat(this.constructor.name, ": category=").concat(this.category, ", action=").concat(this.action, ", name=").concat(this.name, ", value=").concat(this.value, ", campaignId=").concat(this.campaignId, ", times=").concat(this.times, ", first=").concat(this.first.format(), ", last=").concat(this.last.format(), "]"); }; return Event; }(DataPoint_1.DataPoint)); exports.Event = Event;