Commit Graph

10 Commits

Author SHA1 Message Date
Daniel Lockyer
6fc4aa8c4b
Reworked testing and documentation for email-analytics-provider-mailgun
- the tests here were no longer relevant because they were more testing
  things that have been moved to `mailgun-client`
- this commit cleans up the tests to ensure we're passing the correct
  parameters to the mailgun client package
- also adds jsdoc on all the functions and maintains 100% code coverage
2022-08-11 10:30:12 +02:00
Daniel Lockyer
bf254b9c6a Extracted Mailgun client to separate package
refs https://github.com/TryGhost/Toolbox/issues/363

- this commit pulls all code involving the Mailgun client SDK into one
  new package called `mailgun-client`
- this means we should be able to replace `mailgun-js` (deprecated) with
  `mailgun.js` (the new, official one) without editing code all over the
  place
- this also lays some groundwork for better testing of smaller
  components
2022-08-10 17:12:37 +02:00
ceecko
a9cce0281d Added support for eu Mailgun domain (#73)
closes: https://github.com/TryGhost/Ghost/issues/14640

- eu mailgun domains have a different structure. 
- we weren't accounting for this when fetching the next page of results, meaning that email stats didn't work on EU domains
2022-05-02 19:08:30 +01:00
Sam Lord
a96cf1a39a Use @tryghost/logging package instead of injected argument
refs: https://github.com/TryGhost/Toolbox/issues/146
2021-12-02 12:26:23 +00:00
Naz
b5de031b42 Added debug logs to event fetch loop
refs https://linear.app/tryghost/issue/CORE-91/add-email-analytics-job-unstalling-mechanism

- Additional logs should give more insight into what's going on during event fetching
2021-10-11 17:15:35 +02:00
Kevin Ansfield
0145c925a0 Added email analytics mailgun provider tests 2021-02-25 20:04:17 +00:00
Kevin Ansfield
88c648636c Initial update of email analytics packages to work as external modules
refs https://github.com/TryGhost/Ghost/pull/12541

- make `EventProcessor` a super-class designed to be inherited from in consumer applications for application-level implementation
  - helps to keep application-level concerns for event handling (eg, what to do with spam complaints) and things like application database knowledge in the consumer
- removed all database knowledge from `EmailAnalyticsService`
  - requires a `queries` option to be passed in that lets the consuming application provide knowledge and define how fetched stats should be aggregated
2021-02-24 21:23:56 +00:00
Kevin Ansfield
723218ee34 Added guard for page.items existing in Mailgun response
no issue

- it's possible to get Mailgun responses where the `items` array doesn't exist so we need to guard against that so we don't error
2021-02-24 21:03:29 +00:00
Kevin Ansfield
837334b536 Fixed linting 2021-02-24 21:03:29 +00:00
Kevin Ansfield
7bbf644d0d Added email analytics service (#12393)
no issue

- added `EmailAnalyticsService`
  - `.fetchAll()` grabs and processes all available events
  - `.fetchLatest()` grabs and processes all events since the last seen event timestamp
  - `EventProcessor` passed event objects and updates `email_recipients` or `members` records depending on the event being analytics or list hygiene
    - always returns a `EventProcessingResult` instance so that progress can be tracked and merged across individual events, batches (pages of events), and total runs
    - adds email_id and member_id to the returned result where appropriate so that the stats aggregator can limit processing to data that has changed
    - sets `email_recipients.{delivered_at, opened_at, failed_at}` for analytics events
    - sets `members.subscribed = false` for permanent failure/unsubscribed/complained list hygiene events
  - `StatsAggregator` takes an `EventProcessingResult`-like object containing arrays of email ids and member ids on which to aggregate statistics.
  - jobs for `fetch-latest` and `fetch-all` ready for use with the JobsService
- added `initialiseRecurringJobs()` function to Ghost bootup procedure that schedules the email analytics "fetch latest" job to run every minute
2021-02-24 21:03:29 +00:00