-
Notifications
You must be signed in to change notification settings - Fork 461
Add email tracking helper API (Fixes #646) #821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add email tracking helper API (Fixes #646) #821
Conversation
Fixes KartikTalwar#646 - Add gmail.track namespace with easy-to-use email tracking functions - Implement gmail.track.sent_emails() for tracking sent emails - Implement gmail.track.scheduled_emails() for tracking scheduled emails - Implement gmail.track.all_emails() for tracking both types - Add gmail.track.logger() for easy debugging - Create comprehensive documentation with examples - Provide cleaner API compared to direct observe.on() usage Features: - Simple callback-based API - Email data as first parameter (most intuitive) - Support for both sent and scheduled emails - Built-in logger for debugging - Comprehensive documentation with use cases - Examples for analytics, notifications, backup systems Benefits: - Solves user request from issue KartikTalwar#646 - Makes email tracking accessible to beginners - Provides clean wrapper around existing observe API - Backward compatible (doesn't break existing code) - Well-documented with real-world examples Total: 279 lines (129 code + 150 documentation)
| @@ -0,0 +1,150 @@ | |||
| # Email Tracking with Gmail.js | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add this documentation to a new markdown-file, rather than the existing README with all the other API documentation?
| api.track.sent_emails = function(callback) { | ||
| if (typeof callback !== 'function') { | ||
| api.tools.error('track.sent_emails requires a callback function'); | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people are using our API in a way which can never succeed, we should throw an error, not return null IMO.
This is anyway a kind of API where people are almost guaranteed to not check the return-value (as you yourself are not doing in your examples).
| api.track.scheduled_emails = function(callback) { | ||
| if (typeof callback !== 'function') { | ||
| api.tools.error('track.scheduled_emails requires a callback function'); | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people are using our API in a way which can never succeed, we should through, not return null IMO.
This is anyway a kind of API where people are almost guaranteed to not check the return-value (as you yourself are not doing in your examples).
| api.track.all_emails = function(callback) { | ||
| if (typeof callback !== 'function') { | ||
| api.tools.error('track.all_emails requires a callback function'); | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people are using our API in a way which can never succeed, we should through, not return null IMO.
This is anyway a kind of API where people are almost guaranteed to not check the return-value (as you yourself are not doing in your examples).
| return { | ||
| sent: sentCallback, | ||
| scheduled: scheduledCallback | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What value does it provide to return these items? If the intent is to allow people to unregister, the API should provide symmetric means of doing so.
| }; | ||
| }; | ||
|
|
||
| return api; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All in all I'm positive to these changes. It makes some functionality more up-front and accessible. That's good!
One thing though, when adding new APIs, make sure to add the type-definitions for those new APIs to gmail.d.ts as well.
We have many typescript users these days 😄
Summary
This PR adds a new
gmail.tracknamespace with easy-to-use helper functions for tracking sent emails, directly addressing the user request in issue #646.Fixes #646
Problem
Users wanted a simple way to track sent emails but found the existing
observe.on()API confusing, especially for beginners (as mentioned in #646).Solution
Added a new
gmail.tracknamespace that provides:observe.on()functionalityChanges
New API Functions (129 lines in
src/gmail.js)1.
gmail.track.sent_emails(callback)Track emails when they are sent immediately.
2.
gmail.track.scheduled_emails(callback)Track emails when they are scheduled for later.
3.
gmail.track.all_emails(callback)Track both sent and scheduled emails with a single callback.
4.
gmail.track.logger(prefix)Built-in logger for debugging and testing.
Documentation (150 lines in
examples/email-tracking.md)Comprehensive guide including:
Benefits
1. Beginner-Friendly
2. Solves Issue #646
3. Backward Compatible
observe.on()4. Well-Documented
API Comparison
Old Way (confusing for beginners)
New Way (intuitive)
Use Cases
The documentation includes examples for:
Testing
The new functions:
Code Quality
api.tools.error()Total Changes
279 lines added across 2 files:
src/gmail.js: 129 lines (new API functions)examples/email-tracking.md: 150 lines (documentation)Related
observe.on()APIsend_messageandsend_scheduled_messageeventsFuture Enhancements
Potential additions (not in this PR):
gmail.track.off()for removing observersgmail.track.stats()for built-in analyticsgmail.track.export()for data exportContribution by Gittensor, learn more at https://gittensor.io/