Skip to content

[MKT-822]:feat/add isFirstPruchaseCheck to the impact services tracking#1935

Merged
jaaaaavier merged 3 commits intomasterfrom
fix/impact-tracking
Apr 23, 2026
Merged

[MKT-822]:feat/add isFirstPruchaseCheck to the impact services tracking#1935
jaaaaavier merged 3 commits intomasterfrom
fix/impact-tracking

Conversation

@jaaaaavier
Copy link
Copy Markdown
Contributor

@jaaaaavier jaaaaavier commented Apr 21, 2026

Description

Implemented logic to distinguish between new sales and returning customers during checkout to optimize Impact conversion tracking.

Key Changes:

  • checkIsFirstPurchase: Added a new function in useUserPayment.ts that retrieves the user's invoice history to determine if the purchase is their first. The isFirstPurchase state is now stored in localStorage during the payment process for retrieval on the success page.

  • Impact Service: Updated trackPaymentConversion to ensure conversion events are only sent to Impact if:
    The purchase is confirmed as the user's first.

Related Issues

Related Pull Requests

Checklist

  • Changes have been tested locally.
  • Unit tests have been written or updated as necessary.
  • The code adheres to the repository's coding standards.
  • Relevant documentation has been added or updated.
  • No new warnings or errors have been introduced.
  • SonarCloud issues have been reviewed and addressed.
  • QA Passed

Testing Process

Simulated the checkout flow in development environment using new and existing user accounts.

Scenarios Tested:

  • New Customer (First Purchase):
    - Step: Logged in with a user who has no previous invoice history.
    - Observed:
    - The invoices API call returned an empty array.
    - isFirstPurchase was correctly set to true in localStorage after clicking "Pay".

  • Returning Customer (Repeat Purchase):
    - Step: Logged in with a user who already has a paid invoice.
    - Observed:
    - The invoices API call returned at least one record.
    - isFirstPurchase was correctly set to false in localStorage.

Additional Notes

Video attached of the testing process attached on the task

@jaaaaavier jaaaaavier self-assigned this Apr 21, 2026
@jaaaaavier jaaaaavier added the enhancement New feature or request label Apr 21, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 21, 2026

Deploying drive-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: a6ad508
Status: ✅  Deploy successful!
Preview URL: https://61641a82.drive-web.pages.dev
Branch Preview URL: https://fix-impact-tracking-6cgr.drive-web.pages.dev

View logs

@jaaaaavier jaaaaavier marked this pull request as ready for review April 21, 2026 08:56
@jaaaaavier jaaaaavier requested review from a team and xabg2 as code owners April 21, 2026 08:56
Comment thread src/app/analytics/impact.service.ts Outdated
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.

Would be better to pass an object instead of function parameter, so you know what props you have.

@sonarqubecloud
Copy link
Copy Markdown

@jaaaaavier jaaaaavier requested a review from xabg2 April 22, 2026 08:17
confirmSetupIntent,
}: UseUserPaymentPayload) => {
const planInterval = selectedPlan.price.interval;
const isFirstPurchase = await checkIsFirstPurchase();
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.

What if this fails here? Will the payments not go through? Is that the expected outcome? Unless it’s absolutely necessary, this shouldn’t interfere with the payment process. In other words, whether it works or fails, I understand that it shouldn’t affect the payment flow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The checkIsFirstPurchase function contains an internal try/catch block. If the API call fails, it catches the error, logs it, and simply returns false. It should not throw an error, so the payment flow is never interrupted. However, if you think this is risky, I can look for an alternative.

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.

It's ok for me then! 🚀

@jaaaaavier jaaaaavier merged commit 297c255 into master Apr 23, 2026
11 checks passed
@jaaaaavier jaaaaavier deleted the fix/impact-tracking branch April 23, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants