UNPKG

@questlabs/core

Version:
77 lines (76 loc) 4.31 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.QuestEvents = void 0; const config_1 = require("../../utils/config"); const constants_1 = require("../../utils/constants"); const helperFunctions_1 = require("../../utils/helperFunctions"); class QuestEvents { constructor(questSdk) { this.questSdk = questSdk; } track({ entityId, name, userId, properties, isIndependent, isQuestUser, queue }, options) { return __awaiter(this, void 0, void 0, function* () { try { const defaultEntityId = entityId || this.questSdk.getEntityId(); const url = `/events/track${queue ? "/queue" : ""}`; (0, helperFunctions_1.validateParams)({ entityId: defaultEntityId, name, userId }); const userData = yield this.questSdk.getUserInfo(); const urlData = this.questSdk.getUrlInformation(); let textCampaigns = []; if (typeof window !== "undefined" && (window === null || window === void 0 ? void 0 : window.sessionStorage)) { const textCampaignString = window.sessionStorage.getItem(config_1.TEXT_CAMPAIGN_SESSION_ID); if (textCampaignString !== null) { const parsedCampaigns = JSON.parse(textCampaignString || String([])) || []; if (Array.isArray(parsedCampaigns)) { textCampaigns = parsedCampaigns; } } } const data = { entityId: defaultEntityId, name, source: "sdk", properties, isIndependent, userId: userId || this.questSdk.getDistinctId(), isQuestUser, // default ones metadata: { userAgent: typeof navigator !== 'undefined' && (navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) || '', ip: userData === null || userData === void 0 ? void 0 : userData.ip, city: userData === null || userData === void 0 ? void 0 : userData.city, region: userData === null || userData === void 0 ? void 0 : userData.region, country: userData === null || userData === void 0 ? void 0 : userData.country, url: urlData === null || urlData === void 0 ? void 0 : urlData.href, host: urlData === null || urlData === void 0 ? void 0 : urlData.host, hostname: urlData === null || urlData === void 0 ? void 0 : urlData.hostname, origin: urlData === null || urlData === void 0 ? void 0 : urlData.origin, pathname: urlData === null || urlData === void 0 ? void 0 : urlData.pathname, textCampaigns, } }; return this.questSdk.makeRequest({ url, method: constants_1.HTTP_METHOD.POST, queryParams: options === null || options === void 0 ? void 0 : options._queryParams, body: data, headers: options === null || options === void 0 ? void 0 : options._headers, }); } catch (error) { this.questSdk.captureSentryException(error); throw error; } }); } } exports.QuestEvents = QuestEvents;