@getkoala/browser
Advanced tools
Comparing version 1.17.0 to 1.20.0
@@ -66,7 +66,7 @@ "use strict"; | ||
(_a = window.ko) === null || _a === void 0 ? void 0 : _a.ready(spy); | ||
(_b = window.ko) === null || _b === void 0 ? void 0 : _b.on('change', spy); | ||
(_b = window.ko) === null || _b === void 0 ? void 0 : _b.on('profile-update', spy); | ||
KoalaSDK.load({ project: 'test' }); | ||
setTimeout(() => { | ||
var _a; | ||
(_a = window.ko) === null || _a === void 0 ? void 0 : _a.emit('change'); | ||
(_a = window.ko) === null || _a === void 0 ? void 0 : _a.emit('profile-update'); | ||
expect(spy).toHaveBeenCalledTimes(2); | ||
@@ -73,0 +73,0 @@ done(); |
@@ -22,2 +22,4 @@ import { build } from '@getkoala/edge-api-client'; | ||
Intercom?: any; | ||
FS?: any; | ||
posthog?: any; | ||
_hsq?: { | ||
@@ -47,7 +49,2 @@ push: (callParam: any) => void; | ||
initialized: [BootstrapData]; | ||
open: []; | ||
close: []; | ||
'request-show': []; | ||
show: []; | ||
hide: []; | ||
track: [string, { | ||
@@ -60,4 +57,2 @@ [key: string]: unknown; | ||
qualification: [Qualification]; | ||
/** @deprecated */ | ||
change: []; | ||
} | ||
@@ -76,3 +71,2 @@ export declare type CollectorOptions = Partial<ProjectSettings> & Options; | ||
private bootstrapData?; | ||
private lastActivityAt?; | ||
private autocapture; | ||
@@ -97,10 +91,4 @@ private referrerAllowed; | ||
startAutocapture(): void; | ||
open(): void; | ||
close(): void; | ||
show(): void; | ||
hide(): void; | ||
get session(): Session; | ||
get email(): string | undefined; | ||
private touchLastActivityAt; | ||
private updatePresence; | ||
private detectHubspot; | ||
@@ -111,3 +99,3 @@ private detectSegment; | ||
[key: string]: unknown; | ||
}): Promise<void>; | ||
}, options?: EventOptions): Promise<void>; | ||
identify(email: string, traits?: Record<string, unknown>, options?: EventOptions): Promise<void>; | ||
@@ -114,0 +102,0 @@ identify(traits: Record<string, unknown>, options?: EventOptions): Promise<void>; |
@@ -21,9 +21,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AnalyticsCollector = void 0; | ||
const edge_api_client_1 = require("@getkoala/edge-api-client"); | ||
const throttle_1 = __importDefault(require("lodash/throttle")); | ||
const collect_1 = require("../api/collect"); | ||
@@ -46,5 +42,7 @@ const utkApi = __importStar(require("../api/utk")); | ||
const drift_1 = require("./plugins/drift"); | ||
const fullstory_1 = require("./plugins/fullstory"); | ||
const hubspot_1 = require("./plugins/hubspot"); | ||
const intercom_1 = require("./plugins/intercom"); | ||
const navattic_1 = require("./plugins/navattic"); | ||
const posthog_screen_recording_1 = require("./plugins/posthog-screen-recording"); | ||
const qualified_1 = require("./plugins/qualified"); | ||
@@ -62,3 +60,2 @@ const session_1 = require("./session"); | ||
} | ||
const interactionEvents = ['scroll', 'mousemove', 'click', 'touchstart', 'keypress']; | ||
function checkReferrer(referrers) { | ||
@@ -128,13 +125,7 @@ if (referrers.length === 0) | ||
(0, qualified_1.initQualified)(this); | ||
if (settings.autotrack_fullstory) | ||
(0, fullstory_1.initFullstory)(this); | ||
if (settings.autotrack_posthog_screen_recording) | ||
(0, posthog_screen_recording_1.initPostHogScreenRecording)(this); | ||
}; | ||
this.touchLastActivityAt = (0, throttle_1.default)(() => { | ||
if (document.visibilityState === 'visible') { | ||
this.lastActivityAt = new Date().toISOString(); | ||
this.updatePresence(); | ||
} | ||
}, 1000); | ||
this.updatePresence = (0, throttle_1.default)(() => { | ||
var _a; | ||
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.updatePresence(this.lastActivityAt); | ||
}, 30000); | ||
this.trackError = (error, method) => { | ||
@@ -199,7 +190,2 @@ if (error) { | ||
}); | ||
// capture tab regaining focus as interaction | ||
window.addEventListener('focus', this.touchLastActivityAt); | ||
interactionEvents.forEach((event) => { | ||
window.addEventListener(event, this.touchLastActivityAt, { capture: true, passive: true }); | ||
}); | ||
if (options.hookSegment !== false) { | ||
@@ -373,14 +359,2 @@ this.detectSegment(); | ||
} | ||
open() { | ||
this.emit('open'); | ||
} | ||
close() { | ||
this.emit('close'); | ||
} | ||
show() { | ||
this.emit('request-show'); | ||
} | ||
hide() { | ||
this.emit('hide'); | ||
} | ||
get session() { | ||
@@ -517,3 +491,3 @@ return session_1.session.fetch(this.options.sdk_settings); | ||
} | ||
async track(event, properties = {}) { | ||
async track(event, properties = {}, options) { | ||
event = event.trim(); | ||
@@ -523,3 +497,3 @@ if (!event || !this.referrerAllowed || !this.geoAllowed) | ||
const type = event === '$submit' ? 'submit' : 'track'; | ||
this.eventQueue.track(event, properties, type); | ||
this.eventQueue.track(event, properties, type, options); | ||
this.edge.index({ event, properties }); | ||
@@ -582,6 +556,11 @@ this.emit('track', event, properties); | ||
subscribe() { | ||
var _a, _b; | ||
if (!this.referrerAllowed || !this.geoAllowed || ((_b = (_a = this.bootstrapData) === null || _a === void 0 ? void 0 : _a.sdk_settings) === null || _b === void 0 ? void 0 : _b.websocket_connection) === 'off') { | ||
var _a, _b, _c; | ||
if (!this.referrerAllowed) | ||
return; | ||
} | ||
if (!this.geoAllowed) | ||
return; | ||
if (((_b = (_a = this.bootstrapData) === null || _a === void 0 ? void 0 : _a.sdk_settings) === null || _b === void 0 ? void 0 : _b.websocket_connection) === 'off') | ||
return; | ||
if (((_c = this.bootstrapData) === null || _c === void 0 ? void 0 : _c.edge_api) === false) | ||
return; | ||
this.when(() => Boolean(this.user.id())) | ||
@@ -626,3 +605,2 @@ .then(() => { | ||
this.emit('qualification', result); | ||
this.emit('change'); | ||
if (a) { | ||
@@ -689,3 +667,2 @@ this.buildAnonymousProfile(a); | ||
this.qualification = undefined; | ||
this.lastActivityAt = undefined; | ||
this.edge = (0, edge_api_client_1.build)({}); | ||
@@ -692,0 +669,0 @@ session_1.session.clear(); |
@@ -1,2 +0,2 @@ | ||
import { Context, EventContext } from './event-context'; | ||
import { Context, EventContext, EventOptions } from './event-context'; | ||
import { Queue, QueueOptions } from './queue'; | ||
@@ -18,5 +18,5 @@ export declare type Event = { | ||
[key: string]: unknown; | ||
}, type?: string): void; | ||
}, type?: string, options?: EventOptions): void; | ||
reset(): void; | ||
protected onSend(events?: Event[]): boolean | Promise<boolean> | undefined; | ||
} |
@@ -33,5 +33,8 @@ "use strict"; | ||
} | ||
track(event, properties = {}, type = 'track') { | ||
track(event, properties = {}, type = 'track', options = {}) { | ||
const e = { | ||
context: this.context.current('event'), | ||
context: { | ||
...this.context.current('event'), | ||
...options | ||
}, | ||
message_id: (0, uuid_1.v4)(), | ||
@@ -38,0 +41,0 @@ type: type, |
@@ -8,3 +8,5 @@ "use strict"; | ||
if (ko && event.data && event.data.eventName) { | ||
ko.track('Arcade ' + event.data.eventName, event.data); | ||
ko.track('Arcade ' + event.data.eventName, event.data, { | ||
source: 'arcade' | ||
}); | ||
} | ||
@@ -11,0 +13,0 @@ } |
@@ -23,3 +23,5 @@ "use strict"; | ||
ko.identify({ email: event.data.email }, { source: 'drift' }); | ||
ko.track('Drift Email Captured', event.data); | ||
ko.track('Drift Email Captured', event.data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -32,3 +34,5 @@ }); | ||
ko.identify({ phone: data.phone }, { source: 'drift' }); | ||
ko.track('Drift Phone Captured', data); | ||
ko.track('Drift Phone Captured', data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -50,3 +54,5 @@ }); | ||
} | ||
ko.track('Drift Conversation Started', data); | ||
ko.track('Drift Conversation Started', data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -58,3 +64,5 @@ }); | ||
if (ko && data) { | ||
ko.track('Drift Meeting Booked', data); | ||
ko.track('Drift Meeting Booked', data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -61,0 +69,0 @@ }); |
@@ -29,2 +29,4 @@ "use strict"; | ||
meeting_date: (_f = booking.event) === null || _f === void 0 ? void 0 : _f.dateString | ||
}, { | ||
source: 'hubspot_meeting' | ||
}); | ||
@@ -31,0 +33,0 @@ } |
@@ -32,3 +32,5 @@ "use strict"; | ||
if (event.type) { | ||
ko.track('Navattic ' + (navattic_events[event.type] || event.type), event); | ||
ko.track('Navattic ' + (navattic_events[event.type] || event.type), event, { | ||
source: 'navattic' | ||
}); | ||
} | ||
@@ -35,0 +37,0 @@ } |
@@ -20,3 +20,5 @@ "use strict"; | ||
} | ||
ko.track('Qualified ' + name, data); | ||
ko.track('Qualified ' + name, data, { | ||
source: 'qualified' | ||
}); | ||
} | ||
@@ -23,0 +25,0 @@ catch (error) { |
@@ -9,2 +9,4 @@ import type { AnonymousProfile, QualificationResult } from './collect'; | ||
autotrack_qualified?: boolean; | ||
autotrack_fullstory?: boolean; | ||
autotrack_posthog_screen_recording?: boolean; | ||
segment_auto_track?: 'on' | 'off'; | ||
@@ -24,5 +26,6 @@ form_collection?: 'on' | 'off'; | ||
sdk_settings: SdkSettings; | ||
edge_api?: boolean; | ||
a?: AnonymousProfile | null; | ||
} | ||
export declare function bootstrap(slug: string, profileId?: string): Promise<BootstrapData>; | ||
export declare function bootstrap(publicKey: string, profileId?: string): Promise<BootstrapData>; | ||
export {}; |
@@ -5,4 +5,4 @@ "use strict"; | ||
const fetch_1 = require("./fetch"); | ||
async function bootstrap(slug, profileId) { | ||
let url = `/web/projects/${slug}`; | ||
async function bootstrap(publicKey, profileId) { | ||
let url = `/web/projects/${publicKey}`; | ||
if (profileId) { | ||
@@ -9,0 +9,0 @@ url += `?profile_id=${profileId}`; |
@@ -34,8 +34,8 @@ "use strict"; | ||
/** | ||
* Fetches project settings | ||
* Fetches settings for public key | ||
*/ | ||
async function fetchSettings(project, profileId) { | ||
async function fetchSettings(publicKey, profileId) { | ||
var _a; | ||
try { | ||
const settings = await (0, bootstrap_1.bootstrap)(project, profileId); | ||
const settings = await (0, bootstrap_1.bootstrap)(publicKey, profileId); | ||
// Update the profile id in case it changed (or wasn't set yet) | ||
@@ -50,3 +50,3 @@ if (settings.profile_id) { | ||
}; | ||
return { ...settings, project }; | ||
return { ...settings, project: publicKey }; | ||
} | ||
@@ -53,0 +53,0 @@ catch (error) { |
@@ -9,5 +9,4 @@ import type { Consumer, Mixin, Subscription } from '@rails/actioncable'; | ||
rejected: () => void; | ||
updatePresence: (lastActivity?: string) => void; | ||
}; | ||
export declare function createProfileSubscription(client: Consumer, instance: AnalyticsCollector, onReceived: OnReceivedFn): ProfileSubscription; | ||
export {}; |
@@ -7,5 +7,2 @@ "use strict"; | ||
isConnected: false, | ||
initialized() { | ||
this.updatePresence = this.updatePresence.bind(this); | ||
}, | ||
connected() { | ||
@@ -20,11 +17,2 @@ this.isConnected = true; | ||
}, | ||
updatePresence(lastActivityAt) { | ||
if (!this.isConnected || !lastActivityAt) | ||
return; | ||
this.perform('presence', { | ||
sid: instance.session.id, | ||
last_activity_at: lastActivityAt, | ||
visible: document.visibilityState === 'visible' | ||
}); | ||
}, | ||
received: onReceived | ||
@@ -31,0 +19,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
export declare const version = "1.17.0"; | ||
export declare const version = "1.20.0"; |
@@ -5,3 +5,3 @@ "use strict"; | ||
// This file is generated - DO NOT EDIT DIRECTLY. | ||
exports.version = '1.17.0'; | ||
exports.version = '1.20.0'; | ||
//# sourceMappingURL=version.js.map |
@@ -45,7 +45,7 @@ /** | ||
(_a = window.ko) === null || _a === void 0 ? void 0 : _a.ready(spy); | ||
(_b = window.ko) === null || _b === void 0 ? void 0 : _b.on('change', spy); | ||
(_b = window.ko) === null || _b === void 0 ? void 0 : _b.on('profile-update', spy); | ||
KoalaSDK.load({ project: 'test' }); | ||
setTimeout(() => { | ||
var _a; | ||
(_a = window.ko) === null || _a === void 0 ? void 0 : _a.emit('change'); | ||
(_a = window.ko) === null || _a === void 0 ? void 0 : _a.emit('profile-update'); | ||
expect(spy).toHaveBeenCalledTimes(2); | ||
@@ -52,0 +52,0 @@ done(); |
@@ -22,2 +22,4 @@ import { build } from '@getkoala/edge-api-client'; | ||
Intercom?: any; | ||
FS?: any; | ||
posthog?: any; | ||
_hsq?: { | ||
@@ -47,7 +49,2 @@ push: (callParam: any) => void; | ||
initialized: [BootstrapData]; | ||
open: []; | ||
close: []; | ||
'request-show': []; | ||
show: []; | ||
hide: []; | ||
track: [string, { | ||
@@ -60,4 +57,2 @@ [key: string]: unknown; | ||
qualification: [Qualification]; | ||
/** @deprecated */ | ||
change: []; | ||
} | ||
@@ -76,3 +71,2 @@ export declare type CollectorOptions = Partial<ProjectSettings> & Options; | ||
private bootstrapData?; | ||
private lastActivityAt?; | ||
private autocapture; | ||
@@ -97,10 +91,4 @@ private referrerAllowed; | ||
startAutocapture(): void; | ||
open(): void; | ||
close(): void; | ||
show(): void; | ||
hide(): void; | ||
get session(): Session; | ||
get email(): string | undefined; | ||
private touchLastActivityAt; | ||
private updatePresence; | ||
private detectHubspot; | ||
@@ -111,3 +99,3 @@ private detectSegment; | ||
[key: string]: unknown; | ||
}): Promise<void>; | ||
}, options?: EventOptions): Promise<void>; | ||
identify(email: string, traits?: Record<string, unknown>, options?: EventOptions): Promise<void>; | ||
@@ -114,0 +102,0 @@ identify(traits: Record<string, unknown>, options?: EventOptions): Promise<void>; |
import { build } from '@getkoala/edge-api-client'; | ||
import throttle from 'lodash/throttle'; | ||
import { collectIdentify, collectPages, qualify } from '../api/collect'; | ||
@@ -20,5 +19,7 @@ import * as utkApi from '../api/utk'; | ||
import { initDrift } from './plugins/drift'; | ||
import { initFullstory } from './plugins/fullstory'; | ||
import { initHubSpot } from './plugins/hubspot'; | ||
import { initIntercom } from './plugins/intercom'; | ||
import { initNavattic } from './plugins/navattic'; | ||
import { initPostHogScreenRecording } from './plugins/posthog-screen-recording'; | ||
import { initQualified } from './plugins/qualified'; | ||
@@ -36,3 +37,2 @@ import { session } from './session'; | ||
} | ||
const interactionEvents = ['scroll', 'mousemove', 'click', 'touchstart', 'keypress']; | ||
function checkReferrer(referrers) { | ||
@@ -102,13 +102,7 @@ if (referrers.length === 0) | ||
initQualified(this); | ||
if (settings.autotrack_fullstory) | ||
initFullstory(this); | ||
if (settings.autotrack_posthog_screen_recording) | ||
initPostHogScreenRecording(this); | ||
}; | ||
this.touchLastActivityAt = throttle(() => { | ||
if (document.visibilityState === 'visible') { | ||
this.lastActivityAt = new Date().toISOString(); | ||
this.updatePresence(); | ||
} | ||
}, 1000); | ||
this.updatePresence = throttle(() => { | ||
var _a; | ||
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.updatePresence(this.lastActivityAt); | ||
}, 30000); | ||
this.trackError = (error, method) => { | ||
@@ -173,7 +167,2 @@ if (error) { | ||
}); | ||
// capture tab regaining focus as interaction | ||
window.addEventListener('focus', this.touchLastActivityAt); | ||
interactionEvents.forEach((event) => { | ||
window.addEventListener(event, this.touchLastActivityAt, { capture: true, passive: true }); | ||
}); | ||
if (options.hookSegment !== false) { | ||
@@ -347,14 +336,2 @@ this.detectSegment(); | ||
} | ||
open() { | ||
this.emit('open'); | ||
} | ||
close() { | ||
this.emit('close'); | ||
} | ||
show() { | ||
this.emit('request-show'); | ||
} | ||
hide() { | ||
this.emit('hide'); | ||
} | ||
get session() { | ||
@@ -491,3 +468,3 @@ return session.fetch(this.options.sdk_settings); | ||
} | ||
async track(event, properties = {}) { | ||
async track(event, properties = {}, options) { | ||
event = event.trim(); | ||
@@ -497,3 +474,3 @@ if (!event || !this.referrerAllowed || !this.geoAllowed) | ||
const type = event === '$submit' ? 'submit' : 'track'; | ||
this.eventQueue.track(event, properties, type); | ||
this.eventQueue.track(event, properties, type, options); | ||
this.edge.index({ event, properties }); | ||
@@ -556,6 +533,11 @@ this.emit('track', event, properties); | ||
subscribe() { | ||
var _a, _b; | ||
if (!this.referrerAllowed || !this.geoAllowed || ((_b = (_a = this.bootstrapData) === null || _a === void 0 ? void 0 : _a.sdk_settings) === null || _b === void 0 ? void 0 : _b.websocket_connection) === 'off') { | ||
var _a, _b, _c; | ||
if (!this.referrerAllowed) | ||
return; | ||
} | ||
if (!this.geoAllowed) | ||
return; | ||
if (((_b = (_a = this.bootstrapData) === null || _a === void 0 ? void 0 : _a.sdk_settings) === null || _b === void 0 ? void 0 : _b.websocket_connection) === 'off') | ||
return; | ||
if (((_c = this.bootstrapData) === null || _c === void 0 ? void 0 : _c.edge_api) === false) | ||
return; | ||
this.when(() => Boolean(this.user.id())) | ||
@@ -600,3 +582,2 @@ .then(() => { | ||
this.emit('qualification', result); | ||
this.emit('change'); | ||
if (a) { | ||
@@ -663,3 +644,2 @@ this.buildAnonymousProfile(a); | ||
this.qualification = undefined; | ||
this.lastActivityAt = undefined; | ||
this.edge = build({}); | ||
@@ -666,0 +646,0 @@ session.clear(); |
@@ -1,2 +0,2 @@ | ||
import { Context, EventContext } from './event-context'; | ||
import { Context, EventContext, EventOptions } from './event-context'; | ||
import { Queue, QueueOptions } from './queue'; | ||
@@ -18,5 +18,5 @@ export declare type Event = { | ||
[key: string]: unknown; | ||
}, type?: string): void; | ||
}, type?: string, options?: EventOptions): void; | ||
reset(): void; | ||
protected onSend(events?: Event[]): boolean | Promise<boolean> | undefined; | ||
} |
@@ -11,5 +11,8 @@ import { v4 as uuid } from '@lukeed/uuid'; | ||
} | ||
track(event, properties = {}, type = 'track') { | ||
track(event, properties = {}, type = 'track', options = {}) { | ||
const e = { | ||
context: this.context.current('event'), | ||
context: { | ||
...this.context.current('event'), | ||
...options | ||
}, | ||
message_id: uuid(), | ||
@@ -16,0 +19,0 @@ type: type, |
@@ -5,3 +5,5 @@ export function initArcade(ko) { | ||
if (ko && event.data && event.data.eventName) { | ||
ko.track('Arcade ' + event.data.eventName, event.data); | ||
ko.track('Arcade ' + event.data.eventName, event.data, { | ||
source: 'arcade' | ||
}); | ||
} | ||
@@ -8,0 +10,0 @@ } |
@@ -20,3 +20,5 @@ import { when } from '../../lib/when'; | ||
ko.identify({ email: event.data.email }, { source: 'drift' }); | ||
ko.track('Drift Email Captured', event.data); | ||
ko.track('Drift Email Captured', event.data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -29,3 +31,5 @@ }); | ||
ko.identify({ phone: data.phone }, { source: 'drift' }); | ||
ko.track('Drift Phone Captured', data); | ||
ko.track('Drift Phone Captured', data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -47,3 +51,5 @@ }); | ||
} | ||
ko.track('Drift Conversation Started', data); | ||
ko.track('Drift Conversation Started', data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -55,3 +61,5 @@ }); | ||
if (ko && data) { | ||
ko.track('Drift Meeting Booked', data); | ||
ko.track('Drift Meeting Booked', data, { | ||
source: 'drift' | ||
}); | ||
} | ||
@@ -58,0 +66,0 @@ }); |
@@ -26,2 +26,4 @@ export function initHubSpot(ko) { | ||
meeting_date: (_f = booking.event) === null || _f === void 0 ? void 0 : _f.dateString | ||
}, { | ||
source: 'hubspot_meeting' | ||
}); | ||
@@ -28,0 +30,0 @@ } |
@@ -29,3 +29,5 @@ import { when } from '../../lib/when'; | ||
if (event.type) { | ||
ko.track('Navattic ' + (navattic_events[event.type] || event.type), event); | ||
ko.track('Navattic ' + (navattic_events[event.type] || event.type), event, { | ||
source: 'navattic' | ||
}); | ||
} | ||
@@ -32,0 +34,0 @@ } |
@@ -17,3 +17,5 @@ import { when } from '../../lib/when'; | ||
} | ||
ko.track('Qualified ' + name, data); | ||
ko.track('Qualified ' + name, data, { | ||
source: 'qualified' | ||
}); | ||
} | ||
@@ -20,0 +22,0 @@ catch (error) { |
@@ -9,2 +9,4 @@ import type { AnonymousProfile, QualificationResult } from './collect'; | ||
autotrack_qualified?: boolean; | ||
autotrack_fullstory?: boolean; | ||
autotrack_posthog_screen_recording?: boolean; | ||
segment_auto_track?: 'on' | 'off'; | ||
@@ -24,5 +26,6 @@ form_collection?: 'on' | 'off'; | ||
sdk_settings: SdkSettings; | ||
edge_api?: boolean; | ||
a?: AnonymousProfile | null; | ||
} | ||
export declare function bootstrap(slug: string, profileId?: string): Promise<BootstrapData>; | ||
export declare function bootstrap(publicKey: string, profileId?: string): Promise<BootstrapData>; | ||
export {}; |
import { fetchJson } from './fetch'; | ||
export async function bootstrap(slug, profileId) { | ||
let url = `/web/projects/${slug}`; | ||
export async function bootstrap(publicKey, profileId) { | ||
let url = `/web/projects/${publicKey}`; | ||
if (profileId) { | ||
@@ -5,0 +5,0 @@ url += `?profile_id=${profileId}`; |
@@ -30,8 +30,8 @@ import { AnalyticsCollector as KoalaSDK } from './analytics/collector'; | ||
/** | ||
* Fetches project settings | ||
* Fetches settings for public key | ||
*/ | ||
async function fetchSettings(project, profileId) { | ||
async function fetchSettings(publicKey, profileId) { | ||
var _a; | ||
try { | ||
const settings = await bootstrap(project, profileId); | ||
const settings = await bootstrap(publicKey, profileId); | ||
// Update the profile id in case it changed (or wasn't set yet) | ||
@@ -46,3 +46,3 @@ if (settings.profile_id) { | ||
}; | ||
return { ...settings, project }; | ||
return { ...settings, project: publicKey }; | ||
} | ||
@@ -49,0 +49,0 @@ catch (error) { |
@@ -9,5 +9,4 @@ import type { Consumer, Mixin, Subscription } from '@rails/actioncable'; | ||
rejected: () => void; | ||
updatePresence: (lastActivity?: string) => void; | ||
}; | ||
export declare function createProfileSubscription(client: Consumer, instance: AnalyticsCollector, onReceived: OnReceivedFn): ProfileSubscription; | ||
export {}; |
export function createProfileSubscription(client, instance, onReceived) { | ||
return client.subscriptions.create({ channel: 'ProfileChannel', sid: instance.session.id }, { | ||
isConnected: false, | ||
initialized() { | ||
this.updatePresence = this.updatePresence.bind(this); | ||
}, | ||
connected() { | ||
@@ -16,11 +13,2 @@ this.isConnected = true; | ||
}, | ||
updatePresence(lastActivityAt) { | ||
if (!this.isConnected || !lastActivityAt) | ||
return; | ||
this.perform('presence', { | ||
sid: instance.session.id, | ||
last_activity_at: lastActivityAt, | ||
visible: document.visibilityState === 'visible' | ||
}); | ||
}, | ||
received: onReceived | ||
@@ -27,0 +15,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
export declare const version = "1.17.0"; | ||
export declare const version = "1.20.0"; |
// This file is generated - DO NOT EDIT DIRECTLY. | ||
export const version = '1.17.0'; | ||
export const version = '1.20.0'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@getkoala/browser", | ||
"version": "1.17.0", | ||
"version": "1.20.0", | ||
"license": "UNLICENSED", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -51,3 +51,3 @@ /** | ||
window.ko?.ready(spy) | ||
window.ko?.on('change', spy) | ||
window.ko?.on('profile-update', spy) | ||
@@ -57,3 +57,3 @@ KoalaSDK.load({ project: 'test' }) | ||
setTimeout(() => { | ||
window.ko?.emit('change') | ||
window.ko?.emit('profile-update') | ||
expect(spy).toHaveBeenCalledTimes(2) | ||
@@ -60,0 +60,0 @@ done() |
import { build, CountMinSketchOptions } from '@getkoala/edge-api-client' | ||
import { RawProfile } from '@getkoala/edge-api-client/dist/raw-profile' | ||
import { CookieAttributes } from 'js-cookie' | ||
import throttle from 'lodash/throttle' | ||
import { BootstrapData } from '../api/bootstrap' | ||
@@ -33,5 +32,7 @@ import { | ||
import { initDrift } from './plugins/drift' | ||
import { initFullstory } from './plugins/fullstory' | ||
import { initHubSpot } from './plugins/hubspot' | ||
import { initIntercom } from './plugins/intercom' | ||
import { initNavattic } from './plugins/navattic' | ||
import { initPostHogScreenRecording } from './plugins/posthog-screen-recording' | ||
import { initQualified } from './plugins/qualified' | ||
@@ -49,2 +50,4 @@ import { Session, session } from './session' | ||
Intercom?: any | ||
FS?: any | ||
posthog?: any | ||
_hsq?: { push: (callParam: any) => void } | ||
@@ -95,7 +98,2 @@ _hstc_ran?: boolean | ||
initialized: [BootstrapData] | ||
open: [] | ||
close: [] | ||
'request-show': [] | ||
show: [] | ||
hide: [] | ||
track: [string, { [key: string]: unknown }] | ||
@@ -106,4 +104,2 @@ identify: [string | undefined, Record<string, unknown>] | ||
qualification: [Qualification] | ||
/** @deprecated */ | ||
change: [] | ||
} | ||
@@ -113,4 +109,2 @@ | ||
const interactionEvents = ['scroll', 'mousemove', 'click', 'touchstart', 'keypress'] | ||
function checkReferrer(referrers: string[]) { | ||
@@ -147,3 +141,2 @@ if (referrers.length === 0) return true | ||
private bootstrapData?: BootstrapData | ||
private lastActivityAt?: string | ||
private autocapture = true | ||
@@ -218,9 +211,2 @@ private referrerAllowed = true | ||
// capture tab regaining focus as interaction | ||
window.addEventListener('focus', this.touchLastActivityAt) | ||
interactionEvents.forEach((event) => { | ||
window.addEventListener(event, this.touchLastActivityAt, { capture: true, passive: true }) | ||
}) | ||
if (options.hookSegment !== false) { | ||
@@ -399,2 +385,4 @@ this.detectSegment() | ||
if (settings.autotrack_qualified) initQualified(this) | ||
if (settings.autotrack_fullstory) initFullstory(this) | ||
if (settings.autotrack_posthog_screen_recording) initPostHogScreenRecording(this) | ||
} | ||
@@ -464,18 +452,2 @@ | ||
public open() { | ||
this.emit('open') | ||
} | ||
public close() { | ||
this.emit('close') | ||
} | ||
public show() { | ||
this.emit('request-show') | ||
} | ||
public hide() { | ||
this.emit('hide') | ||
} | ||
public get session(): Session { | ||
@@ -489,13 +461,2 @@ return session.fetch(this.options.sdk_settings) | ||
private touchLastActivityAt = throttle(() => { | ||
if (document.visibilityState === 'visible') { | ||
this.lastActivityAt = new Date().toISOString() | ||
this.updatePresence() | ||
} | ||
}, 1_000) | ||
private updatePresence = throttle(() => { | ||
this.subscription?.updatePresence(this.lastActivityAt) | ||
}, 30_000) | ||
private detectHubspot() { | ||
@@ -653,7 +614,7 @@ const condition = () => window._hstc_ran && window._hsq && window._hsq.push !== Array.prototype.push | ||
async track(event: string, properties: { [key: string]: unknown } = {}) { | ||
async track(event: string, properties: { [key: string]: unknown } = {}, options?: EventOptions) { | ||
event = event.trim() | ||
if (!event || !this.referrerAllowed || !this.geoAllowed) return | ||
const type = event === '$submit' ? 'submit' : 'track' | ||
this.eventQueue.track(event, properties, type) | ||
this.eventQueue.track(event, properties, type, options) | ||
this.edge.index({ event, properties }) | ||
@@ -728,5 +689,6 @@ this.emit('track', event, properties) | ||
public subscribe() { | ||
if (!this.referrerAllowed || !this.geoAllowed || this.bootstrapData?.sdk_settings?.websocket_connection === 'off') { | ||
return | ||
} | ||
if (!this.referrerAllowed) return | ||
if (!this.geoAllowed) return | ||
if (this.bootstrapData?.sdk_settings?.websocket_connection === 'off') return | ||
if (this.bootstrapData?.edge_api === false) return | ||
@@ -781,3 +743,2 @@ this.when(() => Boolean(this.user.id())) | ||
this.emit('qualification', result) | ||
this.emit('change') | ||
@@ -854,3 +815,2 @@ if (a) { | ||
this.qualification = undefined | ||
this.lastActivityAt = undefined | ||
this.edge = build({}) | ||
@@ -857,0 +817,0 @@ |
import { v4 as uuid } from '@lukeed/uuid' | ||
import * as api from '../api/collect' | ||
import { Context, EventContext } from './event-context' | ||
import { Context, EventContext, EventOptions } from './event-context' | ||
import { Queue, QueueOptions } from './queue' | ||
@@ -26,5 +26,8 @@ | ||
track(event: string, properties: { [key: string]: unknown } = {}, type = 'track') { | ||
track(event: string, properties: { [key: string]: unknown } = {}, type = 'track', options: EventOptions = {}) { | ||
const e: Event = { | ||
context: this.context.current('event'), | ||
context: { | ||
...this.context.current('event'), | ||
...options | ||
}, | ||
message_id: uuid(), | ||
@@ -31,0 +34,0 @@ type: type, |
@@ -9,3 +9,5 @@ import type { AnalyticsCollector } from '../collector' | ||
if (ko && event.data && event.data.eventName) { | ||
ko.track('Arcade ' + event.data.eventName, event.data) | ||
ko.track('Arcade ' + event.data.eventName, event.data, { | ||
source: 'arcade' | ||
}) | ||
} | ||
@@ -12,0 +14,0 @@ } |
@@ -23,3 +23,5 @@ import { when } from '../../lib/when' | ||
ko.identify({ email: event.data.email }, { source: 'drift' }) | ||
ko.track('Drift Email Captured', event.data) | ||
ko.track('Drift Email Captured', event.data, { | ||
source: 'drift' | ||
}) | ||
} | ||
@@ -33,3 +35,5 @@ }) | ||
ko.identify({ phone: data.phone }, { source: 'drift' }) | ||
ko.track('Drift Phone Captured', data) | ||
ko.track('Drift Phone Captured', data, { | ||
source: 'drift' | ||
}) | ||
} | ||
@@ -54,3 +58,5 @@ }) | ||
} | ||
ko.track('Drift Conversation Started', data) | ||
ko.track('Drift Conversation Started', data, { | ||
source: 'drift' | ||
}) | ||
} | ||
@@ -63,3 +69,5 @@ }) | ||
if (ko && data) { | ||
ko.track('Drift Meeting Booked', data) | ||
ko.track('Drift Meeting Booked', data, { | ||
source: 'drift' | ||
}) | ||
} | ||
@@ -66,0 +74,0 @@ }) |
@@ -21,8 +21,14 @@ import type { AnalyticsCollector } from '../collector' | ||
} | ||
ko.track('Meeting Booked', { | ||
integration: 'HubSpot', | ||
contact, | ||
organizer: booking.postResponse?.organizer, | ||
meeting_date: booking.event?.dateString | ||
}) | ||
ko.track( | ||
'Meeting Booked', | ||
{ | ||
integration: 'HubSpot', | ||
contact, | ||
organizer: booking.postResponse?.organizer, | ||
meeting_date: booking.event?.dateString | ||
}, | ||
{ | ||
source: 'hubspot_meeting' | ||
} | ||
) | ||
} | ||
@@ -29,0 +35,0 @@ } catch (error) { |
@@ -39,3 +39,5 @@ import { when } from '../../lib/when' | ||
if (event.type) { | ||
ko.track('Navattic ' + (navattic_events[event.type] || event.type), event) | ||
ko.track('Navattic ' + (navattic_events[event.type] || event.type), event, { | ||
source: 'navattic' | ||
}) | ||
} | ||
@@ -42,0 +44,0 @@ } catch (error) { |
@@ -21,3 +21,5 @@ import { when } from '../../lib/when' | ||
ko.track('Qualified ' + name, data) | ||
ko.track('Qualified ' + name, data, { | ||
source: 'qualified' | ||
}) | ||
} catch (error) { | ||
@@ -24,0 +26,0 @@ ko?.trackError(error as Error, 'qualified.handleEvents') |
@@ -11,2 +11,4 @@ import type { AnonymousProfile, QualificationResult } from './collect' | ||
autotrack_qualified?: boolean | ||
autotrack_fullstory?: boolean | ||
autotrack_posthog_screen_recording?: boolean | ||
segment_auto_track?: 'on' | 'off' | ||
@@ -27,7 +29,8 @@ form_collection?: 'on' | 'off' | ||
sdk_settings: SdkSettings | ||
edge_api?: boolean | ||
a?: AnonymousProfile | null | ||
} | ||
export async function bootstrap(slug: string, profileId?: string): Promise<BootstrapData> { | ||
let url = `/web/projects/${slug}` | ||
export async function bootstrap(publicKey: string, profileId?: string): Promise<BootstrapData> { | ||
let url = `/web/projects/${publicKey}` | ||
if (profileId) { | ||
@@ -34,0 +37,0 @@ url += `?profile_id=${profileId}` |
@@ -39,7 +39,7 @@ import { AnalyticsCollector as KoalaSDK, type Options } from './analytics/collector' | ||
/** | ||
* Fetches project settings | ||
* Fetches settings for public key | ||
*/ | ||
async function fetchSettings(project: string, profileId: string | undefined): Promise<ProjectSettings> { | ||
async function fetchSettings(publicKey: string, profileId: string | undefined): Promise<ProjectSettings> { | ||
try { | ||
const settings = await bootstrap(project, profileId) | ||
const settings = await bootstrap(publicKey, profileId) | ||
@@ -57,3 +57,3 @@ // Update the profile id in case it changed (or wasn't set yet) | ||
return { ...settings, project } | ||
return { ...settings, project: publicKey } | ||
} catch (error) { | ||
@@ -60,0 +60,0 @@ console.warn('[KOALA]', 'Failed to load project settings', error) |
@@ -12,3 +12,2 @@ import type { Consumer, Mixin, Subscription } from '@rails/actioncable' | ||
rejected: () => void | ||
updatePresence: (lastActivity?: string) => void | ||
} | ||
@@ -25,5 +24,2 @@ | ||
isConnected: false, | ||
initialized() { | ||
this.updatePresence = this.updatePresence.bind(this) | ||
}, | ||
connected() { | ||
@@ -38,10 +34,2 @@ this.isConnected = true | ||
}, | ||
updatePresence(lastActivityAt?: string) { | ||
if (!this.isConnected || !lastActivityAt) return | ||
this.perform('presence', { | ||
sid: instance.session.id, | ||
last_activity_at: lastActivityAt, | ||
visible: document.visibilityState === 'visible' | ||
}) | ||
}, | ||
received: onReceived | ||
@@ -48,0 +36,0 @@ } |
// This file is generated - DO NOT EDIT DIRECTLY. | ||
export const version = '1.17.0' | ||
export const version = '1.20.0' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1125235
376
16506