@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.
- package/README.md +13 -20
- 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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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