UNPKG

@phantomstudios/ft-lib

Version:

A collection of Javascript UI & tracking utils for FT sites

88 lines 3.48 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FTTracking = void 0; var consentMonitor_1 = require("../consentMonitor"); var gaTracker_1 = require("../gaTracker"); var oTracker_1 = require("../oTracker"); var scroll_1 = require("../utils/scroll"); var yupValidator_1 = require("../utils/yupValidator"); var DEFAULT_OPTIONS = { scrollTrackerSelector: "#o_tracker_scroll", isCustomGTMEvent: true, sendGTMPageViewYN: true, sendBrandedContent: true, }; var FTTracking = /** @class */ (function () { function FTTracking(config, options) { var _this = this; this.initializeConsentMonitor = function () { if (!_this.consentMonitor) { _this.consentMonitor = new consentMonitor_1.ConsentMonitor(window.location.hostname, [ ".app", "preview", ]); } return _this.consentMonitor; }; this.options = __assign(__assign({}, DEFAULT_OPTIONS), options); this.oTracker = new oTracker_1.oTracker(config, this.options); this.gaTracker = new gaTracker_1.gaTracker(this.options); this.disableAppFormatTransform = this.options.disableAppFormatTransform || false; this.logValidationErrors = this.options.logValidationErrors || false; this.oEvent = this.oTracker.eventDispatcher; this.gaEvent = this.options.isCustomGTMEvent ? this.gaTracker.GTMEventDispatcher : this.gaTracker.GtagEventDispatcher; this._config = config; //backwards compatibility this.gtmEvent = this.gaEvent; this.scrollTracker = new scroll_1.ScrollTracker(this); //cookie consent monitor for permutive tracking window.addEventListener("load", function () { _this.consentMonitor = new consentMonitor_1.ConsentMonitor(window.location.hostname, [ ".app", "preview", ]); }); } Object.defineProperty(FTTracking.prototype, "config", { get: function () { return this._config; }, set: function (c) { this._config = c; this.oTracker.config = c; }, enumerable: false, configurable: true }); FTTracking.prototype.newPageView = function (config) { //Update passed config to otracker,send pageview events and reset scrollTracker (0, yupValidator_1.validateConfig)(config, this.disableAppFormatTransform, this.logValidationErrors); this.oTracker.config = config; this.oTracker.broadcastPageView(); if (this.options.sendBrandedContent) { this.oTracker.broadcastBrandedContent(); } this.scrollTracker.reset(); if (this.options.sendGTMPageViewYN) { this.gaTracker.GTMVirtualPageView(this.config.url, this.config.title); } //ga pageview event required for sites without GTM? }; return FTTracking; }()); exports.FTTracking = FTTracking; //# sourceMappingURL=index.js.map