Merge pull request #32115 from mcliwanow/add/12397-tracking-params-wccom-from-subscriptions

Subscriptions - add tracking params to WCCOM URLs
This commit is contained in:
Vedanshu Jain 2022-05-05 14:31:50 +05:30 committed by GitHub
commit 79c953c2f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 8 deletions

View File

@ -223,7 +223,10 @@ class WC_Helper {
$action['message'] .= ' ' . __( 'To enable this update you need to <strong>purchase</strong> a new subscription.', 'woocommerce' );
$action['button_label'] = __( 'Purchase', 'woocommerce' );
$action['button_url'] = $subscription['product_url'];
$action['button_url'] = self::add_utm_params_to_url_for_subscription_link(
$subscription['product_url'],
'purchase'
);
$subscription['actions'][] = $action;
} elseif ( $subscription['expired'] && ! empty( $subscription['master_user_email'] ) ) {
@ -238,7 +241,10 @@ class WC_Helper {
$action = array(
'message' => sprintf( __( 'This subscription has expired. Please <strong>renew</strong> to receive updates and support.', 'woocommerce' ) ),
'button_label' => __( 'Renew', 'woocommerce' ),
'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/',
'button_url' => self::add_utm_params_to_url_for_subscription_link(
'https://woocommerce.com/my-account/my-subscriptions/',
'renew'
),
'status' => 'expired',
'icon' => 'dashicons-info',
);
@ -250,7 +256,10 @@ class WC_Helper {
$action = array(
'message' => __( 'Subscription is <strong>expiring</strong> soon.', 'woocommerce' ),
'button_label' => __( 'Enable auto-renew', 'woocommerce' ),
'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/',
'button_url' => self::add_utm_params_to_url_for_subscription_link(
'https://woocommerce.com/my-account/my-subscriptions/',
'auto-renew'
),
'status' => 'expired',
'icon' => 'dashicons-info',
);
@ -261,7 +270,10 @@ class WC_Helper {
$action = array(
'message' => sprintf( __( 'This subscription is expiring soon. Please <strong>renew</strong> to continue receiving updates and support.', 'woocommerce' ) ),
'button_label' => __( 'Renew', 'woocommerce' ),
'button_url' => 'https://woocommerce.com/my-account/my-subscriptions/',
'button_url' => self::add_utm_params_to_url_for_subscription_link(
'https://woocommerce.com/my-account/my-subscriptions/',
'renew'
),
'status' => 'expired',
'icon' => 'dashicons-info',
);
@ -309,7 +321,10 @@ class WC_Helper {
/* translators: %s: version number */
'message' => sprintf( __( 'Version %s is <strong>available</strong>. To enable this update you need to <strong>purchase</strong> a new subscription.', 'woocommerce' ), esc_html( $updates[ $data['_product_id'] ]['version'] ) ),
'button_label' => __( 'Purchase', 'woocommerce' ),
'button_url' => $data['_product_url'],
'button_url' => self::add_utm_params_to_url_for_subscription_link(
$data['_product_url'],
'purchase'
),
'status' => 'expired',
'icon' => 'dashicons-info',
);
@ -320,7 +335,10 @@ class WC_Helper {
/* translators: 1: subscriptions docs 2: subscriptions docs */
'message' => sprintf( __( 'To receive updates and support for this extension, you need to <strong>purchase</strong> a new subscription or consolidate your extensions to one connected account by <strong><a href="%1$s" title="Sharing Docs">sharing</a> or <a href="%2$s" title="Transferring Docs">transferring</a></strong> this extension to this connected account.', 'woocommerce' ), 'https://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-10', 'https://docs.woocommerce.com/document/managing-woocommerce-com-subscriptions/#section-5' ),
'button_label' => __( 'Purchase', 'woocommerce' ),
'button_url' => $data['_product_url'],
'button_url' => self::add_utm_params_to_url_for_subscription_link(
$data['_product_url'],
'purchase'
),
'status' => 'expired',
'icon' => 'dashicons-info',
);
@ -350,6 +368,28 @@ class WC_Helper {
return;
}
/**
* Add tracking parameters to buttons (Renew, Purchase, etc.) on subscriptions page
*
* @param string $url URL to product page or to https://woocommerce.com/my-account/my-subscriptions/
* @param string $utm_content value of utm_content query parameter used for tracking
*
* @return string URL including utm parameters for tracking
*/
public static function add_utm_params_to_url_for_subscription_link( $url, $utm_content ) {
$utm_params = 'utm_source=subscriptionsscreen&' .
'utm_medium=product&' .
'utm_campaign=wcaddons&' .
'utm_content=' . $utm_content;
// there are already some URL parameters
if ( strpos( $url, '?' ) ) {
return $url . '&' . $utm_params;
}
return $url . '?' . $utm_params;
}
/**
* Get available subscriptions filters.
*

View File

@ -75,7 +75,7 @@
<tr class="wp-list-table__row is-ext-header">
<td class="wp-list-table__ext-details">
<div class="wp-list-table__ext-title">
<a href="<?php echo esc_url( $subscription['product_url'] ); ?>" target="_blank">
<a href="<?php echo esc_url( WC_Helper::add_utm_params_to_url_for_subscription_link( $subscription['product_url'], 'product-name' ) ); ?>" target="_blank">
<?php echo esc_html( $subscription['product_name'] ); ?>
</a>
</div>
@ -206,7 +206,9 @@
<tr class="wp-list-table__row is-ext-header">
<td class="wp-list-table__ext-details color-bar autorenews">
<div class="wp-list-table__ext-title">
<a href="<?php echo esc_url( $data['_product_url'] ); ?>" target="_blank"><?php echo esc_html( $data['Name'] ); ?></a>
<a href="<?php echo esc_url( WC_Helper::add_utm_params_to_url_for_subscription_link( $data['_product_url'], 'product-name' ) ); ?>" target="_blank">
<?php echo esc_html( $data['Name'] ); ?>
</a>
</div>
<div class="wp-list-table__ext-description">
</div>