Skip to content

Commit 6a7a34f

Browse files
committed
Add support for campaign order attribution data.
1 parent 4a9a6c1 commit 6a7a34f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

includes/Generator/OrderAttribution.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public static function add_order_attribution_meta( $order, $assoc_args = array()
5858
'_wc_order_attribution_utm_source' => self::get_source( $source_type ),
5959
'_wc_order_attribution_referrer' => self::get_referrer( $source_type ),
6060
'_wc_order_attribution_source_type' => $source_type,
61+
'_wc_order_attribution_utm_campaign' => self::get_random_utm_campaign(),
62+
'_wc_order_attribution_utm_term' => self::get_random_utm_term(),
6163
);
6264
}
6365

@@ -321,4 +323,48 @@ public static function get_random_session_start_time( $order ) {
321323
return $order_created_date->format( 'Y-m-d H:i:s' );
322324
}
323325

326+
/**
327+
* Get a random UTM campaign name.
328+
*
329+
* @return string The UTM campaign name.
330+
*/
331+
public static function get_random_utm_campaign() {
332+
$campaigns = array(
333+
'summer_sale_2024',
334+
'black_friday_2024',
335+
'new_product_launch',
336+
'holiday_special',
337+
'spring_collection',
338+
'flash_sale',
339+
'membership_promo',
340+
'newsletter_special',
341+
'social_campaign',
342+
'influencer_collab',
343+
);
344+
345+
return $campaigns[ array_rand( $campaigns ) ];
346+
}
347+
348+
/**
349+
* Get a random UTM term (usually for paid search keywords).
350+
*
351+
* @return string The UTM term.
352+
*/
353+
public static function get_random_utm_term() {
354+
$terms = array(
355+
'buy_online',
356+
'best_deals',
357+
'discount_code',
358+
'free_shipping',
359+
'premium_products',
360+
'sale_items',
361+
'new_arrival',
362+
'trending_products',
363+
'limited_offer',
364+
'', // Sometimes term might be empty
365+
);
366+
367+
return $terms[ array_rand( $terms ) ];
368+
}
369+
324370
}

0 commit comments

Comments
 (0)