make-mp-data 2.1.4 → 2.1.5

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.
@@ -31,7 +31,7 @@ const config = {
31
31
  region: "US",
32
32
  hasAnonIds: false, //if true, anonymousIds are created for each user
33
33
  hasSessionIds: false, //if true, hasSessionIds are created for each user
34
- hasAdSpend: false,
34
+ hasAdSpend: true,
35
35
  hasLocation: true,
36
36
  hasAndroidDevices: false,
37
37
  hasIOSDevices: false,
@@ -18,26 +18,35 @@ import * as u from "../utils/utils.js";
18
18
  export async function makeAdSpend(context, day, campaigns = null) {
19
19
  // Update operation counter
20
20
  context.incrementOperations();
21
-
21
+
22
22
  // Use campaigns from context if not provided
23
23
  const campaignConfigs = campaigns || context.campaigns;
24
-
24
+
25
25
  if (!campaignConfigs || campaignConfigs.length === 0) {
26
26
  return [];
27
27
  }
28
-
28
+
29
29
  const chance = u.getChance();
30
30
  const adSpendEvents = [];
31
-
31
+
32
+ // Determine if we should apply time shift
33
+ // Only shift if the date is in the historical "fixed" range (before 2025)
34
+ const dayTimestamp = dayjs(day).unix();
35
+ const CUTOFF_DATE = dayjs('2025-01-01').unix(); // Dates before 2025 are considered "fixed" range
36
+ const shouldShift = dayTimestamp < CUTOFF_DATE;
37
+
38
+ // Get time shift from context, but only use it if we should shift
39
+ const timeShiftSeconds = shouldShift ? (context.TIME_SHIFT_SECONDS || 0) : 0;
40
+
32
41
  for (const network of campaignConfigs) {
33
42
  const networkCampaigns = network.utm_campaign;
34
-
43
+
35
44
  for (const campaign of networkCampaigns) {
36
45
  // Skip organic campaigns
37
46
  if (campaign === "$organic") continue;
38
47
 
39
- // Generate realistic ad spend metrics
40
- const adSpendEvent = createAdSpendEvent(network, campaign, day, chance);
48
+ // Generate realistic ad spend metrics with conditional time shift
49
+ const adSpendEvent = createAdSpendEvent(network, campaign, day, chance, timeShiftSeconds);
41
50
  adSpendEvents.push(adSpendEvent);
42
51
  }
43
52
  }
@@ -51,9 +60,15 @@ export async function makeAdSpend(context, day, campaigns = null) {
51
60
  * @param {string} campaign - Campaign name
52
61
  * @param {string} day - ISO date string
53
62
  * @param {Object} chance - Chance.js instance
63
+ * @param {number} timeShiftSeconds - Time shift in seconds to apply to timestamps (default: 0)
54
64
  * @returns {Object} Ad spend event object
55
65
  */
56
- function createAdSpendEvent(network, campaign, day, chance) {
66
+ function createAdSpendEvent(network, campaign, day, chance, timeShiftSeconds = 0) {
67
+ // Apply time shift to the day timestamp
68
+ const dayTimestamp = dayjs(day).unix();
69
+ const shiftedTimestamp = dayTimestamp + timeShiftSeconds;
70
+ const shiftedDay = dayjs.unix(shiftedTimestamp).toISOString();
71
+
57
72
  // Generate realistic cost
58
73
  const cost = chance.floating({ min: 10, max: 250, fixed: 2 });
59
74
 
@@ -77,7 +92,7 @@ function createAdSpendEvent(network, campaign, day, chance) {
77
92
 
78
93
  return {
79
94
  event: "$ad_spend",
80
- time: day,
95
+ time: shiftedDay, // Use shifted timestamp
81
96
  // source: 'dm4',
82
97
  utm_campaign: campaign,
83
98
  campaign_id: id,
@@ -92,7 +107,7 @@ function createAdSpendEvent(network, campaign, day, chance) {
92
107
  views,
93
108
  impressions,
94
109
  cost,
95
- date: dayjs(day).format("YYYY-MM-DD"),
110
+ date: dayjs.unix(shiftedTimestamp).format("YYYY-MM-DD"), // Also use shifted timestamp for date
96
111
  };
97
112
  }
98
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "make-mp-data",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "builds all mixpanel primitives for a given project",
5
5
  "type": "module",
6
6
  "main": "index.js",