feat: implement email click tracking and custom redirect handler (#259)#268
Open
CodeSparks45 wants to merge 1 commit into
Open
feat: implement email click tracking and custom redirect handler (#259)#268CodeSparks45 wants to merge 1 commit into
CodeSparks45 wants to merge 1 commit into
Conversation
Owner
🚀 PR Guidelines — Read Before Raising a PRHey contributors 👋 I’m LeadOrbit's Bot, and I’ll review every PR before it gets merged. ✅ Your PR will only be merged if:
❌ PRs that may be rejected:
Before submitting:
And if you find the project useful, consider ⭐ starring the repository — it helps the project grow and motivates further development. Quality contributions > PR count. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a robust click-tracking mechanism for outbound campaign emails. It parses outgoing email bodies, rewrites anchor tags with a secure tracking URL, and handles the redirection while updating lead analytics.
Closes #259
Key Changes:
tasks.py: Implemented rewrite_email_links using BeautifulSoup to parse HTML. Used Django's cryptographic Signer to securely encode the campaign_lead_id and step_id within the tracking URL to prevent tampering. Intercepted the email body just before send_gmail.
views.py: Added ClickTrackingView (unauthenticated API endpoint). This decodes the secure token, updates the last_clicked_at timestamp on the specific CampaignLead, and gracefully handles the HttpResponseRedirect to the original URL.
urls.py: Registered the new /api/v1/clicks/track/ route for the interceptor.
Testing Performed:
Verified the link rewriting logic locally to ensure secure tokens generate correctly.
Tested the tracking endpoint to ensure it safely decodes the payload, updates database metrics, and redirects to the target destination without error.