Skip to content

Commit 713761f

Browse files
authored
fix(analytics): restore Mixpanel IIFE syntax broken in PR #5 (P1) (#6)
* fix(analytics): restore Mixpanel IIFE syntax broken in PR #5 PR #5 (Rocket Loader bypass) accidentally introduced a typo in the Mixpanel bootstrap IIFE: a[c[0]]= became a=c[0]]=, which is a JS SyntaxError (Unexpected token ']'). The whole <script> block fails to parse, so mixpanel.init() never runs and no events are sent — the Rocket Loader fix was correct but got masked by this regression. Confirmed via `node --check` on the extracted <script> block: SyntaxError on the merged code, OK after this fix. Reported by Codex (P1) and Copilot review on PR #5. Only the two bytes a[ → a= are changed; nothing else. * fix(analytics): replace corrupted Mixpanel stub with official snippet The bootstrap IIFE shipped since 7c95a83 was a hand-edited variant with a structurally broken init stub: it called b._q.push(...) but only ever initialized b._i (never b._q), so every mixpanel.init(...) threw 'TypeError: Cannot read properties of undefined (reading push') before any tracking method (track/identify/people.set/...) could be stubbed onto the object. Result: zero events, even with a valid SDK URL and Rocket Loader bypass. PR #6 fixed one symptom (the a=c[0]] syntax typo from #5), but the underlying _q/_i logic bug remained — flagged again as P1 by Codex review on #6. Fix: replace the whole IIFE with Mixpanel's official snippet verbatim from https://docs.mixpanel.com/docs/tracking-methods/sdks/javascript. The official stub stubs out all methods (track, identify, people.*, ...) and records the init call via b._i.push([...]) — matching the SDK's own contract. Verified by executing the extracted <script> block in Node with a DOM mock: - mixpanel._i receives the init call - mixpanel.track / identify / people.set are all functions - No TypeError, no SyntaxError Same snippet in site/index.html and web/index.html. data-cfasync="false" and the existing mixpanel.init(...) config line are preserved.
1 parent d32aa63 commit 713761f

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

site/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
data-cfasync="false" tells Cloudflare Rocket Loader to leave this script alone (run immediately, in document order).
208208
Without it, Rocket Loader rewrites <script type> and the inline init never executes → zero events reach Mixpanel. -->
209209
<script data-cfasync="false">
210-
(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b){var c=b.split(".");2==c.length&&(b=b[c[0]],a=c[0]]=a[c[0]]||{},a=a[c[0]])}b._q.push({a:d});f("track");f("identify");f("reset");f("register");f("alias");f("people.set");f("people.increment");f("track_charge");f("append");b._i[d]={};a&&"function"==typeof a&&(b._i[d]=a)};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";g=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);
210+
(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&((a=a[b[0]]),(d=b[1]));a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?(a=b[c]=[]):(c="mixpanel");a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" ");for(h=0;h<i.length;h++)g(a,i[h]);var j="set set_once union unset remove delete".split(" ");a.get_group=function(){function b(c){d[c]=function(){call2_args=arguments;call2=[c].concat(Array.prototype.slice.call(call2_args,0));a.push([e,call2])}}for(var d={},e=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)b(j[c]);return d};b._i.push([e,f,c])};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";g=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);
211211
mixpanel.init("72970b4dccaded033cafffc4bb48e196", { debug: false, track_pageview: true, persistence: "localStorage" });
212212
</script>
213213
</head>

web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
data-cfasync="false" tells Cloudflare Rocket Loader to leave this script alone (run immediately, in document order).
208208
Without it, Rocket Loader rewrites <script type> and the inline init never executes → zero events reach Mixpanel. -->
209209
<script data-cfasync="false">
210-
(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b){var c=b.split(".");2==c.length&&(b=b[c[0]],a=c[0]]=a[c[0]]||{},a=a[c[0]])}b._q.push({a:d});f("track");f("identify");f("reset");f("register");f("alias");f("people.set");f("people.increment");f("track_charge");f("append");b._i[d]={};a&&"function"==typeof a&&(b._i[d]=a)};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";g=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);
210+
(function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&((a=a[b[0]]),(d=b[1]));a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?(a=b[c]=[]):(c="mixpanel");a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" ");for(h=0;h<i.length;h++)g(a,i[h]);var j="set set_once union unset remove delete".split(" ");a.get_group=function(){function b(c){d[c]=function(){call2_args=arguments;call2=[c].concat(Array.prototype.slice.call(call2_args,0));a.push([e,call2])}}for(var d={},e=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)b(j[c]);return d};b._i.push([e,f,c])};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";g=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]);
211211
mixpanel.init("72970b4dccaded033cafffc4bb48e196", { debug: false, track_pageview: true, persistence: "localStorage" });
212212
</script>
213213
</head>

0 commit comments

Comments
 (0)