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.
Files changed (213) hide show
  1. package/.env.example +37 -0
  2. package/README.md +486 -0
  3. package/alchemy.run.ts +155 -0
  4. package/cli/bootstrap-admin.ts +284 -0
  5. package/cli/deploy-staging.ts +692 -0
  6. package/cli/import-events.ts +628 -0
  7. package/cli/import-sites.ts +518 -0
  8. package/cli/index.ts +609 -0
  9. package/cli/init-db.ts +269 -0
  10. package/cli/migrate-to-durable-objects.ts +564 -0
  11. package/cli/migration-worker.ts +300 -0
  12. package/cli/performance-test.ts +588 -0
  13. package/cli/pg/client.ts +4 -0
  14. package/cli/pg/new-site.ts +153 -0
  15. package/cli/rollback-durable-objects.ts +622 -0
  16. package/cli/seed-data.ts +459 -0
  17. package/cli/setup.js +18 -0
  18. package/cli/setup.ts +463 -0
  19. package/cli/validate-migration.ts +200 -0
  20. package/cli/wrangler-migration.jsonc +28 -0
  21. package/db/adapter.ts +166 -0
  22. package/db/analytics_engine/client.ts +0 -0
  23. package/db/analytics_engine/sites.ts +0 -0
  24. package/db/client.ts +16 -0
  25. package/db/d1/client.ts +8 -0
  26. package/db/d1/drizzle.config.ts +35 -0
  27. package/db/d1/migrations/0000_true_maelstrom.sql +165 -0
  28. package/db/d1/migrations/0001_wonderful_bloodaxe.sql +12 -0
  29. package/db/d1/migrations/0002_late_frightful_four.sql +1 -0
  30. package/db/d1/migrations/0003_cuddly_obadiah_stane.sql +16 -0
  31. package/db/d1/migrations/0004_mute_stardust.sql +1 -0
  32. package/db/d1/migrations/0005_awesome_silvermane.sql +3 -0
  33. package/db/d1/migrations/0006_volatile_shriek.sql +2 -0
  34. package/db/d1/migrations/0007_superb_lila_cheney.sql +1 -0
  35. package/db/d1/migrations/0008_bitter_longshot.sql +17 -0
  36. package/db/d1/migrations/0009_wonderful_madame_masque.sql +28 -0
  37. package/db/d1/migrations/meta/0000_snapshot.json +1112 -0
  38. package/db/d1/migrations/meta/0001_snapshot.json +1187 -0
  39. package/db/d1/migrations/meta/0002_snapshot.json +1194 -0
  40. package/db/d1/migrations/meta/0003_snapshot.json +1296 -0
  41. package/db/d1/migrations/meta/0004_snapshot.json +1303 -0
  42. package/db/d1/migrations/meta/0005_snapshot.json +1325 -0
  43. package/db/d1/migrations/meta/0006_snapshot.json +1339 -0
  44. package/db/d1/migrations/meta/0007_snapshot.json +1347 -0
  45. package/db/d1/migrations/meta/0008_snapshot.json +1464 -0
  46. package/db/d1/migrations/meta/0009_snapshot.json +1648 -0
  47. package/db/d1/migrations/meta/_journal.json +76 -0
  48. package/db/d1/schema.ts +407 -0
  49. package/db/d1/sites.ts +374 -0
  50. package/db/d1/teamAiUsage.ts +101 -0
  51. package/db/d1/teams.ts +127 -0
  52. package/db/durable/drizzle.config.ts +8 -0
  53. package/db/durable/durableObjectClient.ts +480 -0
  54. package/db/durable/events.ts +100 -0
  55. package/db/durable/migrations/0000_fair_bucky.sql +38 -0
  56. package/db/durable/migrations/meta/0000_snapshot.json +278 -0
  57. package/db/durable/migrations/meta/_journal.json +13 -0
  58. package/db/durable/migrations/migrations.js +10 -0
  59. package/db/durable/schema.ts +5 -0
  60. package/db/durable/siteDurableObject.ts +1352 -0
  61. package/db/durable/types.ts +53 -0
  62. package/db/postgres/client.ts +13 -0
  63. package/db/postgres/drizzle.config.ts +12 -0
  64. package/db/postgres/migrations/0000_brainy_sprite.sql +116 -0
  65. package/db/postgres/migrations/meta/0000_snapshot.json +681 -0
  66. package/db/postgres/migrations/meta/_journal.json +13 -0
  67. package/db/postgres/schema.ts +145 -0
  68. package/db/postgres/sites.ts +118 -0
  69. package/db/tranformReports.ts +595 -0
  70. package/db/types.ts +55 -0
  71. package/endpoints/api_worker.tsx +1854 -0
  72. package/endpoints/site_do_worker.ts +11 -0
  73. package/index.d.ts +63 -0
  74. package/index.ts +83 -0
  75. package/lib/auth.ts +279 -0
  76. package/lib/geojson/world_countries.json +45307 -0
  77. package/lib/random_name.ts +41 -0
  78. package/lib/sendMail.ts +252 -0
  79. package/package.json +142 -0
  80. package/public/favicon.ico +0 -0
  81. package/public/images/android-chrome-192x192.png +0 -0
  82. package/public/images/android-chrome-512x512.png +0 -0
  83. package/public/images/apple-touch-icon.png +0 -0
  84. package/public/images/favicon-16x16.png +0 -0
  85. package/public/images/favicon-32x32.png +0 -0
  86. package/public/images/lytx_dark_dashboard.png +0 -0
  87. package/public/images/lytx_light_dashboard.png +0 -0
  88. package/public/images/safari-pinned-tab.svg +4 -0
  89. package/public/logo.png +0 -0
  90. package/public/site.webmanifest +26 -0
  91. package/public/sw.js +107 -0
  92. package/src/Document.tsx +86 -0
  93. package/src/api/ai_api.ts +1156 -0
  94. package/src/api/authMiddleware.ts +45 -0
  95. package/src/api/auth_api.ts +465 -0
  96. package/src/api/event_labels_api.ts +193 -0
  97. package/src/api/events_api.ts +210 -0
  98. package/src/api/queueWorker.ts +303 -0
  99. package/src/api/reports_api.ts +278 -0
  100. package/src/api/seed_api.ts +288 -0
  101. package/src/api/sites_api.ts +904 -0
  102. package/src/api/tag_api.ts +458 -0
  103. package/src/api/tag_api_v2.ts +289 -0
  104. package/src/api/team_api.ts +456 -0
  105. package/src/app/Dashboard.tsx +1339 -0
  106. package/src/app/Events.tsx +974 -0
  107. package/src/app/Explore.tsx +312 -0
  108. package/src/app/Layout.tsx +58 -0
  109. package/src/app/Settings.tsx +1302 -0
  110. package/src/app/components/DashboardCard.tsx +118 -0
  111. package/src/app/components/EditableCell.tsx +123 -0
  112. package/src/app/components/EventForm.tsx +93 -0
  113. package/src/app/components/MarketingFooter.tsx +49 -0
  114. package/src/app/components/MarketingNav.tsx +150 -0
  115. package/src/app/components/Nav.tsx +755 -0
  116. package/src/app/components/NewSiteSetup.tsx +298 -0
  117. package/src/app/components/SQLEditor.tsx +740 -0
  118. package/src/app/components/SiteSelector.tsx +126 -0
  119. package/src/app/components/SiteTag.tsx +42 -0
  120. package/src/app/components/SiteTagInstallCard.tsx +241 -0
  121. package/src/app/components/WorldMapCard.tsx +337 -0
  122. package/src/app/components/charts/ChartComponents.tsx +1481 -0
  123. package/src/app/components/charts/EventFunnel.tsx +45 -0
  124. package/src/app/components/charts/EventSummary.tsx +194 -0
  125. package/src/app/components/charts/SankeyFlows.tsx +72 -0
  126. package/src/app/components/marketing/CheckIcon.tsx +16 -0
  127. package/src/app/components/marketing/MarketingLayout.tsx +23 -0
  128. package/src/app/components/marketing/SectionHeading.tsx +35 -0
  129. package/src/app/components/reports/AskAiWorkspace.tsx +371 -0
  130. package/src/app/components/reports/CreateReportStarter.tsx +74 -0
  131. package/src/app/components/reports/DashboardRouteFiltersContext.tsx +14 -0
  132. package/src/app/components/reports/DashboardToolbar.tsx +154 -0
  133. package/src/app/components/reports/DashboardWorkspaceLayout.tsx +63 -0
  134. package/src/app/components/reports/DashboardWorkspaceShell.tsx +118 -0
  135. package/src/app/components/reports/ReportBuilderWorkspace.tsx +76 -0
  136. package/src/app/components/reports/custom/CustomReportBuilderPage.tsx +1667 -0
  137. package/src/app/components/reports/custom/ReportWidgetChart.tsx +297 -0
  138. package/src/app/components/reports/custom/buildWidgetSql.ts +151 -0
  139. package/src/app/components/reports/custom/chartPalettes.ts +18 -0
  140. package/src/app/components/reports/custom/types.ts +50 -0
  141. package/src/app/components/reports/reportBuilderMenuItems.ts +17 -0
  142. package/src/app/components/reports/useDashboardToolbarControls.tsx +235 -0
  143. package/src/app/components/ui/AlertBanner.tsx +101 -0
  144. package/src/app/components/ui/Button.tsx +55 -0
  145. package/src/app/components/ui/Card.tsx +80 -0
  146. package/src/app/components/ui/Input.tsx +72 -0
  147. package/src/app/components/ui/Link.tsx +23 -0
  148. package/src/app/components/ui/ReportBuilderMenu.tsx +246 -0
  149. package/src/app/components/ui/ThemeToggle.tsx +54 -0
  150. package/src/app/constants.ts +6 -0
  151. package/src/app/headers.ts +33 -0
  152. package/src/app/providers/AuthProvider.tsx +189 -0
  153. package/src/app/providers/ClientProviders.tsx +18 -0
  154. package/src/app/providers/QueryProvider.tsx +23 -0
  155. package/src/app/providers/ThemeProvider.tsx +88 -0
  156. package/src/app/utils/chartThemes.ts +146 -0
  157. package/src/app/utils/keybinds.ts +96 -0
  158. package/src/app/utils/media.tsx +24 -0
  159. package/src/client.tsx +114 -0
  160. package/src/config/createLytxAppConfig.ts +252 -0
  161. package/src/config/resourceNames.ts +88 -0
  162. package/src/db/index.ts +67 -0
  163. package/src/index.css +285 -0
  164. package/src/lib/featureFlags.ts +69 -0
  165. package/src/pages/GetStarted.tsx +290 -0
  166. package/src/pages/Home.tsx +268 -0
  167. package/src/pages/Login.tsx +283 -0
  168. package/src/pages/PrivacyPolicy.tsx +120 -0
  169. package/src/pages/Signup.tsx +267 -0
  170. package/src/pages/TermsOfService.tsx +126 -0
  171. package/src/pages/VerifyEmail.tsx +56 -0
  172. package/src/session/durableObject.ts +7 -0
  173. package/src/session/siteSchema.ts +86 -0
  174. package/src/session/types.ts +36 -0
  175. package/src/templates/README.md +80 -0
  176. package/src/templates/cleanFunctions.js +44 -0
  177. package/src/templates/embedFunctions.js +52 -0
  178. package/src/templates/lytx-shared.ts +662 -0
  179. package/src/templates/lytxpixel-core.ts +144 -0
  180. package/src/templates/lytxpixel.ts +267 -0
  181. package/src/templates/lytxpixelBrowser.js +634 -0
  182. package/src/templates/lytxpixelBrowser.mjs +634 -0
  183. package/src/templates/parseData.js +12 -0
  184. package/src/templates/script.ts +31 -0
  185. package/src/templates/template.tsx +50 -0
  186. package/src/templates/test.js +3 -0
  187. package/src/templates/trackWebEvents.ts +177 -0
  188. package/src/templates/vendors/clickcease.ts +8 -0
  189. package/src/templates/vendors/google.ts +174 -0
  190. package/src/templates/vendors/linkedin.ts +23 -0
  191. package/src/templates/vendors/meta.ts +56 -0
  192. package/src/templates/vendors/quantcast.ts +22 -0
  193. package/src/templates/vendors/simplfi.ts +7 -0
  194. package/src/types/app-context.ts +16 -0
  195. package/src/utilities/dashboardParams.ts +188 -0
  196. package/src/utilities/dashboardQueries.ts +537 -0
  197. package/src/utilities/dashboardTransforms.ts +167 -0
  198. package/src/utilities/dataValidation.ts +414 -0
  199. package/src/utilities/detector.ts +73 -0
  200. package/src/utilities/encrypt.ts +103 -0
  201. package/src/utilities/index.ts +13 -0
  202. package/src/utilities/parser.ts +117 -0
  203. package/src/utilities/performanceMonitoring.ts +570 -0
  204. package/src/utilities/route_interuptors.ts +24 -0
  205. package/src/worker.tsx +675 -0
  206. package/tsconfig.json +78 -0
  207. package/types/env.d.ts +16 -0
  208. package/types/rw.d.ts +7 -0
  209. package/types/shims.d.ts +53 -0
  210. package/types/vite.d.ts +19 -0
  211. package/vite/vite-plugin-pixel-bundle.ts +126 -0
  212. package/vite.config.ts +53 -0
  213. package/worker-configuration.d.ts +8401 -0
@@ -0,0 +1,634 @@
1
+ // src/templates/lytxpixel.ts
2
+ var encodePixel = "R0lGODlhAQABAIAAANvf7wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
3
+ var decodedPixel = atob(encodePixel);
4
+ //!BLINK X Product
5
+ //!Personalization type --> JSON
6
+ function parseData(data = null, config, trackCustomEvents, track_web_events, platformName) {
7
+ const pageUrl = new URL(window.location.href);
8
+ const debug = pageUrl.searchParams.has("lytxDebug");
9
+ if (window.lytxDataLayer.length < 2) {
10
+ console.log(`Lytx script is working \uD83D\uDD25\uD83D\uDD25\uD83D\uDD25${debug ? "\uD83D\uDC1B\uD83D\uDC1B\uD83D\uDC1B debug enabled" : ""}`);
11
+ }
12
+ function createScriptElement(src, async, type) {
13
+ const script = document.createElement("script");
14
+ script.src = src;
15
+ script.async = async;
16
+ let scriptPlacement = document.head.children[0];
17
+ if (!scriptPlacement) {
18
+ scriptPlacement = document.getElementsByTagName("script")[0];
19
+ }
20
+ if (type) {
21
+ script.type = type;
22
+ }
23
+ scriptPlacement.parentNode.insertBefore(script, scriptPlacement);
24
+ }
25
+ function quantcastScript(label) {
26
+ return {
27
+ async: true,
28
+ src: (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js",
29
+ element: "script",
30
+ callBack: (id) => {
31
+ window._qevents = window._qevents || [];
32
+ if (debug) {
33
+ console.log("Quantcast label is : ", label);
34
+ }
35
+ const qStructure = {
36
+ qacct: id,
37
+ labels: label ?? "_fp.event.PageView"
38
+ };
39
+ if (label) {
40
+ qStructure.event = "refresh";
41
+ }
42
+ window._qevents.push(qStructure);
43
+ }
44
+ };
45
+ }
46
+ function simplfiScript(id) {
47
+ return {
48
+ async: true,
49
+ src: `https://tag.simpli.fi/sifitag/${id}`,
50
+ element: "script"
51
+ };
52
+ }
53
+ function decodeHtmlEntities(str) {
54
+ return str.replaceAll(/&#39;/g, "'").replaceAll(/&quot;/g, '"').replaceAll(/&gt;/g, ">").replaceAll(/&lt;/g, "<").replaceAll(/&amp;/g, "&");
55
+ }
56
+ function customScript(script) {
57
+ if (debug) {
58
+ console.log("Custom script is : ", script);
59
+ }
60
+ try {
61
+ let parsedScript = decodeHtmlEntities(script);
62
+ const createCustomScript = document.createElement("script");
63
+ createCustomScript.innerHTML = parsedScript;
64
+ const scriptPlacement = document.getElementsByTagName("script")[0];
65
+ scriptPlacement.parentNode.insertBefore(createCustomScript, scriptPlacement);
66
+ } catch (error) {
67
+ console.error(error);
68
+ }
69
+ }
70
+ function googleTagScript(id) {
71
+ return {
72
+ async: true,
73
+ src: `https://www.googletagmanager.com/gtag/js?id=${id}`,
74
+ id,
75
+ callBack: (id2) => {
76
+ window.dataLayer = window.dataLayer || [];
77
+ if (window.gtag_lytx) {
78
+ const gtag_lytx = function() {
79
+ window.dataLayer.push(arguments);
80
+ };
81
+ gtag_lytx("config", new Date);
82
+ gtag_lytx("config", id2);
83
+ } else {
84
+ const gtagScript = document.createElement("script");
85
+ gtagScript.innerHTML = `
86
+ window.dataLayer = window.dataLayer || [];
87
+ function gtag_lytx(){window.dataLayer.push(arguments);}
88
+ gtag_lytx('js', new Date());
89
+
90
+ gtag_lytx('config', '${id2}');
91
+ `;
92
+ const scriptTags = document.head.querySelectorAll("script");
93
+ let scriptPlacement = document.head.children[0];
94
+ if (scriptTags) {
95
+ const scripts = [...scriptTags];
96
+ const activeGscript = scripts.filter((val) => val.src.includes(`id=${id2}`));
97
+ try {
98
+ scriptPlacement = activeGscript[0].nextSibling;
99
+ } catch (error) {
100
+ console.log(error);
101
+ }
102
+ }
103
+ if (!scriptPlacement) {
104
+ scriptPlacement = document.getElementsByTagName("script")[0];
105
+ }
106
+ scriptPlacement.parentNode.insertBefore(gtagScript, scriptPlacement);
107
+ }
108
+ }
109
+ };
110
+ }
111
+ function metaScript(config2) {
112
+ const { metaId, eventName, scriptInit } = config2;
113
+ let init = scriptInit ?? false;
114
+ let event = eventName ?? "PageView";
115
+ let id = metaId ?? "";
116
+ const facebookPixelStandardEvents = [
117
+ "AddPaymentInfo",
118
+ "AddToCart",
119
+ "AddToWishlist",
120
+ "CompleteRegistration",
121
+ "Contact",
122
+ "CustomizeProduct",
123
+ "Donate",
124
+ "FindLocation",
125
+ "InitiateCheckout",
126
+ "Lead",
127
+ "PageView",
128
+ "Purchase",
129
+ "Schedule",
130
+ "Search",
131
+ "StartTrial",
132
+ "SubmitApplication",
133
+ "Subscribe",
134
+ "ViewContent"
135
+ ];
136
+ if (init) {
137
+ (function(f, b, e, v, n, t, s) {
138
+ if (f.fbq)
139
+ return;
140
+ n = f.fbq = function() {
141
+ n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
142
+ };
143
+ if (!f._fbq)
144
+ f._fbq = n;
145
+ n.push = n;
146
+ n.loaded = true;
147
+ n.version = "2.0";
148
+ n.queue = [];
149
+ t = b.createElement(e);
150
+ t.async = true;
151
+ t.src = v;
152
+ s = b.getElementsByTagName(e)[0];
153
+ s.parentNode.insertBefore(t, s);
154
+ })(window, document, "script", "https://connect.facebook.net/en_US/fbevents.js");
155
+ }
156
+ if (window.fbq) {
157
+ if (init) {
158
+ window.fbq("init", `${id}`);
159
+ }
160
+ if (facebookPixelStandardEvents.includes(event)) {
161
+ window.fbq("track", event);
162
+ } else {
163
+ window.fbq("trackCustom", event);
164
+ }
165
+ }
166
+ }
167
+ function linkedinScript(id) {
168
+ const _linkedin_partner_id = id;
169
+ window._linkedin_data_partner_ids = window._linkedin_data_partner_ids || [];
170
+ window._linkedin_data_partner_ids.push(_linkedin_partner_id);
171
+ (function(l) {
172
+ if (!l) {
173
+ window.lintrk = function(a, b2) {
174
+ window.lintrk.q.push([a, b2]);
175
+ };
176
+ window.lintrk.q = [];
177
+ }
178
+ var s = document.getElementsByTagName("script")[0];
179
+ var b = document.createElement("script");
180
+ b.type = "text/javascript";
181
+ b.async = true;
182
+ b.src = "https://snap.licdn.com/li.lms-analytics/insight.min.js";
183
+ s.parentNode.insertBefore(b, s);
184
+ })(window.lintrk);
185
+ }
186
+ function handleIframe(config2) {
187
+ window.addEventListener("blur", function() {
188
+ window.setTimeout(function() {
189
+ if (config2.element && document.activeElement instanceof HTMLIFrameElement) {
190
+ if (config2.debug) {
191
+ console.log("Debug Iframe element is : ", config2.element, document.activeElement);
192
+ }
193
+ if (config2.callback && document.activeElement == config2.element) {
194
+ if (config2.debug)
195
+ console.log(config2.element, `Iframe Has been tracked correctly event name is ${config2.name ?? ""}`);
196
+ if (config2.callback.arguments) {
197
+ config2.callback.func(...config2.callback.arguments);
198
+ } else {
199
+ config2.callback.func();
200
+ }
201
+ }
202
+ }
203
+ }, 0);
204
+ });
205
+ }
206
+ function googleConversion(GoogleCommand, id, type, value) {
207
+ const options = {};
208
+ if (GoogleCommand == "config") {
209
+ options[`${type}`] = value;
210
+ try {
211
+ if (window.gtag_lytx) {
212
+ window.gtag_lytx(GoogleCommand, id, options);
213
+ } else {
214
+ const gtagScript = document.createElement("script");
215
+ gtagScript.innerHTML = `
216
+ gtag_lytx('${GoogleCommand}', '${id}', {
217
+ '${type}': '${value}'
218
+ });
219
+ `;
220
+ let scriptPlacement = document.head.children[0];
221
+ if (!scriptPlacement) {
222
+ scriptPlacement = document.getElementsByTagName("script")[0];
223
+ }
224
+ scriptPlacement.parentNode.insertBefore(gtagScript, scriptPlacement);
225
+ }
226
+ } catch (error) {
227
+ console.log(error);
228
+ }
229
+ } else if (GoogleCommand == "event") {
230
+ if (type == "conversion") {
231
+ try {
232
+ const gtag_report_conversion = (url = undefined) => {
233
+ const callback = function() {
234
+ if (typeof url != "undefined") {
235
+ window.location = url;
236
+ }
237
+ };
238
+ window.gtag_lytx(GoogleCommand, type, {
239
+ send_to: id,
240
+ value,
241
+ event_callback: callback
242
+ });
243
+ return false;
244
+ };
245
+ gtag_report_conversion();
246
+ } catch (error) {
247
+ console.log(error);
248
+ }
249
+ }
250
+ }
251
+ }
252
+ function clickCeaseScript() {
253
+ return {
254
+ async: true,
255
+ src: "https://www.clickcease.com/monitor/stat.js",
256
+ type: "text/javascript"
257
+ };
258
+ }
259
+ function splitQueryParams(split, queryParams, skipSmallSplit = false) {
260
+ let keys;
261
+ if (!skipSmallSplit && typeof split != "string") {
262
+ keys = split.map((values) => {
263
+ let smallSplit = values.split("=");
264
+ return { key: smallSplit[0], val: smallSplit[1] };
265
+ });
266
+ } else if (skipSmallSplit && typeof split == "string") {
267
+ let smallSplit = split.split("=");
268
+ keys = [
269
+ {
270
+ key: smallSplit[0],
271
+ val: smallSplit[1]
272
+ }
273
+ ];
274
+ }
275
+ let allowed = true;
276
+ queryParams.forEach((val, key) => {
277
+ let check = keys.find((value) => value.key == key && value.val == val);
278
+ if (!check)
279
+ allowed = false;
280
+ });
281
+ return allowed;
282
+ }
283
+ function updateEventRecord(trackedEvent) {
284
+ if (window.lytxDataLayer && window.lytxDataLayer.length > 1) {
285
+ window.lytxDataLayer.find((layer) => layer.tag == config.tag)?.tracked.push(trackedEvent);
286
+ } else {
287
+ window.lytxDataLayer[0].tracked.push(trackedEvent);
288
+ }
289
+ }
290
+ function trackDataPassBack() {}
291
+ function trackCustomRecord(event) {
292
+ if (track_web_events) {
293
+ trackCustomEvents(config.tag, platformName, { custom: event.event_name });
294
+ if (debug) {
295
+ console.log("Event tracked is", event.event_name);
296
+ }
297
+ }
298
+ }
299
+ function googleClickConversion(elems, parsedValue) {
300
+ elems.forEach((elem) => {
301
+ elem.addEventListener("click", () => {
302
+ parsedValue.forEach((val) => googleConversion(val.GoogleCommand, val.id, val.type, val.value));
303
+ });
304
+ });
305
+ }
306
+ function googleSingleClickConversion(elem, parsedValue) {
307
+ elem.addEventListener("click", () => {
308
+ parsedValue.forEach((val) => googleConversion(val.GoogleCommand, val.id, val.type, val.value));
309
+ });
310
+ }
311
+ function loadLytxEvents(url = new URL(window.location.href)) {
312
+ if (data) {
313
+ if (window.lytxDataLayer.length < 2) {
314
+ console.log("⚡⚡⚡⚡ See Defined Lytx Events Here ⚡⚡⚡⚡ -->", window.lytxDataLayer);
315
+ }
316
+ try {
317
+ data.forEach((ev) => {
318
+ //!TODO add missing events
319
+ if (ev.condition == "path") {
320
+ if (ev.parameters == "*") {
321
+ if (ev.metaEvent) {
322
+ metaScript({ metaId: ev.metaEvent, scriptInit: true });
323
+ }
324
+ if (ev.linkedinEvent) {
325
+ linkedinScript(ev.linkedinEvent);
326
+ }
327
+ if (ev.SimplfiPixelid) {
328
+ const newScript = simplfiScript(ev.SimplfiPixelid);
329
+ createScriptElement(newScript.src, newScript.async);
330
+ }
331
+ if (ev.googleanalytics) {
332
+ const newScript = googleTagScript(ev.googleanalytics);
333
+ createScriptElement(newScript.src, true);
334
+ newScript.callBack(newScript.id);
335
+ }
336
+ if (ev.QuantcastPixelId) {
337
+ const newScript = quantcastScript();
338
+ createScriptElement(newScript.src, true);
339
+ newScript.callBack(ev.QuantcastPixelId);
340
+ }
341
+ if (ev.clickCease && ev.clickCease == "enabled") {
342
+ const newScript = clickCeaseScript();
343
+ createScriptElement(newScript.src, newScript.async, newScript.type);
344
+ }
345
+ if (ev.googleadsscript) {
346
+ const newScript = googleTagScript(ev.googleadsscript);
347
+ createScriptElement(newScript.src, true);
348
+ newScript.callBack(newScript.id);
349
+ }
350
+ if (ev.customScript) {
351
+ customScript(ev.customScript);
352
+ }
353
+ if (ev.googleadsconversion) {
354
+ try {
355
+ const parsedValue = JSON.parse(ev.googleadsconversion);
356
+ parsedValue.forEach((val) => googleConversion(val.GoogleCommand, val.id, val.type, val.value));
357
+ } catch (error) {
358
+ console.log(error);
359
+ }
360
+ }
361
+ } else {
362
+ const parsedUrl = url ?? new URL(window.location.href);
363
+ const path = url && url.pathname ? url.pathname : window.location.pathname;
364
+ const queryParams = parsedUrl.searchParams;
365
+ let queryParamCheck = true;
366
+ try {
367
+ if (ev.query_parameters) {
368
+ if (ev.query_parameters.includes("&")) {
369
+ let split = ev.query_parameters.split("&");
370
+ queryParamCheck = splitQueryParams(split, queryParams);
371
+ } else {
372
+ queryParamCheck = splitQueryParams(ev.query_parameters, queryParams);
373
+ }
374
+ }
375
+ } catch (error) {
376
+ queryParamCheck = true;
377
+ }
378
+ if (path.includes(ev.parameters) && queryParamCheck) {
379
+ if (ev.SimplfiPixelid) {
380
+ const newScript = simplfiScript(ev.SimplfiPixelid);
381
+ createScriptElement(newScript.src, newScript.async);
382
+ updateEventRecord(ev);
383
+ }
384
+ if (ev.QuantcastPixelId && ev.QuantCastPixelLabel) {
385
+ const newQEvent = quantcastScript(ev.QuantCastPixelLabel);
386
+ newQEvent.callBack(ev.QuantcastPixelId);
387
+ }
388
+ if (ev.googleadsconversion) {
389
+ try {
390
+ const parsedValue = JSON.parse(ev.googleadsconversion);
391
+ parsedValue.forEach((val) => googleConversion(val.GoogleCommand, val.id, val.type, val.value));
392
+ } catch (error) {
393
+ console.log(error);
394
+ }
395
+ }
396
+ }
397
+ }
398
+ } else if (ev.condition == "dom element") {
399
+ if (ev.rules == "click") {
400
+ try {
401
+ let elem = document.querySelector(`[${ev.parameters}]`);
402
+ let queryAll = false;
403
+ const delay = { enabled: false, amount: 0 };
404
+ let iframe = false;
405
+ let allElems = null;
406
+ if (ev.paramConfig) {
407
+ if (debug)
408
+ console.log(`This is the param config for${ev.event_name}`, ev.paramConfig);
409
+ let parseConfig;
410
+ if (ev.paramConfig.includes("&quot;")) {
411
+ let rawStr = ev.paramConfig.replaceAll("&quot;", '"');
412
+ if (debug)
413
+ console.log(rawStr, JSON.parse(rawStr));
414
+ parseConfig = JSON.parse(rawStr);
415
+ } else {
416
+ parseConfig = JSON.parse(ev.paramConfig);
417
+ }
418
+ if (parseConfig) {
419
+ if (parseConfig.delay) {
420
+ delay.amount = Number(parseConfig.delay);
421
+ delay.enabled = true;
422
+ if (debug)
423
+ console.log(`Delay of ${delay.amount} has been enabled for : ${ev.event_name}`);
424
+ }
425
+ if (parseConfig.iframe) {
426
+ iframe = true;
427
+ }
428
+ }
429
+ if (debug)
430
+ console.log(parseConfig);
431
+ if (parseConfig && parseConfig.querySelectorAll) {
432
+ if (parseConfig.path) {
433
+ const path = window.location.pathname;
434
+ if (path.includes(`${parseConfig.path}`) || parseConfig.path == "*") {
435
+ if (parseConfig.querySelectorAll == "all") {
436
+ queryAll = true;
437
+ allElems = document.querySelectorAll(`[${ev.parameters}]`);
438
+ if (debug) {
439
+ console.log(`\uD83D\uDC1B\uD83D\uDC1B\uD83D\uDC1B ${ev.event_name} has the following elements tracked`, allElems);
440
+ }
441
+ } else {
442
+ elem = document.querySelectorAll(`[${ev.parameters}]`)[parseConfig.querySelectorAll];
443
+ }
444
+ }
445
+ } else {
446
+ if (parseConfig.querySelectorAll == "all") {
447
+ queryAll = true;
448
+ allElems = document.querySelectorAll(`[${ev.parameters}]`);
449
+ } else {
450
+ elem = document.querySelectorAll(`[${ev.parameters}]`)[parseConfig.querySelectorAll];
451
+ }
452
+ }
453
+ if (!elem)
454
+ elem = document.querySelector(`[${ev.parameters}]`);
455
+ }
456
+ }
457
+ let clicked = false;
458
+ if (elem) {
459
+ if (track_web_events) {
460
+ if (queryAll && allElems) {
461
+ allElems.forEach((el) => {
462
+ el.addEventListener("click", () => {
463
+ trackCustomRecord(ev);
464
+ });
465
+ });
466
+ } else {
467
+ if (delay.enabled) {
468
+ setTimeout(() => {
469
+ const delayElem = document.querySelector(`[${ev.parameters}]`);
470
+ delayElem.addEventListener("click", () => {
471
+ trackCustomRecord(ev);
472
+ });
473
+ if (debug) {
474
+ console.log(`Delayed track record event added for event : ${ev.event_name} and element -->`, delayElem);
475
+ }
476
+ }, delay.amount);
477
+ } else {
478
+ elem.addEventListener("click", () => {
479
+ trackCustomRecord(ev);
480
+ });
481
+ }
482
+ }
483
+ }
484
+ if (ev.SimplfiPixelid) {
485
+ if (queryAll && allElems) {
486
+ allElems.forEach((el) => {
487
+ el.addEventListener("click", () => {
488
+ if (ev.SimplfiPixelid) {
489
+ const newScript = simplfiScript(ev.SimplfiPixelid);
490
+ createScriptElement(newScript.src, newScript.async);
491
+ updateEventRecord(ev);
492
+ }
493
+ });
494
+ });
495
+ } else {
496
+ elem.addEventListener("click", () => {
497
+ if (!clicked && ev.SimplfiPixelid) {
498
+ const newScript = simplfiScript(ev.SimplfiPixelid);
499
+ createScriptElement(newScript.src, newScript.async);
500
+ updateEventRecord(ev);
501
+ clicked = true;
502
+ }
503
+ });
504
+ }
505
+ }
506
+ if (ev.googleadsconversion) {
507
+ try {
508
+ const parsedValue = JSON.parse(ev.googleadsconversion);
509
+ if (queryAll) {
510
+ if (delay.enabled) {
511
+ setTimeout(() => {
512
+ if (allElems) {
513
+ googleClickConversion(allElems, parsedValue);
514
+ if (debug) {
515
+ console.log("Delayed event added", ev.event_name);
516
+ }
517
+ }
518
+ }, delay.amount);
519
+ } else {
520
+ if (allElems) {
521
+ googleClickConversion(allElems, parsedValue);
522
+ }
523
+ }
524
+ } else {
525
+ if (delay.enabled) {
526
+ setTimeout(() => {
527
+ const delayElem = document.querySelector(`[${ev.parameters}]`);
528
+ googleSingleClickConversion(delayElem, parsedValue);
529
+ if (debug) {
530
+ console.log(`Delayed event added for event : ${ev.event_name} and element -->`, delayElem);
531
+ }
532
+ }, delay.amount);
533
+ } else {
534
+ googleSingleClickConversion(elem, parsedValue);
535
+ //!Iframe
536
+ try {
537
+ if (iframe) {
538
+ handleIframe({
539
+ name: ev.event_name,
540
+ callback: {
541
+ func: googleSingleClickConversion,
542
+ arguments: [elem, parsedValue]
543
+ },
544
+ element: elem,
545
+ debug
546
+ });
547
+ }
548
+ } catch (error) {
549
+ console.error("Iframe handler mishandled", error);
550
+ }
551
+ }
552
+ }
553
+ } catch (error) {
554
+ console.log(error);
555
+ }
556
+ }
557
+ if (ev.QuantcastPixelId) {
558
+ elem.addEventListener("click", () => {
559
+ updateEventRecord(ev);
560
+ if (ev.QuantcastPixelId && ev.QuantCastPixelLabel) {
561
+ const newQEvent = quantcastScript(ev.QuantCastPixelLabel);
562
+ newQEvent.callBack(ev.QuantcastPixelId);
563
+ }
564
+ });
565
+ }
566
+ if (ev.metaEvent) {
567
+ elem.addEventListener("click", () => {
568
+ updateEventRecord(ev);
569
+ metaScript({ metaId: ev.metaEvent, eventName: ev.event_name });
570
+ });
571
+ }
572
+ }
573
+ } catch (error) {
574
+ console.log(error);
575
+ }
576
+ } else if (ev.rules == "submit") {
577
+ try {
578
+ const elem = document.querySelector(`[${ev.parameters}]`);
579
+ let submitted = false;
580
+ if (elem) {
581
+ if (track_web_events) {
582
+ elem.addEventListener("submit", () => {
583
+ trackCustomRecord(ev);
584
+ });
585
+ }
586
+ if (ev.SimplfiPixelid) {
587
+ elem.addEventListener("submit", () => {
588
+ if (!submitted && ev.SimplfiPixelid) {
589
+ const newScript = simplfiScript(ev.SimplfiPixelid);
590
+ createScriptElement(newScript.src, newScript.async);
591
+ updateEventRecord(ev);
592
+ submitted = true;
593
+ }
594
+ });
595
+ }
596
+ if (ev.metaEvent) {
597
+ elem.addEventListener("submit", () => {
598
+ updateEventRecord(ev);
599
+ metaScript({ metaId: ev.metaEvent, eventName: ev.event_name });
600
+ });
601
+ }
602
+ }
603
+ } catch (error) {}
604
+ }
605
+ }
606
+ });
607
+ } catch (error) {
608
+ console.log(error);
609
+ }
610
+ }
611
+ }
612
+ window.lytxApi = {
613
+ emit: loadLytxEvents,
614
+ event: () => {},
615
+ rid: () => {
616
+ if (window.lytxDataLayer) {
617
+ let ridVal = null;
618
+ window.lytxDataLayer.forEach((layer) => {
619
+ if (layer.rid) {
620
+ ridVal = layer.rid;
621
+ }
622
+ });
623
+ return ridVal;
624
+ } else {
625
+ return null;
626
+ }
627
+ }
628
+ };
629
+ loadLytxEvents();
630
+ }
631
+ export {
632
+ parseData,
633
+ decodedPixel
634
+ };
@@ -0,0 +1,12 @@
1
+ // Clean JavaScript version of parseData function for embedding
2
+ function parseData(data, config, trackCustomEvents, track_web_events, platformName) {
3
+ const pageUrl = new URL(window.location.href);
4
+ const debug = pageUrl.searchParams.has('lytxDebug');
5
+
6
+ if(window.lytxDataLayer.length < 2) {
7
+ console.log(`Lytx script is working 🔥🔥🔥${debug ? '🐛🐛🐛 debug enabled' : ''}`);
8
+ }
9
+
10
+ // Add the rest of your parseData logic here
11
+ // Copy from the TypeScript version but as clean JavaScript
12
+ }
@@ -0,0 +1,31 @@
1
+ export function simplfiScript(id: string) {
2
+ return {
3
+ async: true,
4
+ src: `https://tag.simpli.fi/sifitag/${id}`,
5
+ element: "script",
6
+ };
7
+ }
8
+
9
+ export function quantcastScript(id: string) {
10
+ return {
11
+ async: true,
12
+ src: "",
13
+ };
14
+ }
15
+ export const pageScript = `
16
+ window._lytxEvents = window._lytxEvents || [];
17
+ (function () {
18
+ const elem = document.createElement("script");
19
+ elem.src = "http://localhost:8787/container.js?test=true";
20
+ elem.async = true;
21
+ elem.type = "text/javascript";
22
+ const script = document.getElementsByTagName("script")[0];
23
+ script.parentNode.insertBefore(elem, script);
24
+ }
25
+ )();
26
+ window._lytxEvents.push({
27
+ lytxAccount: "lytx-main",
28
+ labels: "lytx-main",
29
+ }
30
+ );
31
+ `;