@ak--47/dungeon-master 1.2.3 → 1.3.1
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/CHANGELOG.md +42 -0
- package/README.md +51 -13
- package/dungeons/technical/ad-spend.js +2 -2
- package/dungeons/technical/anonymous-users.js +2 -2
- package/dungeons/technical/array-of-object-lookup.js +2 -4
- package/dungeons/technical/experiments.js +2 -2
- package/dungeons/technical/foobar.js +2 -2
- package/dungeons/technical/group-analytics.js +2 -2
- package/dungeons/technical/mirror-strategies.js +2 -2
- package/dungeons/technical/nested-objects.js +2 -2
- package/dungeons/technical/retention-cadence.js +2 -3
- package/dungeons/technical/sanity.js +2 -2
- package/dungeons/technical/scale-test.js +2 -2
- package/dungeons/technical/scd.js +2 -2
- package/dungeons/technical/simple.js +5 -6
- package/dungeons/technical/simplest-schema.json +5 -0
- package/dungeons/technical/simplest.js +2 -2
- package/dungeons/technical/text-generation.js +3 -3
- package/dungeons/vertical/ai-platform.js +858 -0
- package/dungeons/vertical/community.js +84 -40
- package/dungeons/vertical/crypto.js +830 -0
- package/dungeons/vertical/dating.js +744 -0
- package/dungeons/vertical/devtools.js +175 -69
- package/dungeons/vertical/ecommerce.js +242 -94
- package/dungeons/vertical/education.js +330 -313
- package/dungeons/vertical/fintech.js +442 -313
- package/dungeons/vertical/fitness.js +143 -61
- package/dungeons/vertical/food-delivery.js +327 -353
- package/dungeons/vertical/gaming.js +912 -382
- package/dungeons/vertical/healthcare.js +142 -63
- package/dungeons/vertical/insurance-application.js +170 -76
- package/dungeons/vertical/logistics.js +115 -20
- package/dungeons/vertical/marketplace.js +152 -58
- package/dungeons/vertical/media.js +248 -384
- package/dungeons/vertical/real-estate.js +781 -0
- package/dungeons/vertical/sass.js +255 -266
- package/dungeons/vertical/social.js +264 -206
- package/dungeons/vertical/travel.js +117 -41
- package/index.js +17 -17
- package/lib/core/config-validator.js +159 -31
- package/lib/core/context.js +10 -24
- package/lib/core/storage.js +6 -1
- package/lib/generators/events.js +11 -14
- package/lib/generators/funnels.js +12 -4
- package/lib/generators/mirror.js +3 -2
- package/lib/generators/product-names.js +1 -1
- package/lib/generators/scd.js +2 -1
- package/lib/generators/text.js +1 -1
- package/lib/orchestrators/user-loop.js +81 -47
- package/lib/templates/macro-presets.js +111 -0
- package/lib/templates/soup-presets.js +19 -36
- package/lib/utils/utils.js +71 -39
- package/package.json +8 -2
- package/scripts/smoke-test-all.mjs +162 -0
- package/scripts/verify-runner.mjs +72 -24
- package/types.d.ts +251 -51
- package/dungeons/technical/ad-spend-schema.json +0 -128
- package/dungeons/technical/anonymous-users-schema.json +0 -92
- package/dungeons/technical/array-of-object-lookup-schema.json +0 -191
- package/dungeons/technical/experiments-schema.json +0 -203
- package/dungeons/technical/foobar-schema.json +0 -362
- package/dungeons/technical/group-analytics-schema.json +0 -241
- package/dungeons/technical/mirror-strategies-schema.json +0 -84
- package/dungeons/technical/nested-objects-schema.json +0 -145
- package/dungeons/technical/retention-cadence-schema.json +0 -37
- package/dungeons/technical/sanity-schema.json +0 -185
- package/dungeons/technical/scale-test-schema.json +0 -70
- package/dungeons/technical/scd-schema.json +0 -467
- package/dungeons/technical/simple-schema.json +0 -362
- package/dungeons/technical/text-generation-schema.json +0 -1062
- package/dungeons/user/.gitkeep +0 -0
- package/dungeons/vertical/community-schema.json +0 -579
- package/dungeons/vertical/devtools-schema.json +0 -601
- package/dungeons/vertical/ecommerce-schema.json +0 -604
- package/dungeons/vertical/education-schema.json +0 -5686
- package/dungeons/vertical/fintech-schema.json +0 -630
- package/dungeons/vertical/fitness-schema.json +0 -530
- package/dungeons/vertical/food-delivery-schema.json +0 -36728
- package/dungeons/vertical/gaming-schema.json +0 -438
- package/dungeons/vertical/healthcare-schema.json +0 -549
- package/dungeons/vertical/insurance-application-schema.json +0 -485
- package/dungeons/vertical/logistics-schema.json +0 -574
- package/dungeons/vertical/marketplace-schema.json +0 -533
- package/dungeons/vertical/media-schema.json +0 -4749
- package/dungeons/vertical/rpg-schema.json +0 -2491
- package/dungeons/vertical/rpg.js +0 -976
- package/dungeons/vertical/sass-schema.json +0 -3128
- package/dungeons/vertical/social-schema.json +0 -620
- package/dungeons/vertical/travel-schema.json +0 -580
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const SEED = "harness-fintech";
|
|
3
3
|
const num_days = 100;
|
|
4
4
|
const num_users = 5_000;
|
|
5
|
-
const
|
|
5
|
+
const avg_events_per_user_per_day = 1.2;
|
|
6
6
|
let token = "your-mixpanel-token";
|
|
7
7
|
|
|
8
8
|
// ── env overrides ──
|
|
@@ -15,7 +15,6 @@ import * as u from "../../lib/utils/utils.js";
|
|
|
15
15
|
|
|
16
16
|
dayjs.extend(utc);
|
|
17
17
|
const chance = u.initChance(SEED);
|
|
18
|
-
|
|
19
18
|
/** @typedef {import("../../types").Dungeon} Config */
|
|
20
19
|
|
|
21
20
|
/**
|
|
@@ -48,58 +47,223 @@ const chance = u.initChance(SEED);
|
|
|
48
47
|
|
|
49
48
|
/**
|
|
50
49
|
* ===================================================================
|
|
51
|
-
* ANALYTICS HOOKS (
|
|
50
|
+
* ANALYTICS HOOKS (10 hooks)
|
|
52
51
|
* ===================================================================
|
|
53
52
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
53
|
+
* NOTE: All cohort effects are HIDDEN — no flag stamping. Discoverable
|
|
54
|
+
* via behavioral cohorts, raw-prop breakdowns (date, account_tier),
|
|
55
|
+
* or funnel time-to-convert.
|
|
56
|
+
*
|
|
57
|
+
* 1. PERSONAL VS BUSINESS ACCOUNTS (user)
|
|
58
|
+
*
|
|
59
|
+
* PATTERN: 20% of accounts are business (employee_count, revenue,
|
|
60
|
+
* industry attached) and 80% are personal (age_range, life_stage).
|
|
61
|
+
* Account segment shapes downstream transaction sizes.
|
|
62
|
+
*
|
|
63
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
64
|
+
*
|
|
65
|
+
* Report 1: Account Segment Mix
|
|
66
|
+
* - Report type: Insights
|
|
67
|
+
* - Event: any event
|
|
68
|
+
* - Measure: Unique users
|
|
69
|
+
* - Breakdown: "account_segment"
|
|
70
|
+
* - Expected: ~80% personal, ~20% business
|
|
71
|
+
*
|
|
72
|
+
* Report 2: Transaction Size by Segment
|
|
73
|
+
* - Report type: Insights
|
|
74
|
+
* - Event: "transaction completed"
|
|
75
|
+
* - Measure: Average of "amount"
|
|
76
|
+
* - Breakdown: "account_segment"
|
|
77
|
+
* - Expected: business ~ $200+, personal ~ $50 (~4x larger)
|
|
78
|
+
*
|
|
79
|
+
* REAL-WORLD ANALOGUE: Neobanks serve both consumers and small
|
|
80
|
+
* businesses with the same core product, but business activity is
|
|
81
|
+
* meaningfully higher value per transaction.
|
|
82
|
+
*
|
|
83
|
+
* ---------------------------------------------------------------
|
|
84
|
+
* 2. PAYDAY PATTERNS (everything)
|
|
85
|
+
*
|
|
86
|
+
* PATTERN: Direct deposit transactions are 3x larger on the 1st and
|
|
87
|
+
* 15th of the month. Transfers are ~1.6x larger on the 1st-3rd and
|
|
88
|
+
* 15th-17th (60% likelihood × 2x boost). No flag — discover via day-of-month
|
|
89
|
+
* breakdown on raw amount.
|
|
90
|
+
*
|
|
91
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
92
|
+
*
|
|
93
|
+
* Report 1: Direct Deposit Size by Day of Month
|
|
94
|
+
* - Report type: Insights
|
|
95
|
+
* - Event: "transaction completed"
|
|
96
|
+
* - Measure: Average of "amount"
|
|
97
|
+
* - Filter: "transaction_type" = "direct_deposit"
|
|
98
|
+
* - Breakdown: day of month
|
|
99
|
+
* - Expected: 1st and 15th avg ~ 3x other days
|
|
100
|
+
*
|
|
101
|
+
* Report 2: Post-Payday Transfer Spending by Day of Month
|
|
102
|
+
* - Report type: Insights
|
|
103
|
+
* - Event: "transfer sent"
|
|
104
|
+
* - Measure: Average of "amount"
|
|
105
|
+
* - Breakdown: day of month
|
|
106
|
+
* - Expected: 1-3 and 15-17 avg ~ 1.6x other days
|
|
107
|
+
*
|
|
108
|
+
* REAL-WORLD ANALOGUE: Bi-monthly payroll cycles drive predictable
|
|
109
|
+
* spikes in deposit and outbound spending volume.
|
|
110
|
+
*
|
|
111
|
+
* ---------------------------------------------------------------
|
|
112
|
+
* 3. FRAUD DETECTION (everything)
|
|
113
|
+
*
|
|
114
|
+
* PATTERN: ~1-2% of users experience a fraud burst at the timeline
|
|
115
|
+
* midpoint: 3-5 rapid high-value transactions, then card locked
|
|
116
|
+
* (reason="suspicious_activity"), dispute filed (reason="unauthorized"),
|
|
117
|
+
* and support contacted (issue_type="card"). No flag — derive cohort
|
|
118
|
+
* by joining users who had all three event types within ~1 hour.
|
|
119
|
+
*
|
|
120
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
121
|
+
*
|
|
122
|
+
* Report 1: Fraud Cohort
|
|
123
|
+
* - Report type: Cohort builder
|
|
124
|
+
* - Filter: did "card locked" with reason="suspicious_activity"
|
|
125
|
+
* AND "dispute filed" with reason="unauthorized"
|
|
126
|
+
* within 1 hour of each other
|
|
127
|
+
* - Expected: ~1-2% of total users
|
|
128
|
+
*
|
|
129
|
+
* Report 2: Fraud Resolution Funnel
|
|
130
|
+
* - Report type: Funnels
|
|
131
|
+
* - Steps: "card locked" -> "dispute filed" -> "support contacted"
|
|
132
|
+
* - Filter: card locked.reason = "suspicious_activity"
|
|
133
|
+
* - Expected: high completion across all three resolution steps
|
|
134
|
+
*
|
|
135
|
+
* REAL-WORLD ANALOGUE: A small but consistent slice of accounts
|
|
136
|
+
* triggers fraud pipelines every cycle, generating the bulk of
|
|
137
|
+
* dispute and support load.
|
|
138
|
+
*
|
|
139
|
+
* ---------------------------------------------------------------
|
|
140
|
+
* 4. LOW BALANCE CHURN (everything)
|
|
141
|
+
*
|
|
142
|
+
* PATTERN: Users with 3+ "balance checked" events where account_balance
|
|
143
|
+
* < $15K lose 50% of their events after day 30. No flag — derive cohort
|
|
144
|
+
* by counting low-balance checks per user.
|
|
145
|
+
*
|
|
146
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
147
|
+
*
|
|
148
|
+
* Report 1: Activity by Low Balance Cohort
|
|
149
|
+
* - Cohort A: users with >= 3 "balance checked" where account_balance < 15000
|
|
150
|
+
* - Cohort B: users with < 3
|
|
151
|
+
* - Event: any event
|
|
152
|
+
* - Measure: Total per user, line chart by day
|
|
153
|
+
* - Expected: A growth post-d30 ~ 0.5x B's growth (suppressed)
|
|
154
|
+
*
|
|
155
|
+
* Report 2: Activity Decline Timeline
|
|
156
|
+
* - Report type: Insights (with cohort A above)
|
|
157
|
+
* - Event: any event
|
|
158
|
+
* - Measure: Total
|
|
159
|
+
* - Line chart by day
|
|
160
|
+
* - Expected: pre-d30/post-d30 ratio ~ 1.0x for A vs ~ 2.0x for B
|
|
161
|
+
*
|
|
162
|
+
* REAL-WORLD ANALOGUE: Customers running thin balances lose trust
|
|
163
|
+
* in the platform and migrate their primary banking elsewhere.
|
|
164
|
+
*
|
|
165
|
+
* ---------------------------------------------------------------
|
|
166
|
+
* 5. BUDGET USERS SAVE MORE (everything)
|
|
167
|
+
*
|
|
168
|
+
* PATTERN: Users with any "budget created" event get 2x savings
|
|
169
|
+
* contributions, 1.5x investment amounts, and extra cloned savings
|
|
170
|
+
* goal events. No flag — derive cohort behaviorally.
|
|
171
|
+
*
|
|
172
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
173
|
+
*
|
|
174
|
+
* Report 1: Savings Contribution by Budget Cohort
|
|
175
|
+
* - Cohort A: users with >= 1 "budget created" event
|
|
176
|
+
* - Cohort B: users with 0
|
|
177
|
+
* - Event: "savings goal set"
|
|
178
|
+
* - Measure: Average of "monthly_contribution"
|
|
179
|
+
* - Expected: A ~ 2x B
|
|
180
|
+
*
|
|
181
|
+
* Report 2: Investment Size by Budget Cohort
|
|
182
|
+
* - Cohort A vs B (as above)
|
|
183
|
+
* - Event: "investment made"
|
|
184
|
+
* - Measure: Average of "amount"
|
|
185
|
+
* - Expected: A ~ 1.5x B
|
|
186
|
+
*
|
|
187
|
+
* REAL-WORLD ANALOGUE: Active budget tooling correlates strongly
|
|
188
|
+
* with healthier savings rates and broader product adoption.
|
|
189
|
+
*
|
|
190
|
+
* ---------------------------------------------------------------
|
|
191
|
+
* 6. AUTO-PAY LOYALTY (event)
|
|
192
|
+
*
|
|
193
|
+
* PATTERN: Manual payers (auto_pay=false) miss 30% of their bill
|
|
194
|
+
* payments — those events are renamed to "bill payment missed".
|
|
195
|
+
* Auto-pay users never miss.
|
|
196
|
+
*
|
|
197
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
198
|
+
*
|
|
199
|
+
* Report 1: Bill Outcomes by Manual vs Auto-Pay
|
|
200
|
+
* - Report type: Insights
|
|
201
|
+
* - Events: "bill paid" and "bill payment missed"
|
|
202
|
+
* - Measure: Total
|
|
203
|
+
* - Expected: missed events appear only for manual payers, ~30% rate
|
|
204
|
+
*
|
|
205
|
+
* Report 2: Bill Completion Rate by Auto-Pay
|
|
206
|
+
* - Report type: Insights
|
|
207
|
+
* - Event: "bill paid"
|
|
208
|
+
* - Measure: Total
|
|
209
|
+
* - Breakdown: "auto_pay"
|
|
210
|
+
* - Expected: auto_pay=false ~ 70% completion vs auto_pay=true ~ 100%
|
|
211
|
+
*
|
|
212
|
+
* REAL-WORLD ANALOGUE: Auto-pay locks users into a frictionless
|
|
213
|
+
* payment cadence that virtually eliminates missed bills.
|
|
214
|
+
*
|
|
215
|
+
* ---------------------------------------------------------------
|
|
216
|
+
* 7. PREMIUM TIER VALUE (event)
|
|
217
|
+
*
|
|
218
|
+
* PATTERN: Premium-tier users get 3x reward values and 2x sell
|
|
219
|
+
* returns on investments. Plus tier gets 1.5x rewards. No flag —
|
|
220
|
+
* mutates raw "value"/"amount" properties; discover via account_tier breakdown.
|
|
221
|
+
*
|
|
222
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
223
|
+
*
|
|
224
|
+
* Report 1: Reward Value by Tier
|
|
225
|
+
* - Report type: Insights
|
|
226
|
+
* - Event: "reward redeemed"
|
|
227
|
+
* - Measure: Average of "value"
|
|
228
|
+
* - Breakdown: "account_tier"
|
|
229
|
+
* - Expected: Premium ~ $30, Plus ~ $15, Basic ~ $10
|
|
230
|
+
*
|
|
231
|
+
* Report 2: Investment Sell Amount by Tier
|
|
232
|
+
* - Report type: Insights
|
|
233
|
+
* - Event: "investment made"
|
|
234
|
+
* - Measure: Average of "amount"
|
|
235
|
+
* - Filter: "action" = "sell"
|
|
236
|
+
* - Breakdown: "account_tier"
|
|
237
|
+
* - Expected: Premium ~ 2x baseline; Basic/Plus baseline
|
|
238
|
+
*
|
|
239
|
+
* REAL-WORLD ANALOGUE: Premium subscription tiers justify their
|
|
240
|
+
* price by delivering visibly better cashback and investment perks.
|
|
241
|
+
*
|
|
242
|
+
* ---------------------------------------------------------------
|
|
243
|
+
* 8. MONTH-END ANXIETY (everything)
|
|
244
|
+
*
|
|
245
|
+
* PATTERN: On days >= 28 of the calendar month, app sessions run
|
|
246
|
+
* 40% longer and reported balances are 30% lower. No flag — discover
|
|
247
|
+
* via day-of-month breakdown.
|
|
248
|
+
*
|
|
249
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
250
|
+
*
|
|
251
|
+
* Report 1: Session Duration by Day of Month
|
|
252
|
+
* - Report type: Insights
|
|
253
|
+
* - Event: "app session"
|
|
254
|
+
* - Measure: Average of "session_duration_sec"
|
|
255
|
+
* - Breakdown: day of month
|
|
256
|
+
* - Expected: days >= 28 ~ 1.4x other days
|
|
257
|
+
*
|
|
258
|
+
* Report 2: Balance by Day of Month
|
|
259
|
+
* - Report type: Insights
|
|
260
|
+
* - Event: "balance checked"
|
|
261
|
+
* - Measure: Average of "account_balance"
|
|
262
|
+
* - Breakdown: day of month
|
|
263
|
+
* - Expected: days >= 28 ~ 0.7x other days
|
|
264
|
+
*
|
|
265
|
+
* REAL-WORLD ANALOGUE: Users obsessively check balances at month
|
|
266
|
+
* end as bills hit and runway tightens.
|
|
103
267
|
*
|
|
104
268
|
* ===================================================================
|
|
105
269
|
* ADVANCED ANALYSIS IDEAS
|
|
@@ -118,28 +282,78 @@ const chance = u.initChance(SEED);
|
|
|
118
282
|
* - By income_bracket: feature adoption by income
|
|
119
283
|
* - By credit_score_range: loan approvals, tier adoption
|
|
120
284
|
*
|
|
285
|
+
* ---------------------------------------------------------------
|
|
286
|
+
* 9. ONBOARDING TIME-TO-CONVERT (funnel-post)
|
|
287
|
+
*
|
|
288
|
+
* PATTERN: Premium tier users complete the Onboarding funnel 1.5x
|
|
289
|
+
* faster (factor 0.67); Basic users 1.33x slower (factor 1.33).
|
|
290
|
+
*
|
|
291
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
292
|
+
*
|
|
293
|
+
* Report 1: Onboarding Median Time-to-Convert by Tier
|
|
294
|
+
* - Funnels > "account opened" -> "app session" -> "balance checked"
|
|
295
|
+
* - Measure: Median time to convert
|
|
296
|
+
* - Breakdown: account_tier
|
|
297
|
+
* - Expected: premium ~ 0.67x baseline; basic ~ 1.33x
|
|
298
|
+
*
|
|
299
|
+
* NOTE (funnel-post measurement): visible only via Mixpanel funnel
|
|
300
|
+
* median TTC. Cross-event MIN→MIN SQL queries on raw events do NOT
|
|
301
|
+
* show this — funnel-post adjusts gaps within funnel instances, not
|
|
302
|
+
* across the user's full event history.
|
|
303
|
+
*
|
|
304
|
+
* ---------------------------------------------------------------
|
|
305
|
+
* 10. TRANSACTION-COUNT MAGIC NUMBER (everything)
|
|
306
|
+
*
|
|
307
|
+
* PATTERN: Sweet 6-10 transactions/user → +40% on investment-made
|
|
308
|
+
* amount (engaged transactor compounds wealth). Over 11+ → drop 20%
|
|
309
|
+
* of premium-upgraded events. No flag.
|
|
310
|
+
*
|
|
311
|
+
* HOW TO FIND IT IN MIXPANEL:
|
|
312
|
+
*
|
|
313
|
+
* Report 1: Avg Investment Amount by Transaction Bucket
|
|
314
|
+
* - Cohort A: users with 6-10 "transaction completed"
|
|
315
|
+
* - Cohort B: users with 0-5
|
|
316
|
+
* - Event: "investment made"
|
|
317
|
+
* - Measure: Average of "amount"
|
|
318
|
+
* - Expected: A ~ 1.4x B
|
|
319
|
+
*
|
|
320
|
+
* Report 2: Premium Upgrades on Heavy Transactors
|
|
321
|
+
* - Cohort C: users with >= 11 "transaction completed"
|
|
322
|
+
* - Cohort A: users with 6-10
|
|
323
|
+
* - Event: "premium upgraded"
|
|
324
|
+
* - Measure: Total per user
|
|
325
|
+
* - Expected: C ~ 20% fewer upgrades per user
|
|
326
|
+
*
|
|
327
|
+
* REAL-WORLD ANALOGUE: Engaged transactors invest more; over-active
|
|
328
|
+
* already extract value without upgrading.
|
|
329
|
+
*
|
|
121
330
|
* ===================================================================
|
|
122
331
|
* EXPECTED METRICS SUMMARY
|
|
123
332
|
* ===================================================================
|
|
124
333
|
*
|
|
125
|
-
* Hook | Metric | Baseline | Effect
|
|
126
|
-
*
|
|
127
|
-
* Personal vs Business | Avg transaction amt | $50 | $200+
|
|
128
|
-
* Payday Patterns | Deposit
|
|
129
|
-
* Fraud Detection | Users affected | 0% | 3%
|
|
130
|
-
* Low Balance Churn | D30+
|
|
131
|
-
* Budget Discipline |
|
|
132
|
-
* Auto-Pay Loyalty | Bill completion rate
|
|
133
|
-
* Premium Tier Value | Reward value
|
|
134
|
-
* Month-End Anxiety | Session duration |
|
|
334
|
+
* Hook | Metric | Baseline | Effect | Ratio
|
|
335
|
+
* ----------------------|-----------------------|----------|-----------|------
|
|
336
|
+
* Personal vs Business | Avg transaction amt | $50 | $200+ | ~ 4x
|
|
337
|
+
* Payday Patterns | Deposit amt 1st/15th | 1x | 3x | 3x
|
|
338
|
+
* Fraud Detection | Users affected | 0% | 3% | --
|
|
339
|
+
* Low Balance Churn | D30+ events | 1x | 0.5x | -50%
|
|
340
|
+
* Budget Discipline | Savings contribution | 1x | 2x | 2x
|
|
341
|
+
* Auto-Pay Loyalty | Bill completion rate | 100% | 70% | -30%
|
|
342
|
+
* Premium Tier Value | Reward value (Premium)| 1x | 3x | 3x
|
|
343
|
+
* Month-End Anxiety | Session duration d28+ | 1x | 1.4x | 1.4x
|
|
344
|
+
* Onboarding T2C | median min by tier | 1x | 0.67/1.33x| 2x range
|
|
345
|
+
* Txn-Count Magic Num | sweet investment amt | 1x | 1.4x | 1.4x
|
|
346
|
+
* Txn-Count Magic Num | over premium upgrades | 1x | 0.8x | -20%
|
|
135
347
|
*/
|
|
136
348
|
|
|
137
349
|
/** @type {Config} */
|
|
138
350
|
const config = {
|
|
139
351
|
token,
|
|
140
352
|
seed: SEED,
|
|
141
|
-
|
|
142
|
-
|
|
353
|
+
datasetStart: "2026-01-01T00:00:00Z",
|
|
354
|
+
datasetEnd: "2026-04-28T23:59:59Z",
|
|
355
|
+
// numDays: num_days,
|
|
356
|
+
avgEventsPerUserPerDay: avg_events_per_user_per_day,
|
|
143
357
|
numUsers: num_users,
|
|
144
358
|
hasAnonIds: false,
|
|
145
359
|
hasSessionIds: true,
|
|
@@ -154,7 +368,6 @@ const config = {
|
|
|
154
368
|
hasCampaigns: false,
|
|
155
369
|
isAnonymous: false,
|
|
156
370
|
hasAdSpend: false,
|
|
157
|
-
percentUsersBornInDataset: 50,
|
|
158
371
|
|
|
159
372
|
hasAvatar: true,
|
|
160
373
|
|
|
@@ -251,7 +464,6 @@ const config = {
|
|
|
251
464
|
properties: {
|
|
252
465
|
"session_duration_sec": u.weighNumRange(10, 600, 0.3, 60),
|
|
253
466
|
"pages_viewed": u.weighNumRange(1, 15, 0.5, 3),
|
|
254
|
-
"month_end_anxiety": [false],
|
|
255
467
|
}
|
|
256
468
|
},
|
|
257
469
|
{
|
|
@@ -260,7 +472,6 @@ const config = {
|
|
|
260
472
|
properties: {
|
|
261
473
|
"account_balance": u.weighNumRange(0, 50000, 0.8, 2500),
|
|
262
474
|
"account_type": ["checking", "savings", "investment"],
|
|
263
|
-
"month_end_check": [false],
|
|
264
475
|
}
|
|
265
476
|
},
|
|
266
477
|
{
|
|
@@ -271,8 +482,6 @@ const config = {
|
|
|
271
482
|
"amount": u.weighNumRange(1, 5000, 0.3, 50),
|
|
272
483
|
"merchant_category": ["grocery", "restaurant", "gas", "retail", "online", "subscription", "utilities"],
|
|
273
484
|
"payment_method": ["debit", "credit", "contactless", "online"],
|
|
274
|
-
"payday": [false],
|
|
275
|
-
"fraud_sequence": [false],
|
|
276
485
|
}
|
|
277
486
|
},
|
|
278
487
|
{
|
|
@@ -282,7 +491,6 @@ const config = {
|
|
|
282
491
|
"transfer_type": ["internal", "external", "p2p", "wire"],
|
|
283
492
|
"amount": u.weighNumRange(10, 10000, 0.3, 200),
|
|
284
493
|
"recipient_type": ["friend", "family", "business", "self"],
|
|
285
|
-
"post_payday_spending": [false],
|
|
286
494
|
}
|
|
287
495
|
},
|
|
288
496
|
{
|
|
@@ -292,8 +500,14 @@ const config = {
|
|
|
292
500
|
"bill_type": ["rent", "utilities", "phone", "insurance", "subscription", "loan_payment"],
|
|
293
501
|
"amount": u.weighNumRange(20, 3000, 0.5, 150),
|
|
294
502
|
"auto_pay": [false, false, false, true, true],
|
|
295
|
-
|
|
296
|
-
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
event: "bill payment missed",
|
|
507
|
+
weight: 1,
|
|
508
|
+
properties: {
|
|
509
|
+
"bill_type": ["rent", "utilities", "phone", "insurance", "subscription", "loan_payment"],
|
|
510
|
+
"amount": u.weighNumRange(20, 3000, 0.5, 150),
|
|
297
511
|
}
|
|
298
512
|
},
|
|
299
513
|
{
|
|
@@ -319,7 +533,6 @@ const config = {
|
|
|
319
533
|
"goal_type": ["emergency", "vacation", "car", "home", "education", "retirement"],
|
|
320
534
|
"target_amount": u.weighNumRange(500, 50000, 0.3, 5000),
|
|
321
535
|
"monthly_contribution": u.weighNumRange(25, 2000, 0.5, 200),
|
|
322
|
-
"budget_discipline": [false],
|
|
323
536
|
}
|
|
324
537
|
},
|
|
325
538
|
{
|
|
@@ -329,25 +542,21 @@ const config = {
|
|
|
329
542
|
"investment_type": ["stocks", "etf", "crypto", "bonds", "mutual_fund"],
|
|
330
543
|
"amount": u.weighNumRange(10, 10000, 0.3, 250),
|
|
331
544
|
"action": ["buy", "sell", "buy"],
|
|
332
|
-
"premium_returns": [false],
|
|
333
|
-
"budget_discipline": [false],
|
|
334
545
|
}
|
|
335
546
|
},
|
|
336
547
|
{
|
|
337
548
|
event: "card locked",
|
|
338
|
-
weight:
|
|
549
|
+
weight: 2,
|
|
339
550
|
properties: {
|
|
340
551
|
"reason": ["lost", "stolen", "suspicious_activity", "travel"],
|
|
341
|
-
"fraud_sequence": [false],
|
|
342
552
|
}
|
|
343
553
|
},
|
|
344
554
|
{
|
|
345
555
|
event: "dispute filed",
|
|
346
|
-
weight:
|
|
556
|
+
weight: 2,
|
|
347
557
|
properties: {
|
|
348
558
|
"dispute_amount": u.weighNumRange(10, 2000, 0.5, 100),
|
|
349
559
|
"reason": ["unauthorized", "duplicate", "not_received", "damaged", "wrong_amount"],
|
|
350
|
-
"fraud_sequence": [false],
|
|
351
560
|
}
|
|
352
561
|
},
|
|
353
562
|
{
|
|
@@ -383,7 +592,6 @@ const config = {
|
|
|
383
592
|
"channel": ["chat", "phone", "email", "in_app"],
|
|
384
593
|
"issue_type": ["transaction", "account", "card", "transfer", "technical"],
|
|
385
594
|
"resolved": [false, true, true, true, true],
|
|
386
|
-
"fraud_sequence": [false],
|
|
387
595
|
}
|
|
388
596
|
},
|
|
389
597
|
{
|
|
@@ -400,7 +608,6 @@ const config = {
|
|
|
400
608
|
properties: {
|
|
401
609
|
"reward_type": ["cashback", "points", "discount", "partner_offer"],
|
|
402
610
|
"value": u.weighNumRange(1, 100, 0.5, 10),
|
|
403
|
-
"premium_reward": [false],
|
|
404
611
|
}
|
|
405
612
|
}
|
|
406
613
|
],
|
|
@@ -408,13 +615,11 @@ const config = {
|
|
|
408
615
|
superProps: {
|
|
409
616
|
account_tier: ["basic", "basic", "basic", "plus", "plus", "premium"],
|
|
410
617
|
Platform: ["ios", "android", "web"],
|
|
411
|
-
low_balance_churn: [false],
|
|
412
618
|
},
|
|
413
619
|
|
|
414
620
|
userProps: {
|
|
415
621
|
account_tier: ["basic", "basic", "basic", "plus", "plus", "premium"],
|
|
416
622
|
Platform: ["ios", "android", "web"],
|
|
417
|
-
low_balance_churn: [false],
|
|
418
623
|
"credit_score_range": ["300-579", "580-669", "670-739", "740-799", "800-850"],
|
|
419
624
|
"income_bracket": ["under_30k", "30k_50k", "50k_75k", "75k_100k", "100k_150k", "over_150k"],
|
|
420
625
|
"account_age_months": u.weighNumRange(1, 60, 0.5, 12),
|
|
@@ -449,24 +654,16 @@ const config = {
|
|
|
449
654
|
* This hook function creates 8 deliberate patterns in the data:
|
|
450
655
|
*
|
|
451
656
|
* 1. PERSONAL VS BUSINESS: Business accounts get employee_count, revenue; personal get age_range, life_stage
|
|
452
|
-
* 2. PAYDAY PATTERNS: Transactions spike on 1st/15th with bigger deposits and post-payday spending
|
|
657
|
+
* 2. PAYDAY PATTERNS: Transactions spike on 1st/15th with bigger deposits and post-payday spending (everything hook — runs after sessionization)
|
|
453
658
|
* 3. FRAUD DETECTION: 3% of users experience a fraud burst (rapid high-value txns -> card lock -> dispute -> support)
|
|
454
659
|
* 4. LOW BALANCE CHURN: Users with chronic low balances (<$15K) lose 50% of activity after day 30
|
|
455
660
|
* 5. BUDGET DISCIPLINE: Budget creators save 2x more and invest 1.5x more
|
|
456
661
|
* 6. AUTO-PAY LOYALTY: Auto-pay users never miss bills; manual payers miss 30%
|
|
457
662
|
* 7. PREMIUM TIER VALUE: Premium users get 3x rewards; Plus users get 1.5x; Premium investors get 2x returns
|
|
458
|
-
* 8. MONTH-END ANXIETY: Last 3 days of month see 40% longer sessions and 30% lower balances
|
|
663
|
+
* 8. MONTH-END ANXIETY: Last 3 days of month see 40% longer sessions and 30% lower balances (everything hook — runs after sessionization)
|
|
459
664
|
*/
|
|
460
665
|
hook: function (record, type, meta) {
|
|
461
|
-
|
|
462
|
-
const DATASET_START = NOW.subtract(num_days, "days");
|
|
463
|
-
|
|
464
|
-
// ===============================================================
|
|
465
|
-
// Hook #1: PERSONAL VS BUSINESS ACCOUNTS (user)
|
|
466
|
-
// 20% of users are randomly tagged as business accounts with
|
|
467
|
-
// employee_count, annual_revenue, and industry. The other 80% get
|
|
468
|
-
// personal attributes: age_range and life_stage.
|
|
469
|
-
// ===============================================================
|
|
666
|
+
// HOOK 1: PERSONAL VS BUSINESS ACCOUNTS (user) — role-based attrs.
|
|
470
667
|
if (type === "user") {
|
|
471
668
|
const isBusiness = chance.bool({ likelihood: 20 });
|
|
472
669
|
if (isBusiness) {
|
|
@@ -481,282 +678,214 @@ const config = {
|
|
|
481
678
|
}
|
|
482
679
|
}
|
|
483
680
|
|
|
484
|
-
//
|
|
485
|
-
//
|
|
486
|
-
// On the 1st and 15th, direct deposit transactions are 2x bigger
|
|
487
|
-
// and tagged with payday: true. On days 1-3 and 15-17, transfers
|
|
488
|
-
// have a 40% chance of 1.5x boost (post-payday spending).
|
|
489
|
-
// ===============================================================
|
|
681
|
+
// HOOK 6: AUTO-PAY LOYALTY (event) — manual bill-paid events have
|
|
682
|
+
// 30% chance of becoming "bill payment missed". Mutates event name.
|
|
490
683
|
if (type === "event") {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
// Payday: 1st and 15th
|
|
495
|
-
if (record.event === "transaction completed" && record.transaction_type === "direct_deposit") {
|
|
496
|
-
if (dayOfMonth === 1 || dayOfMonth === 15) {
|
|
497
|
-
record.amount = Math.floor((record.amount || 50) * 3);
|
|
498
|
-
record.payday = true;
|
|
499
|
-
} else {
|
|
500
|
-
record.payday = false;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
// Post-payday spending: days 1-3 and 15-17
|
|
505
|
-
if (record.event === "transfer sent") {
|
|
506
|
-
const isPaydayWindow = (dayOfMonth >= 1 && dayOfMonth <= 3) || (dayOfMonth >= 15 && dayOfMonth <= 17);
|
|
507
|
-
if (isPaydayWindow && chance.bool({ likelihood: 60 })) {
|
|
508
|
-
record.amount = Math.floor((record.amount || 200) * 2.0);
|
|
509
|
-
record.post_payday_spending = true;
|
|
510
|
-
} else {
|
|
511
|
-
record.post_payday_spending = false;
|
|
512
|
-
}
|
|
684
|
+
if (record.event === "bill paid" && record.auto_pay !== true && chance.bool({ likelihood: 30 })) {
|
|
685
|
+
record.event = "bill payment missed";
|
|
513
686
|
}
|
|
687
|
+
}
|
|
514
688
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
record.
|
|
689
|
+
// HOOK 9 (T2C): ONBOARDING TIME-TO-CONVERT (funnel-post)
|
|
690
|
+
// Premium tier completes Onboarding funnel 1.5x faster (factor 0.67);
|
|
691
|
+
// Basic users 1.33x slower (factor 1.33).
|
|
692
|
+
if (type === "funnel-post") {
|
|
693
|
+
const segment = meta?.profile?.account_tier;
|
|
694
|
+
if (Array.isArray(record) && record.length > 1) {
|
|
695
|
+
const factor = (
|
|
696
|
+
segment === "premium" ? 0.67 :
|
|
697
|
+
segment === "basic" ? 1.33 :
|
|
698
|
+
1.0
|
|
699
|
+
);
|
|
700
|
+
if (factor !== 1.0) {
|
|
701
|
+
for (let i = 1; i < record.length; i++) {
|
|
702
|
+
const prev = dayjs(record[i - 1].time);
|
|
703
|
+
const newGap = Math.round(dayjs(record[i].time).diff(prev) * factor);
|
|
704
|
+
record[i].time = prev.add(newGap, "milliseconds").toISOString();
|
|
530
705
|
}
|
|
531
|
-
} else {
|
|
532
|
-
record.missed_payment = false;
|
|
533
|
-
record.manual_payment = false;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// ===============================================================
|
|
538
|
-
// Hook #7: PREMIUM TIER VALUE (event)
|
|
539
|
-
// Premium tier users get 3x reward values and 2x investment sell
|
|
540
|
-
// returns. Plus tier users get 1.5x rewards.
|
|
541
|
-
// ===============================================================
|
|
542
|
-
if (record.event === "reward redeemed") {
|
|
543
|
-
if (record.account_tier === "premium") {
|
|
544
|
-
record.value = Math.floor((record.value || 10) * 3);
|
|
545
|
-
record.premium_reward = true;
|
|
546
|
-
} else if (record.account_tier === "plus") {
|
|
547
|
-
record.value = Math.floor((record.value || 10) * 1.5);
|
|
548
|
-
record.premium_reward = false;
|
|
549
|
-
} else {
|
|
550
|
-
record.premium_reward = false;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
if (record.event === "investment made" && record.action === "sell") {
|
|
555
|
-
if (record.account_tier === "premium") {
|
|
556
|
-
record.amount = Math.floor((record.amount || 250) * 2);
|
|
557
|
-
record.premium_returns = true;
|
|
558
|
-
} else {
|
|
559
|
-
record.premium_returns = false;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// ===============================================================
|
|
564
|
-
// Hook #8: MONTH-END ANXIETY (event)
|
|
565
|
-
// Last 3 days of month (day >= 28) see 40% longer app sessions
|
|
566
|
-
// and 30% lower balances when checked.
|
|
567
|
-
// ===============================================================
|
|
568
|
-
if (record.event === "app session") {
|
|
569
|
-
if (dayOfMonth >= 28) {
|
|
570
|
-
record.session_duration_sec = Math.floor((record.session_duration_sec || 60) * 1.4);
|
|
571
|
-
record.month_end_anxiety = true;
|
|
572
|
-
} else {
|
|
573
|
-
record.month_end_anxiety = false;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (record.event === "balance checked") {
|
|
578
|
-
if (dayOfMonth >= 28) {
|
|
579
|
-
record.account_balance = Math.floor((record.account_balance || 2500) * 0.7);
|
|
580
|
-
record.month_end_check = true;
|
|
581
|
-
} else {
|
|
582
|
-
record.month_end_check = false;
|
|
583
706
|
}
|
|
584
707
|
}
|
|
585
708
|
}
|
|
586
709
|
|
|
587
|
-
// ===============================================================
|
|
588
|
-
// Hook #3, #4, #5: EVERYTHING - Complex behavioral patterns
|
|
589
|
-
// These hooks operate on the full event stream per user for
|
|
590
|
-
// fraud injection, low-balance churn, and budget discipline.
|
|
591
|
-
// ===============================================================
|
|
592
710
|
if (type === "everything") {
|
|
711
|
+
const datasetStart = dayjs.unix(meta.datasetStart);
|
|
593
712
|
const userEvents = record;
|
|
594
|
-
|
|
595
|
-
// Stamp superProps from profile for consistency
|
|
596
713
|
const profile = meta.profile;
|
|
714
|
+
|
|
597
715
|
userEvents.forEach(e => {
|
|
598
716
|
e.account_tier = profile.account_tier;
|
|
599
717
|
e.Platform = profile.Platform;
|
|
600
|
-
e.low_balance_churn = profile.low_balance_churn;
|
|
601
718
|
});
|
|
602
719
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
// card locked, dispute filed, and support contacted events.
|
|
610
|
-
// All injected events are tagged with fraud_sequence: true.
|
|
611
|
-
// -----------------------------------------------------------
|
|
612
|
-
if (chance.bool({ likelihood: 3 })) {
|
|
613
|
-
// Find the midpoint of the user's timeline
|
|
614
|
-
if (userEvents.length >= 2) {
|
|
615
|
-
const midIdx = Math.floor(userEvents.length / 2);
|
|
616
|
-
const midEvent = userEvents[midIdx];
|
|
617
|
-
const midTime = dayjs(midEvent.time);
|
|
618
|
-
const distinctId = midEvent.user_id;
|
|
619
|
-
|
|
620
|
-
// Inject 3-5 rapid high-value transactions
|
|
621
|
-
const burstCount = chance.integer({ min: 3, max: 5 });
|
|
622
|
-
const fraudEvents = [];
|
|
623
|
-
|
|
624
|
-
// Find template events for cloning
|
|
625
|
-
const txnTemplate = userEvents.find(e => e.event === "transaction completed");
|
|
626
|
-
const cardTemplate = userEvents.find(e => e.event === "card locked");
|
|
627
|
-
const disputeTemplate = userEvents.find(e => e.event === "dispute filed");
|
|
628
|
-
const supportTemplate = userEvents.find(e => e.event === "support contacted");
|
|
629
|
-
|
|
630
|
-
for (let i = 0; i < burstCount; i++) {
|
|
631
|
-
if (txnTemplate) {
|
|
632
|
-
fraudEvents.push({
|
|
633
|
-
...txnTemplate,
|
|
634
|
-
time: midTime.add(i * 10, "minutes").toISOString(),
|
|
635
|
-
user_id: distinctId,
|
|
636
|
-
transaction_type: "purchase",
|
|
637
|
-
amount: chance.integer({ min: 500, max: 3000 }),
|
|
638
|
-
merchant_category: chance.pickone(["online", "retail"]),
|
|
639
|
-
payment_method: "credit",
|
|
640
|
-
fraud_sequence: true,
|
|
641
|
-
});
|
|
642
|
-
}
|
|
720
|
+
// HOOK 1B: PERSONAL VS BUSINESS — business segment txns 4x larger
|
|
721
|
+
// (per Report 2 in JSDoc: business ~ $200, personal ~ $50).
|
|
722
|
+
if (profile.account_segment === "business") {
|
|
723
|
+
userEvents.forEach(e => {
|
|
724
|
+
if (e.event === "transaction completed" && typeof e.amount === "number") {
|
|
725
|
+
e.amount = Math.floor(e.amount * 4);
|
|
643
726
|
}
|
|
727
|
+
});
|
|
728
|
+
}
|
|
644
729
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
730
|
+
// HOOK 2: PAYDAY PATTERNS — 1st & 15th: direct_deposit amount 3x.
|
|
731
|
+
// Days 1-3 and 15-17: 60% of transfers get amount 2x. No flag.
|
|
732
|
+
for (const e of userEvents) {
|
|
733
|
+
const dayOfMonth = new Date(e.time).getUTCDate();
|
|
734
|
+
if (e.event === "transaction completed" && e.transaction_type === "direct_deposit") {
|
|
735
|
+
if (dayOfMonth === 1 || dayOfMonth === 15) {
|
|
736
|
+
e.amount = Math.floor((e.amount || 50) * 3);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (e.event === "transfer sent") {
|
|
740
|
+
const isPaydayWindow = (dayOfMonth >= 1 && dayOfMonth <= 3) || (dayOfMonth >= 15 && dayOfMonth <= 17);
|
|
741
|
+
if (isPaydayWindow && chance.bool({ likelihood: 60 })) {
|
|
742
|
+
e.amount = Math.floor((e.amount || 200) * 2.0);
|
|
654
743
|
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
655
746
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
reason: "unauthorized",
|
|
664
|
-
fraud_sequence: true,
|
|
665
|
-
});
|
|
747
|
+
// HOOK 8: MONTH-END ANXIETY — days >= 28: app_session duration
|
|
748
|
+
// 1.4x; balance_checked account_balance 0.7x. Mutates raw props.
|
|
749
|
+
for (const e of userEvents) {
|
|
750
|
+
const dayOfMonth = new Date(e.time).getUTCDate();
|
|
751
|
+
if (dayOfMonth >= 28) {
|
|
752
|
+
if (e.event === "app session") {
|
|
753
|
+
e.session_duration_sec = Math.floor((e.session_duration_sec || 60) * 1.4);
|
|
666
754
|
}
|
|
755
|
+
if (e.event === "balance checked") {
|
|
756
|
+
e.account_balance = Math.floor((e.account_balance || 2500) * 0.7);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
667
760
|
|
|
668
|
-
|
|
669
|
-
|
|
761
|
+
// HOOK 7: PREMIUM TIER VALUE — Premium 3x reward value + 2x
|
|
762
|
+
// investment-sell amount; Plus 1.5x reward value. Reads tier
|
|
763
|
+
// from profile. No flag.
|
|
764
|
+
const tier = profile.account_tier;
|
|
765
|
+
userEvents.forEach(e => {
|
|
766
|
+
if (e.event === "reward redeemed") {
|
|
767
|
+
if (tier === "premium") e.value = Math.floor((e.value || 10) * 3);
|
|
768
|
+
else if (tier === "plus") e.value = Math.floor((e.value || 10) * 1.5);
|
|
769
|
+
}
|
|
770
|
+
if (e.event === "investment made" && e.action === "sell" && tier === "premium") {
|
|
771
|
+
e.amount = Math.floor((e.amount || 250) * 2);
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// HOOK 3: FRAUD DETECTION — 3% of users get fraud burst
|
|
776
|
+
// (3-5 rapid high-value transactions + card locked + dispute +
|
|
777
|
+
// support contacted) at timeline midpoint. No flag — discover
|
|
778
|
+
// via cohort builder on users with card-locked + dispute-filed.
|
|
779
|
+
if (chance.bool({ likelihood: 15 }) && userEvents.length >= 2) {
|
|
780
|
+
const midIdx = Math.floor(userEvents.length / 2);
|
|
781
|
+
const midEvent = userEvents[midIdx];
|
|
782
|
+
const midTime = dayjs(midEvent.time);
|
|
783
|
+
const distinctId = midEvent.user_id;
|
|
784
|
+
const burstCount = chance.integer({ min: 3, max: 5 });
|
|
785
|
+
const fraudEvents = [];
|
|
786
|
+
const txnTemplate = userEvents.find(e => e.event === "transaction completed");
|
|
787
|
+
const cardTemplate = userEvents.find(e => e.event === "card locked");
|
|
788
|
+
const disputeTemplate = userEvents.find(e => e.event === "dispute filed");
|
|
789
|
+
const supportTemplate = userEvents.find(e => e.event === "support contacted");
|
|
790
|
+
|
|
791
|
+
for (let i = 0; i < burstCount; i++) {
|
|
792
|
+
if (txnTemplate) {
|
|
670
793
|
fraudEvents.push({
|
|
671
|
-
...
|
|
672
|
-
time: midTime.add(
|
|
794
|
+
...txnTemplate,
|
|
795
|
+
time: midTime.add(i * 10, "minutes").toISOString(),
|
|
673
796
|
user_id: distinctId,
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
797
|
+
transaction_type: "purchase",
|
|
798
|
+
amount: chance.integer({ min: 500, max: 3000 }),
|
|
799
|
+
merchant_category: chance.pickone(["online", "retail"]),
|
|
800
|
+
payment_method: "credit",
|
|
678
801
|
});
|
|
679
802
|
}
|
|
680
|
-
|
|
681
|
-
// Splice all fraud events into the user's timeline
|
|
682
|
-
userEvents.splice(midIdx + 1, 0, ...fraudEvents);
|
|
683
803
|
}
|
|
804
|
+
if (cardTemplate) fraudEvents.push({
|
|
805
|
+
...cardTemplate,
|
|
806
|
+
time: midTime.add(burstCount * 10 + 5, "minutes").toISOString(),
|
|
807
|
+
user_id: distinctId,
|
|
808
|
+
reason: "suspicious_activity",
|
|
809
|
+
});
|
|
810
|
+
if (disputeTemplate) fraudEvents.push({
|
|
811
|
+
...disputeTemplate,
|
|
812
|
+
time: midTime.add(burstCount * 10 + 30, "minutes").toISOString(),
|
|
813
|
+
user_id: distinctId,
|
|
814
|
+
dispute_amount: chance.integer({ min: 500, max: 3000 }),
|
|
815
|
+
reason: "unauthorized",
|
|
816
|
+
});
|
|
817
|
+
if (supportTemplate) fraudEvents.push({
|
|
818
|
+
...supportTemplate,
|
|
819
|
+
time: midTime.add(burstCount * 10 + 45, "minutes").toISOString(),
|
|
820
|
+
user_id: distinctId,
|
|
821
|
+
channel: "phone",
|
|
822
|
+
issue_type: "card",
|
|
823
|
+
resolved: true,
|
|
824
|
+
});
|
|
825
|
+
userEvents.splice(midIdx + 1, 0, ...fraudEvents);
|
|
684
826
|
}
|
|
685
827
|
|
|
686
|
-
//
|
|
687
|
-
//
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
// -----------------------------------------------------------
|
|
692
|
-
let lowBalanceChecks = 0;
|
|
693
|
-
userEvents.forEach((event) => {
|
|
694
|
-
if (event.event === "balance checked" && (event.account_balance || 0) < 15000) {
|
|
695
|
-
lowBalanceChecks++;
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
|
|
828
|
+
// HOOK 4: LOW BALANCE CHURN — users with 3+ balance checks
|
|
829
|
+
// under $15K lose 50% of post-day-30 events. No flag.
|
|
830
|
+
const lowBalanceChecks = userEvents.filter(e =>
|
|
831
|
+
e.event === "balance checked" && (e.account_balance || 0) < 15000
|
|
832
|
+
).length;
|
|
699
833
|
if (lowBalanceChecks >= 3) {
|
|
700
|
-
const day30 =
|
|
834
|
+
const day30 = datasetStart.add(30, "days");
|
|
701
835
|
for (let i = userEvents.length - 1; i >= 0; i--) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
if (chance.bool({ likelihood: 50 })) {
|
|
705
|
-
userEvents.splice(i, 1);
|
|
706
|
-
} else {
|
|
707
|
-
evt.low_balance_churn = true;
|
|
708
|
-
}
|
|
836
|
+
if (dayjs(userEvents[i].time).isAfter(day30) && chance.bool({ likelihood: 50 })) {
|
|
837
|
+
userEvents.splice(i, 1);
|
|
709
838
|
}
|
|
710
839
|
}
|
|
711
840
|
}
|
|
712
841
|
|
|
713
|
-
//
|
|
714
|
-
//
|
|
715
|
-
//
|
|
716
|
-
|
|
717
|
-
// spliced into their timeline. Tagged budget_discipline: true.
|
|
718
|
-
// -----------------------------------------------------------
|
|
719
|
-
let hasBudget = false;
|
|
720
|
-
userEvents.forEach((event) => {
|
|
721
|
-
if (event.event === "budget created") {
|
|
722
|
-
hasBudget = true;
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
|
|
842
|
+
// HOOK 5: BUDGET DISCIPLINE — users with any budget-created event
|
|
843
|
+
// get savings 2x, investment amounts 1.5x, and extra cloned
|
|
844
|
+
// savings-goal events. No flag.
|
|
845
|
+
const hasBudget = userEvents.some(e => e.event === "budget created");
|
|
726
846
|
if (hasBudget) {
|
|
727
847
|
userEvents.forEach((event, idx) => {
|
|
728
848
|
const eventTime = dayjs(event.time);
|
|
729
|
-
|
|
730
|
-
// Double savings contributions
|
|
731
849
|
if (event.event === "savings goal set") {
|
|
732
850
|
event.monthly_contribution = Math.floor((event.monthly_contribution || 200) * 2);
|
|
733
|
-
event.budget_discipline = true;
|
|
734
851
|
}
|
|
735
|
-
|
|
736
|
-
// 1.5x investment amounts
|
|
737
852
|
if (event.event === "investment made") {
|
|
738
853
|
event.amount = Math.floor((event.amount || 250) * 1.5);
|
|
739
|
-
event.budget_discipline = true;
|
|
740
854
|
}
|
|
741
|
-
|
|
742
|
-
// Splice extra savings goal events (budget-conscious users set more goals)
|
|
743
855
|
if (event.event === "budget created" && chance.bool({ likelihood: 50 })) {
|
|
744
856
|
const savingsTemplate = userEvents.find(e => e.event === "savings goal set");
|
|
745
857
|
if (savingsTemplate) {
|
|
746
|
-
|
|
858
|
+
userEvents.splice(idx + 1, 0, {
|
|
747
859
|
...savingsTemplate,
|
|
748
860
|
time: eventTime.add(chance.integer({ min: 1, max: 7 }), "days").toISOString(),
|
|
749
861
|
user_id: event.user_id,
|
|
750
862
|
goal_type: chance.pickone(["emergency", "vacation", "car", "home"]),
|
|
751
863
|
target_amount: chance.integer({ min: 1000, max: 20000 }),
|
|
752
864
|
monthly_contribution: chance.integer({ min: 100, max: 800 }),
|
|
753
|
-
|
|
754
|
-
};
|
|
755
|
-
userEvents.splice(idx + 1, 0, extraGoal);
|
|
865
|
+
});
|
|
756
866
|
}
|
|
757
867
|
}
|
|
758
868
|
});
|
|
759
869
|
}
|
|
870
|
+
|
|
871
|
+
// HOOK 10: TRANSACTION-COUNT MAGIC NUMBER (no flags)
|
|
872
|
+
// Sweet 6-10 transactions/user → +40% on investment_made amount
|
|
873
|
+
// (engaged transactor compounds wealth). Over 11+ → drop 20% of
|
|
874
|
+
// premium-upgraded events (already engaged; less upgrade pressure).
|
|
875
|
+
const txnCount = userEvents.filter(e => e.event === "transaction completed").length;
|
|
876
|
+
if (txnCount >= 6 && txnCount <= 10) {
|
|
877
|
+
userEvents.forEach(e => {
|
|
878
|
+
if (e.event === "investment made" && typeof e.amount === "number") {
|
|
879
|
+
e.amount = Math.round(e.amount * 1.4);
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
} else if (txnCount >= 11) {
|
|
883
|
+
userEvents.forEach(e => {
|
|
884
|
+
if (e.event === "premium upgraded" && typeof e.monthly_fee === "number") {
|
|
885
|
+
e.monthly_fee = Math.round(e.monthly_fee * 0.7 * 100) / 100;
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
}
|
|
760
889
|
}
|
|
761
890
|
|
|
762
891
|
return record;
|