Skip to content

feat(affiliate-marketing): add unified TikTok + Shopee system planner and API#273

Merged
cvsz merged 1 commit into
mainfrom
codex/find-and-implement-system-for-tiktok-shopee
Apr 26, 2026
Merged

feat(affiliate-marketing): add unified TikTok + Shopee system planner and API#273
cvsz merged 1 commit into
mainfrom
codex/find-and-implement-system-for-tiktok-shopee

Conversation

@cvsz
Copy link
Copy Markdown
Owner

@cvsz cvsz commented Apr 26, 2026

Motivation

  • Provide a unified cross-channel planner to reason about TikTok engagement and Shopee conversions and produce actionable budget splits and next-actions for affiliate campaigns.
  • Add a validated request contract and an API surface so other systems can call the planner with strong input validation and deterministic output.

Description

  • Added tiktokShopeeSystemRequestSchema and related types in apps/affiliate-marketing/src/schemas.ts to validate campaign inputs.
  • Implemented buildTikTokShopeeSystem in apps/affiliate-marketing/src/engine.ts which computes TikTok CTR, Shopee CVR, a blended score, recommended TikTok/Shopee budget split, and a deterministic next-action playbook per product.
  • Exposed a new endpoint POST /v1/system/tiktok-shopee in apps/affiliate-marketing/src/index.ts which validates payloads and returns the generated system plan.
  • Added unit coverage in apps/affiliate-marketing/src/engine.test.ts to assert ordering, budget split ranges and output structure for the planner.

Testing

  • Ran npm test --workspace apps/affiliate-marketing which completed successfully and reported all tests passing (1 file, 4 tests).
  • The new planner test passed and existing engine tests remained green.

Codex Task

@cvsz cvsz merged commit 3662fb5 into main Apr 26, 2026
1 of 5 checks passed
@cvsz cvsz deleted the codex/find-and-implement-system-for-tiktok-shopee branch April 26, 2026 14:19
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a unified TikTok and Shopee campaign analysis system, including a new API endpoint, Zod validation schemas, and the core logic for calculating performance metrics and budget splits. The review feedback identifies several areas for improvement: the TikTokShopeeSystemPlan type should be exported for external use, the budget calculation contains unreachable logic and magic numbers that should be refactored, and the nextActions list should be made dynamic based on performance benchmarks rather than remaining static.

return `สำหรับ ${input.audience}: ${input.currentCaption} | ปรับตามข้อเสนอ: ${directives}. CTA: กดดูรายละเอียดและเริ่มได้ทันที`;
}

type TikTokShopeeSystemPlan = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The TikTokShopeeSystemPlan type is used as the return type for the exported buildTikTokShopeeSystem function. It should be exported so that consumers of this module can properly type the results in their own codebases.

Suggested change
type TikTokShopeeSystemPlan = {
export type TikTokShopeeSystemPlan = {

const tiktokCtr = campaign.tiktokViews === 0 ? 0 : campaign.tiktokClicks / campaign.tiktokViews;
const shopeeCvr = campaign.shopeeClicks === 0 ? 0 : campaign.shopeeOrders / campaign.shopeeClicks;
const blendedScore = Number((tiktokCtr * 0.5 + shopeeCvr * 0.5).toFixed(4));
const tiktokBudget = Math.max(25, Math.min(80, Math.round((0.65 - shopeeCvr) * 100)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This budget calculation contains several magic numbers and a potential logic inconsistency. The upper bound of 80 in Math.min(80, ...) is unreachable because the expression (0.65 - shopeeCvr) * 100 maxes out at 65 (when shopeeCvr is 0). Consider extracting these values into named constants and verifying the intended range for the TikTok budget split.

Comment on lines +70 to +74
const nextActions = [
`TikTok hook refresh for ${campaign.productId}`,
`Shopee PDP optimization for ${campaign.productId}`,
`Retarget users who clicked TikTok but not Shopee checkout`,
];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The nextActions list is currently static for all products. To provide a more useful "system plan" as described in the PR, these recommendations should be dynamic based on the calculated metrics (e.g., only suggesting a hook refresh if the tiktokCtr is below a specific benchmark).

      const nextActions = [];
      if (tiktokCtr < 0.03) nextActions.push('TikTok hook refresh for ' + campaign.productId);
      if (shopeeCvr < 0.05) nextActions.push('Shopee PDP optimization for ' + campaign.productId);
      nextActions.push('Retarget users who clicked TikTok but not Shopee checkout');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant