@astralibx/email-analytics 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +13 -20
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -75,27 +75,20 @@ import { createEmailAnalytics } from '@astralibx/email-analytics';
75
75
 
76
76
  const analytics = createEmailAnalytics({ db: { connection: conn } });
77
77
  const accountManager = createEmailAccountManager({ db: { connection: conn } });
78
- const ruleEngine = createEmailRuleEngine({ db: { connection: conn } });
79
-
80
- // Record events from rule engine execution
81
- ruleEngine.on('emailSent', async (detail) => {
82
- await analytics.events.record({
83
- type: 'sent',
84
- accountId: detail.accountId,
85
- ruleId: detail.ruleId,
86
- templateId: detail.templateId,
87
- recipientEmail: detail.recipientEmail,
88
- });
89
- });
90
78
 
91
- ruleEngine.on('emailFailed', async (detail) => {
92
- await analytics.events.record({
93
- type: 'failed',
94
- accountId: detail.accountId,
95
- ruleId: detail.ruleId,
96
- recipientEmail: detail.recipientEmail,
97
- metadata: { error: detail.error },
98
- });
79
+ // Record events via rule engine hooks config
80
+ const ruleEngine = createEmailRuleEngine({
81
+ db: { connection: conn },
82
+ hooks: {
83
+ onSend: async ({ ruleId, ruleName, email, status }) => {
84
+ await analytics.events.record({
85
+ type: status === 'sent' ? 'sent' : 'failed',
86
+ accountId: '...', // from your send context
87
+ recipientEmail: email,
88
+ ruleId,
89
+ });
90
+ },
91
+ },
99
92
  });
100
93
  ```
101
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astralibx/email-analytics",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Email analytics with event recording, aggregation, time-series, and querying",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",