lytx 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +37 -0
- package/README.md +486 -0
- package/alchemy.run.ts +155 -0
- package/cli/bootstrap-admin.ts +284 -0
- package/cli/deploy-staging.ts +692 -0
- package/cli/import-events.ts +628 -0
- package/cli/import-sites.ts +518 -0
- package/cli/index.ts +609 -0
- package/cli/init-db.ts +269 -0
- package/cli/migrate-to-durable-objects.ts +564 -0
- package/cli/migration-worker.ts +300 -0
- package/cli/performance-test.ts +588 -0
- package/cli/pg/client.ts +4 -0
- package/cli/pg/new-site.ts +153 -0
- package/cli/rollback-durable-objects.ts +622 -0
- package/cli/seed-data.ts +459 -0
- package/cli/setup.js +18 -0
- package/cli/setup.ts +463 -0
- package/cli/validate-migration.ts +200 -0
- package/cli/wrangler-migration.jsonc +28 -0
- package/db/adapter.ts +166 -0
- package/db/analytics_engine/client.ts +0 -0
- package/db/analytics_engine/sites.ts +0 -0
- package/db/client.ts +16 -0
- package/db/d1/client.ts +8 -0
- package/db/d1/drizzle.config.ts +35 -0
- package/db/d1/migrations/0000_true_maelstrom.sql +165 -0
- package/db/d1/migrations/0001_wonderful_bloodaxe.sql +12 -0
- package/db/d1/migrations/0002_late_frightful_four.sql +1 -0
- package/db/d1/migrations/0003_cuddly_obadiah_stane.sql +16 -0
- package/db/d1/migrations/0004_mute_stardust.sql +1 -0
- package/db/d1/migrations/0005_awesome_silvermane.sql +3 -0
- package/db/d1/migrations/0006_volatile_shriek.sql +2 -0
- package/db/d1/migrations/0007_superb_lila_cheney.sql +1 -0
- package/db/d1/migrations/0008_bitter_longshot.sql +17 -0
- package/db/d1/migrations/0009_wonderful_madame_masque.sql +28 -0
- package/db/d1/migrations/meta/0000_snapshot.json +1112 -0
- package/db/d1/migrations/meta/0001_snapshot.json +1187 -0
- package/db/d1/migrations/meta/0002_snapshot.json +1194 -0
- package/db/d1/migrations/meta/0003_snapshot.json +1296 -0
- package/db/d1/migrations/meta/0004_snapshot.json +1303 -0
- package/db/d1/migrations/meta/0005_snapshot.json +1325 -0
- package/db/d1/migrations/meta/0006_snapshot.json +1339 -0
- package/db/d1/migrations/meta/0007_snapshot.json +1347 -0
- package/db/d1/migrations/meta/0008_snapshot.json +1464 -0
- package/db/d1/migrations/meta/0009_snapshot.json +1648 -0
- package/db/d1/migrations/meta/_journal.json +76 -0
- package/db/d1/schema.ts +407 -0
- package/db/d1/sites.ts +374 -0
- package/db/d1/teamAiUsage.ts +101 -0
- package/db/d1/teams.ts +127 -0
- package/db/durable/drizzle.config.ts +8 -0
- package/db/durable/durableObjectClient.ts +480 -0
- package/db/durable/events.ts +100 -0
- package/db/durable/migrations/0000_fair_bucky.sql +38 -0
- package/db/durable/migrations/meta/0000_snapshot.json +278 -0
- package/db/durable/migrations/meta/_journal.json +13 -0
- package/db/durable/migrations/migrations.js +10 -0
- package/db/durable/schema.ts +5 -0
- package/db/durable/siteDurableObject.ts +1352 -0
- package/db/durable/types.ts +53 -0
- package/db/postgres/client.ts +13 -0
- package/db/postgres/drizzle.config.ts +12 -0
- package/db/postgres/migrations/0000_brainy_sprite.sql +116 -0
- package/db/postgres/migrations/meta/0000_snapshot.json +681 -0
- package/db/postgres/migrations/meta/_journal.json +13 -0
- package/db/postgres/schema.ts +145 -0
- package/db/postgres/sites.ts +118 -0
- package/db/tranformReports.ts +595 -0
- package/db/types.ts +55 -0
- package/endpoints/api_worker.tsx +1854 -0
- package/endpoints/site_do_worker.ts +11 -0
- package/index.d.ts +63 -0
- package/index.ts +83 -0
- package/lib/auth.ts +279 -0
- package/lib/geojson/world_countries.json +45307 -0
- package/lib/random_name.ts +41 -0
- package/lib/sendMail.ts +252 -0
- package/package.json +142 -0
- package/public/favicon.ico +0 -0
- package/public/images/android-chrome-192x192.png +0 -0
- package/public/images/android-chrome-512x512.png +0 -0
- package/public/images/apple-touch-icon.png +0 -0
- package/public/images/favicon-16x16.png +0 -0
- package/public/images/favicon-32x32.png +0 -0
- package/public/images/lytx_dark_dashboard.png +0 -0
- package/public/images/lytx_light_dashboard.png +0 -0
- package/public/images/safari-pinned-tab.svg +4 -0
- package/public/logo.png +0 -0
- package/public/site.webmanifest +26 -0
- package/public/sw.js +107 -0
- package/src/Document.tsx +86 -0
- package/src/api/ai_api.ts +1156 -0
- package/src/api/authMiddleware.ts +45 -0
- package/src/api/auth_api.ts +465 -0
- package/src/api/event_labels_api.ts +193 -0
- package/src/api/events_api.ts +210 -0
- package/src/api/queueWorker.ts +303 -0
- package/src/api/reports_api.ts +278 -0
- package/src/api/seed_api.ts +288 -0
- package/src/api/sites_api.ts +904 -0
- package/src/api/tag_api.ts +458 -0
- package/src/api/tag_api_v2.ts +289 -0
- package/src/api/team_api.ts +456 -0
- package/src/app/Dashboard.tsx +1339 -0
- package/src/app/Events.tsx +974 -0
- package/src/app/Explore.tsx +312 -0
- package/src/app/Layout.tsx +58 -0
- package/src/app/Settings.tsx +1302 -0
- package/src/app/components/DashboardCard.tsx +118 -0
- package/src/app/components/EditableCell.tsx +123 -0
- package/src/app/components/EventForm.tsx +93 -0
- package/src/app/components/MarketingFooter.tsx +49 -0
- package/src/app/components/MarketingNav.tsx +150 -0
- package/src/app/components/Nav.tsx +755 -0
- package/src/app/components/NewSiteSetup.tsx +298 -0
- package/src/app/components/SQLEditor.tsx +740 -0
- package/src/app/components/SiteSelector.tsx +126 -0
- package/src/app/components/SiteTag.tsx +42 -0
- package/src/app/components/SiteTagInstallCard.tsx +241 -0
- package/src/app/components/WorldMapCard.tsx +337 -0
- package/src/app/components/charts/ChartComponents.tsx +1481 -0
- package/src/app/components/charts/EventFunnel.tsx +45 -0
- package/src/app/components/charts/EventSummary.tsx +194 -0
- package/src/app/components/charts/SankeyFlows.tsx +72 -0
- package/src/app/components/marketing/CheckIcon.tsx +16 -0
- package/src/app/components/marketing/MarketingLayout.tsx +23 -0
- package/src/app/components/marketing/SectionHeading.tsx +35 -0
- package/src/app/components/reports/AskAiWorkspace.tsx +371 -0
- package/src/app/components/reports/CreateReportStarter.tsx +74 -0
- package/src/app/components/reports/DashboardRouteFiltersContext.tsx +14 -0
- package/src/app/components/reports/DashboardToolbar.tsx +154 -0
- package/src/app/components/reports/DashboardWorkspaceLayout.tsx +63 -0
- package/src/app/components/reports/DashboardWorkspaceShell.tsx +118 -0
- package/src/app/components/reports/ReportBuilderWorkspace.tsx +76 -0
- package/src/app/components/reports/custom/CustomReportBuilderPage.tsx +1667 -0
- package/src/app/components/reports/custom/ReportWidgetChart.tsx +297 -0
- package/src/app/components/reports/custom/buildWidgetSql.ts +151 -0
- package/src/app/components/reports/custom/chartPalettes.ts +18 -0
- package/src/app/components/reports/custom/types.ts +50 -0
- package/src/app/components/reports/reportBuilderMenuItems.ts +17 -0
- package/src/app/components/reports/useDashboardToolbarControls.tsx +235 -0
- package/src/app/components/ui/AlertBanner.tsx +101 -0
- package/src/app/components/ui/Button.tsx +55 -0
- package/src/app/components/ui/Card.tsx +80 -0
- package/src/app/components/ui/Input.tsx +72 -0
- package/src/app/components/ui/Link.tsx +23 -0
- package/src/app/components/ui/ReportBuilderMenu.tsx +246 -0
- package/src/app/components/ui/ThemeToggle.tsx +54 -0
- package/src/app/constants.ts +6 -0
- package/src/app/headers.ts +33 -0
- package/src/app/providers/AuthProvider.tsx +189 -0
- package/src/app/providers/ClientProviders.tsx +18 -0
- package/src/app/providers/QueryProvider.tsx +23 -0
- package/src/app/providers/ThemeProvider.tsx +88 -0
- package/src/app/utils/chartThemes.ts +146 -0
- package/src/app/utils/keybinds.ts +96 -0
- package/src/app/utils/media.tsx +24 -0
- package/src/client.tsx +114 -0
- package/src/config/createLytxAppConfig.ts +252 -0
- package/src/config/resourceNames.ts +88 -0
- package/src/db/index.ts +67 -0
- package/src/index.css +285 -0
- package/src/lib/featureFlags.ts +69 -0
- package/src/pages/GetStarted.tsx +290 -0
- package/src/pages/Home.tsx +268 -0
- package/src/pages/Login.tsx +283 -0
- package/src/pages/PrivacyPolicy.tsx +120 -0
- package/src/pages/Signup.tsx +267 -0
- package/src/pages/TermsOfService.tsx +126 -0
- package/src/pages/VerifyEmail.tsx +56 -0
- package/src/session/durableObject.ts +7 -0
- package/src/session/siteSchema.ts +86 -0
- package/src/session/types.ts +36 -0
- package/src/templates/README.md +80 -0
- package/src/templates/cleanFunctions.js +44 -0
- package/src/templates/embedFunctions.js +52 -0
- package/src/templates/lytx-shared.ts +662 -0
- package/src/templates/lytxpixel-core.ts +144 -0
- package/src/templates/lytxpixel.ts +267 -0
- package/src/templates/lytxpixelBrowser.js +634 -0
- package/src/templates/lytxpixelBrowser.mjs +634 -0
- package/src/templates/parseData.js +12 -0
- package/src/templates/script.ts +31 -0
- package/src/templates/template.tsx +50 -0
- package/src/templates/test.js +3 -0
- package/src/templates/trackWebEvents.ts +177 -0
- package/src/templates/vendors/clickcease.ts +8 -0
- package/src/templates/vendors/google.ts +174 -0
- package/src/templates/vendors/linkedin.ts +23 -0
- package/src/templates/vendors/meta.ts +56 -0
- package/src/templates/vendors/quantcast.ts +22 -0
- package/src/templates/vendors/simplfi.ts +7 -0
- package/src/types/app-context.ts +16 -0
- package/src/utilities/dashboardParams.ts +188 -0
- package/src/utilities/dashboardQueries.ts +537 -0
- package/src/utilities/dashboardTransforms.ts +167 -0
- package/src/utilities/dataValidation.ts +414 -0
- package/src/utilities/detector.ts +73 -0
- package/src/utilities/encrypt.ts +103 -0
- package/src/utilities/index.ts +13 -0
- package/src/utilities/parser.ts +117 -0
- package/src/utilities/performanceMonitoring.ts +570 -0
- package/src/utilities/route_interuptors.ts +24 -0
- package/src/worker.tsx +675 -0
- package/tsconfig.json +78 -0
- package/types/env.d.ts +16 -0
- package/types/rw.d.ts +7 -0
- package/types/shims.d.ts +53 -0
- package/types/vite.d.ts +19 -0
- package/vite/vite-plugin-pixel-bundle.ts +126 -0
- package/vite.config.ts +53 -0
- package/worker-configuration.d.ts +8401 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lytx Script - Core Version (No Third-Party Vendors)
|
|
3
|
+
*
|
|
4
|
+
* This version excludes all third-party vendor integrations.
|
|
5
|
+
* Use this when tag_manager is disabled.
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
type PageEventCore,
|
|
9
|
+
type paramConfig,
|
|
10
|
+
updateEventRecord,
|
|
11
|
+
trackCustomRecord,
|
|
12
|
+
handleParameters,
|
|
13
|
+
handleParseConfig,
|
|
14
|
+
waitForAllElements,
|
|
15
|
+
waitForElement,
|
|
16
|
+
splitQueryParams,
|
|
17
|
+
createParseData,
|
|
18
|
+
} from "./lytx-shared";
|
|
19
|
+
|
|
20
|
+
// Re-export types for external use
|
|
21
|
+
export type { PageEventCore as PageEvent } from "./lytx-shared";
|
|
22
|
+
|
|
23
|
+
// ============================================================================
|
|
24
|
+
// Core-specific handlers (no vendor calls)
|
|
25
|
+
// ============================================================================
|
|
26
|
+
|
|
27
|
+
function handleThirdPartyConfigScripts(ev: PageEventCore) {
|
|
28
|
+
// Third-party vendor scripts are disabled in core version
|
|
29
|
+
if (window.lytxApi.debugMode) {
|
|
30
|
+
console.debug('Third-party vendor scripts disabled (core version)');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function handleInteraction(ev: PageEventCore) {
|
|
35
|
+
updateEventRecord(ev);
|
|
36
|
+
trackCustomRecord(ev);
|
|
37
|
+
// No vendor calls in core version
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function handleRule(ev: PageEventCore, type: "interaction" | "url") {
|
|
41
|
+
const { rules, paramConfig } = ev;
|
|
42
|
+
|
|
43
|
+
let queryAll = false;
|
|
44
|
+
const delay = { enabled: false, amount: 0 };
|
|
45
|
+
let iframe = false;
|
|
46
|
+
let parseConfig: paramConfig | null = null;
|
|
47
|
+
|
|
48
|
+
const elemParams = handleParameters(ev);
|
|
49
|
+
if (window.lytxApi.debugMode) {
|
|
50
|
+
console.debug("Auto-capture rule registered", { rule: rules, selector: elemParams, event_name: ev.event_name });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (paramConfig) {
|
|
54
|
+
const checkConfig = handleParseConfig(ev);
|
|
55
|
+
parseConfig = checkConfig.parseConfig;
|
|
56
|
+
iframe = checkConfig.iframe;
|
|
57
|
+
delay.amount = checkConfig.delay.amount;
|
|
58
|
+
delay.enabled = checkConfig.delay.enabled;
|
|
59
|
+
if (parseConfig) {
|
|
60
|
+
if (parseConfig.querySelectorAll) {
|
|
61
|
+
if (parseConfig.querySelectorAll == 'all') {
|
|
62
|
+
queryAll = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (rules == "click") {
|
|
69
|
+
if (queryAll) {
|
|
70
|
+
waitForAllElements(elemParams, (elements) => {
|
|
71
|
+
elements.forEach((element, index) => {
|
|
72
|
+
if (parseConfig && typeof parseConfig.querySelectorAll != "boolean" && typeof parseConfig.querySelectorAll != "string") {
|
|
73
|
+
let querySelecIndex = parseConfig.querySelectorAll
|
|
74
|
+
if (querySelecIndex != index) return;
|
|
75
|
+
}
|
|
76
|
+
element.addEventListener('click', () => {
|
|
77
|
+
handleInteraction(ev);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
waitForElement(elemParams, (element) => {
|
|
83
|
+
element.addEventListener("click", () => {
|
|
84
|
+
handleInteraction(ev);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (rules == "submit") {
|
|
91
|
+
waitForElement(elemParams, (element) => {
|
|
92
|
+
element.addEventListener("submit", () => {
|
|
93
|
+
handleInteraction(ev);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function handleCondition(ev: PageEventCore, url: URL) {
|
|
100
|
+
const { condition, parameters } = ev;
|
|
101
|
+
if (window.lytxApi.debugMode) {
|
|
102
|
+
console.info(`Handling condition for condition ${ev.condition} and event ${ev.event_name}`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (condition == "path") {
|
|
106
|
+
if (parameters == "*") {
|
|
107
|
+
handleThirdPartyConfigScripts(ev);
|
|
108
|
+
} else {
|
|
109
|
+
const parsedUrl = url ?? new URL(window.location.href);
|
|
110
|
+
const path = (url && url.pathname) ? url.pathname : window.location.pathname;
|
|
111
|
+
const queryParams = parsedUrl.searchParams;
|
|
112
|
+
let queryParamCheck = true;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
if (ev.query_parameters) {
|
|
116
|
+
if (ev.query_parameters.includes('&')) {
|
|
117
|
+
let split = ev.query_parameters.split('&');
|
|
118
|
+
queryParamCheck = splitQueryParams(split, queryParams);
|
|
119
|
+
} else {
|
|
120
|
+
queryParamCheck = splitQueryParams(ev.query_parameters, queryParams);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch (error) {
|
|
124
|
+
queryParamCheck = true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (path.includes(ev.parameters) && queryParamCheck) {
|
|
128
|
+
updateEventRecord(ev);
|
|
129
|
+
// No vendor calls in core version
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
} else if (condition == "dom element" || condition == "element") {
|
|
133
|
+
handleRule(ev, "interaction");
|
|
134
|
+
} else if (condition == "form field filled") {
|
|
135
|
+
// Form field filled handler
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ============================================================================
|
|
140
|
+
// Export parseData and trackEvents
|
|
141
|
+
// ============================================================================
|
|
142
|
+
|
|
143
|
+
export const parseData = createParseData(handleCondition, " (core version - no third-party vendors)");
|
|
144
|
+
export { trackEvents } from "./trackWebEvents";
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lytx Script - Full Version (With Third-Party Vendors)
|
|
3
|
+
*
|
|
4
|
+
* This version includes all third-party vendor integrations.
|
|
5
|
+
* Use this when tag_manager is enabled.
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
type PageEvent,
|
|
9
|
+
type paramConfig,
|
|
10
|
+
createScriptElement,
|
|
11
|
+
customScript,
|
|
12
|
+
updateEventRecord,
|
|
13
|
+
trackCustomRecord,
|
|
14
|
+
handleParameters,
|
|
15
|
+
handleParseConfig,
|
|
16
|
+
waitForAllElements,
|
|
17
|
+
waitForElement,
|
|
18
|
+
splitQueryParams,
|
|
19
|
+
createParseData,
|
|
20
|
+
} from "./lytx-shared";
|
|
21
|
+
|
|
22
|
+
// Re-export types for external use
|
|
23
|
+
export type { PageEvent, LytxEvent, rule, condition, eventName, dataPassback, paramConfig, userInteraction } from "./lytx-shared";
|
|
24
|
+
|
|
25
|
+
// Vendor imports
|
|
26
|
+
import type { GoogleConversionParams } from "./vendors/google";
|
|
27
|
+
import { googleTagScript, googleConversion, manualGoogleConversion } from "./vendors/google";
|
|
28
|
+
import { quantcastScript } from "./vendors/quantcast";
|
|
29
|
+
import { simplfiScript } from "./vendors/simplfi";
|
|
30
|
+
import { metaScript } from "./vendors/meta";
|
|
31
|
+
import { linkedinScript } from "./vendors/linkedin";
|
|
32
|
+
import { clickCeaseScript } from "./vendors/clickcease";
|
|
33
|
+
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Vendor-specific handlers
|
|
36
|
+
// ============================================================================
|
|
37
|
+
|
|
38
|
+
function handleIframe(config: { callback: { func: Function, arguments?: Array<any> }, element: HTMLElement, debug: boolean, name: string }) {
|
|
39
|
+
window.addEventListener('blur', function() {
|
|
40
|
+
window.setTimeout(function() {
|
|
41
|
+
if (config.element && document.activeElement instanceof HTMLIFrameElement) {
|
|
42
|
+
if (config.debug) {
|
|
43
|
+
console.log('Debug Iframe element is : ', config.element, document.activeElement);
|
|
44
|
+
}
|
|
45
|
+
if (config.callback && document.activeElement == config.element) {
|
|
46
|
+
if (config.debug) console.log(config.element, `Iframe Has been tracked correctly event name is ${config.name ?? ''}`);
|
|
47
|
+
if (config.callback.arguments) {
|
|
48
|
+
config.callback.func(...config.callback.arguments);
|
|
49
|
+
} else {
|
|
50
|
+
config.callback.func();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, 0);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function handleThirdPartyConfigScripts(ev: PageEvent) {
|
|
59
|
+
const { metaEvent, linkedinEvent, SimplfiPixelid, googleadsscript, googleanalytics, clickCease, QuantcastPixelId, googleadsconversion } = ev;
|
|
60
|
+
|
|
61
|
+
if (metaEvent) {
|
|
62
|
+
metaScript({ metaId: ev.metaEvent, scriptInit: true });
|
|
63
|
+
}
|
|
64
|
+
if (linkedinEvent) {
|
|
65
|
+
linkedinScript(linkedinEvent);
|
|
66
|
+
}
|
|
67
|
+
if (SimplfiPixelid) {
|
|
68
|
+
const newScript = simplfiScript(SimplfiPixelid);
|
|
69
|
+
createScriptElement(newScript.src, newScript.async);
|
|
70
|
+
}
|
|
71
|
+
if (googleanalytics) {
|
|
72
|
+
const newScript = googleTagScript(googleanalytics);
|
|
73
|
+
createScriptElement(newScript.src, true);
|
|
74
|
+
newScript.callBack(newScript.id);
|
|
75
|
+
}
|
|
76
|
+
if (QuantcastPixelId) {
|
|
77
|
+
const newScript = quantcastScript();
|
|
78
|
+
createScriptElement(newScript.src, true);
|
|
79
|
+
newScript.callBack(QuantcastPixelId);
|
|
80
|
+
}
|
|
81
|
+
if (clickCease && clickCease == "enabled") {
|
|
82
|
+
const newScript = clickCeaseScript();
|
|
83
|
+
createScriptElement(newScript.src, newScript.async, newScript.type);
|
|
84
|
+
}
|
|
85
|
+
if (googleadsscript) {
|
|
86
|
+
const newScript = googleTagScript(googleadsscript);
|
|
87
|
+
createScriptElement(newScript.src, true);
|
|
88
|
+
newScript.callBack(newScript.id);
|
|
89
|
+
}
|
|
90
|
+
if (ev.customScript) {
|
|
91
|
+
customScript(ev.customScript);
|
|
92
|
+
}
|
|
93
|
+
if (googleadsconversion) {
|
|
94
|
+
try {
|
|
95
|
+
const parsedValue = JSON.parse(googleadsconversion) as GoogleConversionParams[];
|
|
96
|
+
parsedValue.forEach((val) =>
|
|
97
|
+
googleConversion(val.GoogleCommand, val.id, val.type, val.value)
|
|
98
|
+
);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.log(error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function handleInteraction(ev: PageEvent) {
|
|
106
|
+
const { metaEvent, linkedinEvent, SimplfiPixelid, googleadsscript, googleanalytics, clickCease, QuantcastPixelId, QuantCastPixelLabel, googleadsconversion } = ev;
|
|
107
|
+
|
|
108
|
+
updateEventRecord(ev);
|
|
109
|
+
trackCustomRecord(ev);
|
|
110
|
+
|
|
111
|
+
if (metaEvent) {
|
|
112
|
+
metaScript({ metaId: ev.metaEvent, eventName: ev.event_name });
|
|
113
|
+
}
|
|
114
|
+
if (linkedinEvent) {
|
|
115
|
+
if (linkedinEvent != undefined) linkedinScript(linkedinEvent);
|
|
116
|
+
}
|
|
117
|
+
if (SimplfiPixelid) {
|
|
118
|
+
const newScript = simplfiScript(SimplfiPixelid);
|
|
119
|
+
createScriptElement(newScript.src, newScript.async);
|
|
120
|
+
}
|
|
121
|
+
if (googleanalytics) {
|
|
122
|
+
// Google Analytics handled elsewhere
|
|
123
|
+
}
|
|
124
|
+
if (QuantcastPixelId && QuantCastPixelLabel) {
|
|
125
|
+
const newQEvent = quantcastScript(QuantCastPixelLabel);
|
|
126
|
+
newQEvent.callBack(QuantcastPixelId);
|
|
127
|
+
}
|
|
128
|
+
if (clickCease && clickCease == "enabled") {
|
|
129
|
+
// ClickCease handled elsewhere
|
|
130
|
+
}
|
|
131
|
+
if (googleadsscript) {
|
|
132
|
+
// Google Ads Script handled elsewhere
|
|
133
|
+
}
|
|
134
|
+
if (googleadsconversion) {
|
|
135
|
+
try {
|
|
136
|
+
const parsedValue = JSON.parse(googleadsconversion) as GoogleConversionParams[];
|
|
137
|
+
for (const val of parsedValue) {
|
|
138
|
+
manualGoogleConversion(val.id, { value: val.value });
|
|
139
|
+
}
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.warn(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function handleRule(ev: PageEvent, type: "interaction" | "url") {
|
|
147
|
+
const { rules, paramConfig } = ev;
|
|
148
|
+
|
|
149
|
+
let queryAll = false;
|
|
150
|
+
const delay = { enabled: false, amount: 0 };
|
|
151
|
+
let iframe = false;
|
|
152
|
+
let parseConfig: paramConfig | null = null;
|
|
153
|
+
|
|
154
|
+
const elemParams = handleParameters(ev);
|
|
155
|
+
if (window.lytxApi.debugMode) {
|
|
156
|
+
console.debug("Auto-capture rule registered", { rule: rules, selector: elemParams, event_name: ev.event_name });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (paramConfig) {
|
|
160
|
+
const checkConfig = handleParseConfig(ev);
|
|
161
|
+
parseConfig = checkConfig.parseConfig;
|
|
162
|
+
iframe = checkConfig.iframe;
|
|
163
|
+
delay.amount = checkConfig.delay.amount;
|
|
164
|
+
delay.enabled = checkConfig.delay.enabled;
|
|
165
|
+
if (parseConfig) {
|
|
166
|
+
if (parseConfig.querySelectorAll) {
|
|
167
|
+
if (parseConfig.querySelectorAll == 'all') {
|
|
168
|
+
queryAll = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (rules == "click") {
|
|
175
|
+
if (queryAll) {
|
|
176
|
+
waitForAllElements(elemParams, (elements) => {
|
|
177
|
+
elements.forEach((element, index) => {
|
|
178
|
+
if (parseConfig && typeof parseConfig.querySelectorAll != "boolean" && typeof parseConfig.querySelectorAll != "string") {
|
|
179
|
+
let querySelecIndex = parseConfig.querySelectorAll
|
|
180
|
+
if (querySelecIndex != index) return;
|
|
181
|
+
}
|
|
182
|
+
element.addEventListener('click', () => {
|
|
183
|
+
handleInteraction(ev);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
188
|
+
waitForElement(elemParams, (element) => {
|
|
189
|
+
element.addEventListener("click", () => {
|
|
190
|
+
handleInteraction(ev);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (rules == "submit") {
|
|
197
|
+
waitForElement(elemParams, (element) => {
|
|
198
|
+
element.addEventListener("submit", () => {
|
|
199
|
+
handleInteraction(ev);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function handleCondition(ev: PageEvent, url: URL) {
|
|
206
|
+
const { condition, parameters } = ev;
|
|
207
|
+
if (window.lytxApi.debugMode) {
|
|
208
|
+
console.info(`Handling condition for condition ${ev.condition} and event ${ev.event_name}`);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (condition == "path") {
|
|
212
|
+
if (parameters == "*") {
|
|
213
|
+
handleThirdPartyConfigScripts(ev);
|
|
214
|
+
} else {
|
|
215
|
+
const parsedUrl = url ?? new URL(window.location.href);
|
|
216
|
+
const path = (url && url.pathname) ? url.pathname : window.location.pathname;
|
|
217
|
+
const queryParams = parsedUrl.searchParams;
|
|
218
|
+
let queryParamCheck = true;
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
if (ev.query_parameters) {
|
|
222
|
+
if (ev.query_parameters.includes('&')) {
|
|
223
|
+
let split = ev.query_parameters.split('&');
|
|
224
|
+
queryParamCheck = splitQueryParams(split, queryParams);
|
|
225
|
+
} else {
|
|
226
|
+
queryParamCheck = splitQueryParams(ev.query_parameters, queryParams);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
} catch (error) {
|
|
230
|
+
queryParamCheck = true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (path.includes(ev.parameters) && queryParamCheck) {
|
|
234
|
+
if (ev.SimplfiPixelid) {
|
|
235
|
+
const newScript = simplfiScript(ev.SimplfiPixelid);
|
|
236
|
+
createScriptElement(newScript.src, newScript.async);
|
|
237
|
+
updateEventRecord(ev);
|
|
238
|
+
}
|
|
239
|
+
if (ev.QuantcastPixelId && ev.QuantCastPixelLabel) {
|
|
240
|
+
const newQEvent = quantcastScript(ev.QuantCastPixelLabel);
|
|
241
|
+
newQEvent.callBack(ev.QuantcastPixelId);
|
|
242
|
+
}
|
|
243
|
+
if (ev.googleadsconversion) {
|
|
244
|
+
try {
|
|
245
|
+
const parsedValue = JSON.parse(ev.googleadsconversion) as GoogleConversionParams[];
|
|
246
|
+
parsedValue.forEach((val) =>
|
|
247
|
+
googleConversion(val.GoogleCommand, val.id, val.type, val.value)
|
|
248
|
+
);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
console.log(error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} else if (condition == "dom element" || condition == "element") {
|
|
256
|
+
handleRule(ev, "interaction");
|
|
257
|
+
} else if (condition == "form field filled") {
|
|
258
|
+
// Form field filled handler
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ============================================================================
|
|
263
|
+
// Export parseData and trackEvents
|
|
264
|
+
// ============================================================================
|
|
265
|
+
|
|
266
|
+
export const parseData = createParseData(handleCondition, "");
|
|
267
|
+
export { trackEvents } from "./trackWebEvents";
|