BSF_UTM_Analytics::get_utm_ready_link( string $link, string $product, mixed $utm_args = array() )
This function will add utm_args to pro link or purchase link added utm_source by default additional utm_args such as utm_medium etc can be provided to generate location specific links
Description
Parameters
- $link
-
(string) (Required) Ideally this should be product site link where utm_params can be tracked.
- $product
-
(string) (Required) Product slug whose utm_link need to be created.
- $utm_args
-
(mixed) (Optional) additional args to be passed ex: [ 'utm_medium' => 'dashboard'].
Default value: array()
Return
(string)
Source
File: inc/lib/bsf-analytics/modules/utm-analytics.php
public static function get_utm_ready_link( $link, $product, $utm_args = [] ) { if ( false === wp_http_validate_url( $link ) ) { error_log( 'Invalid url passed to get_utm_ready_link function' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- adding logs in case of failure will help in debugging. return $link; } if ( empty( $product ) || ! is_string( $product ) || ! self::is_valid_bsf_product_slug( $product ) ) { error_log( sprintf( 'Invalid product slug provided "%1$s", does not match bsf_product_slugs', $product ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- adding logs in case of failure will help in debugging. return $link; } $bsf_product_referers = get_option( BSF_UTM_ANALYTICS_REFERER, [] ); if ( ! is_array( $bsf_product_referers ) || empty( $bsf_product_referers[ $product ] ) ) { return $link; } if ( ! self::is_valid_bsf_product_slug( $bsf_product_referers[ $product ] ) ) { return $link; } if ( ! is_array( $utm_args ) ) { $utm_args = []; } $utm_args['utm_source'] = $bsf_product_referers[ $product ]; $link = add_query_arg( $utm_args, $link ); return $link; }
Expand full source code Collapse full source code View on Trac
Changelog
Version | Description |
---|---|
1.1.10 | Introduced. |