UNPKG

@point-api/js-sdk

Version:

Javascript SDK for Point API

61 lines 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** Class to record Events (interactions with no connected user's account) */ class EventsApiModule { constructor(apiUrl = "https://v1.pointapi.com", emailAddress) { this.emailAddress = ""; this.url = "/events"; this.apiUrl = apiUrl; if (emailAddress) { this.emailAddress = emailAddress; } } async scribeInstalled(id) { await this.storeEvent("scribeInstalled", id); } async scribeUninstalled(id) { await this.storeEvent("scribeUninstalled", id); } async acceptedToS(id) { await this.storeEvent("acceptedToS", id); } async signInWithGoogle(id) { await this.storeEvent("signInWithGoogle", id); } async paymentInfoFreeTrialShown(id) { await this.storeEvent("paymentInfoFreeTrialShown", id); } async paymentFailure(id) { await this.storeEvent("paymentFailure", id); } async paymentOpened(id) { await this.storeEvent("paymentOpened", id); } async paymentSuccess(id) { await this.storeEvent("paymentSuccess", id); } async storeEvent(type, trackingId, data) { const headers = { "Content-Type": "application/json" }; const payload = { type, trackingId, data }; if (this.emailAddress) { payload["emailAddress"] = this.emailAddress; } await this.fetch("POST", payload, headers); } /** Make unauthenticated request to Events API Resource */ async fetch(method, data, headers) { const { apiUrl, url } = this; const fullUrl = `${apiUrl}${url}`; const body = data ? JSON.stringify(data) : undefined; const response = await fetch(fullUrl, { method, body, headers }); return response; } } exports.default = EventsApiModule; //# sourceMappingURL=events.js.map