Skip to content

fix: Send abandoned cart emails, keep product views and TikTok server events working - #862

Merged
leomp12 merged 4 commits into
mainfrom
fix/abandoned-cart-views-tiktok
Oct 25, 2026
Merged

leomp12 merged 4 commits into
mainfrom
fix/abandoned-cart-views-tiktok

Conversation

@leomp12

@leomp12 leomp12 commented Oct 25, 2026

Copy link
Copy Markdown
Member

Three small fixes for errors found in the stores' Cloud Logging (last 7 days).

Abandoned cart emails were never sent

cron-cart-emails.ts listed carts without items and subtotal, but the abandoned-cart template reads both (partials/cartitems.ejs → cart.items.forEach). Rendering failed for every cart since the feature shipped. Failed carts are not flagged, so the same 200 came back on every exec: ~47k log entries/day on demo and tiasonia, ~16k on barradoce.

The cron now also limits carts to 7 days past the abandon delay (updated_at>). Without that, the first exec after this fix would send recovery emails for months-old carts that piled up unflagged. Checked on the Store API that updated_at< + updated_at> filter as a range.

Product views stuck on barradoce

The product ID check on /_analytics was unanchored (/[0-9a-f]{24}/), so bot IDs with SQL injection appended were stored on ssrProductViews. cronSaveViews got a 406 on that doc and breaks on any non-404 error, on every exec (169 errors/week), so no views were saved. The ID must now be exactly 24 hex chars, and the cron drops docs on any 4xx except 429 (which already removes the stuck doc).

TikTok server events never sent

The client sent type: 'ttk' while the server groups by ttq (the declared type is already 'ttq', hidden by as any). Only tiasonia has TIKTOK_PIXEL_ID/TIKTOK_ACCESS_TOKEN set. Sending failures are already caught by Promise.allSettled.

Checks

  • tsc --noEmit on ssr and app-emails, eslint on the changed files.
  • No unit tests added: the changes are a fields list, a regex anchor and a type string.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AzZmcNMuAAjtyPLYYbnJBX

leomp12 and others added 4 commits October 24, 2026 22:57
The carts were listed without items and subtotal, which the email template
reads, so rendering failed for every cart. Failed carts were not flagged and
came back on every exec.

Only carts up to 7 days past the abandon delay are emailed now, so the
backlog of unflagged carts doesn't get old recovery emails all at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AzZmcNMuAAjtyPLYYbnJBX
…t IDs

The product ID check was unanchored, so IDs with injection payloads appended
were stored on ssrProductViews. The save views cron stopped on the API 406
for that doc on every exec, leaving all other views unsaved.

The ID must now be exactly 24 hex chars, and the cron drops docs on any 4xx
other than 429 instead of stopping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AzZmcNMuAAjtyPLYYbnJBX
The client tagged TikTok events as 'ttk' while the server groups them by
'ttq', so server-side TikTok events were never sent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AzZmcNMuAAjtyPLYYbnJBX
…re rejected

Only drops view docs on 4xx that can't succeed later, 401 and 403 now stop
the run like before so views aren't lost while credentials are fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AzZmcNMuAAjtyPLYYbnJBX
@leomp12
leomp12 merged commit 50f23ef into main Oct 25, 2026
2 checks passed
@leomp12
leomp12 deleted the fix/abandoned-cart-views-tiktok branch October 25, 2026 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant