Skip to content
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

Added open events for transactional emails #22287

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sam-lord
Copy link
Contributor

ref BAE-383

Uses the Ghost Setting to determine whether these are tracked. These are not used in Ghost Admin but just within Mailgun. For self-hosters, this allows for better analytics in the Mailgun interface.

ref BAE-383
Uses the Ghost Setting to determine whether these are tracked. These
are not used in Ghost Admin but just within Mailgun. For self-hosters,
this allows for better analytics in the Mailgun interface.
@sam-lord sam-lord requested review from lsinger and aileen February 26, 2025 16:12
@sam-lord sam-lord self-assigned this Feb 26, 2025
Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

The changes implement dynamic control over email open tracking across several modules. A new parameter, settingsCache, is introduced to service constructors and modules such as NewslettersService, MagicLink, and MembersAPI to allow retrieval of the email_track_opens setting. A new method, getOpenTrackingEnabled, is added in the services and during magic link initialization to conditionally apply the email header for open tracking. Additionally, corresponding test cases have been introduced to verify both enabled and disabled states for open tracking when sending magic links. The modifications work by propagating the configuration setting through the application's service layers and ensuring that emails reflect the correct tracking header based on the configuration.

Suggested labels

browser-tests, deploy-to-staging

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
ghost/core/test/e2e-api/members/send-magic-link.test.js (1)

381-421: Tests properly verify open tracking functionality.

The new test suite effectively verifies both enabling and disabling of email open tracking. The first test confirms that when email_track_opens is set to true, emails include the o:tracking-opens: true header. The second test verifies behavior when tracking is disabled.

There is a TODO comment on line 415 noting that the test doesn't validate that the o:tracking-opens header is unset. Consider enhancing this test to explicitly verify the absence of the header when tracking is disabled.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8626f70 and 83472d2.

📒 Files selected for processing (6)
  • ghost/core/core/server/services/newsletters/NewslettersService.js (2 hunks)
  • ghost/core/core/server/services/newsletters/index.js (2 hunks)
  • ghost/core/core/server/services/settings/SettingsBREADService.js (1 hunks)
  • ghost/core/test/e2e-api/members/send-magic-link.test.js (1 hunks)
  • ghost/magic-link/lib/MagicLink.js (3 hunks)
  • ghost/members-api/lib/members-api.js (1 hunks)
🔇 Additional comments (7)
ghost/core/core/server/services/newsletters/index.js (2)

9-9: Good addition of settingsCache module.

The addition of the settingsCache module is necessary to enable dynamic control of email open tracking.


26-26: Properly injected settingsCache dependency.

The settingsCache is correctly provided to the NewslettersService, following good dependency injection principles.

ghost/magic-link/lib/MagicLink.js (1)

33-33: Added new optional parameter for dynamic open tracking.

The new getOpenTrackingEnabled parameter is well-documented and properly stored as an instance property.

Also applies to: 46-46

ghost/members-api/lib/members-api.js (1)

160-160: Properly implemented open tracking setting access.

The implementation correctly passes a function that retrieves the email_track_opens setting from the settings cache to the MagicLink service.

ghost/core/core/server/services/settings/SettingsBREADService.js (1)

82-82: Consistent implementation of open tracking getter.

The implementation is consistent with other services, providing the same function to retrieve the email tracking setting from the settings cache.

ghost/core/core/server/services/newsletters/NewslettersService.js (2)

26-26: LGTM! Parameter addition for configurable open tracking.

The settingsCache parameter is properly added to the constructor options.

Also applies to: 31-31


88-88: Good implementation of dynamic open tracking configuration.

The getOpenTrackingEnabled method correctly retrieves the email_track_opens setting from the settingsCache, enabling dynamic control of email open tracking across the application.

Comment on lines +78 to +89
const mailObject = {
to: options.email,
subject: this.getSubject(type),
text: this.getText(url, type, options.email),
html: this.getHTML(url, type, options.email)
});
};

if (await this.getOpenTrackingEnabled()) {
mailObject['o:tracking-opens'] = true;
}

const info = await this.transporter.sendMail(mailObject);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing null check for getOpenTrackingEnabled.

The code doesn't check if this.getOpenTrackingEnabled is defined before calling it, which could cause runtime errors if the function is not provided when instantiating MagicLink.

Add a null check before calling the function:

-        if (await this.getOpenTrackingEnabled()) {
+        if (this.getOpenTrackingEnabled && await this.getOpenTrackingEnabled()) {
            mailObject['o:tracking-opens'] = true;
        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const mailObject = {
to: options.email,
subject: this.getSubject(type),
text: this.getText(url, type, options.email),
html: this.getHTML(url, type, options.email)
});
};
if (await this.getOpenTrackingEnabled()) {
mailObject['o:tracking-opens'] = true;
}
const info = await this.transporter.sendMail(mailObject);
const mailObject = {
to: options.email,
subject: this.getSubject(type),
text: this.getText(url, type, options.email),
html: this.getHTML(url, type, options.email)
};
- if (await this.getOpenTrackingEnabled()) {
+ if (this.getOpenTrackingEnabled && await this.getOpenTrackingEnabled()) {
mailObject['o:tracking-opens'] = true;
}
const info = await this.transporter.sendMail(mailObject);

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