2022-06-16 14:01:47 +02:00
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
|
2019-11-15 23:26:29 +01:00
|
|
|
/**
|
2022-06-16 14:01:47 +02:00
|
|
|
* Jetpack_Google_Analytics_Options provides a single interface to module options
|
|
|
|
|
*
|
|
|
|
|
* @author allendav
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
|
|
|
|
|
/**
|
2022-06-16 14:01:47 +02:00
|
|
|
* Bail if accessed directly
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Jetpack_Google_Analytics_Utils main class.
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
class Jetpack_Google_Analytics_Utils {
|
|
|
|
|
/**
|
|
|
|
|
* Gets product categories or varation attributes as a formatted concatenated string
|
2022-06-16 14:01:47 +02:00
|
|
|
*
|
|
|
|
|
* @param WC_Product $product Product to get categories/variations for.
|
2019-11-15 23:26:29 +01:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function get_product_categories_concatenated( $product ) {
|
|
|
|
|
if ( ! class_exists( 'WooCommerce' ) ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! $product ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : '';
|
|
|
|
|
if ( is_array( $variation_data ) && ! empty( $variation_data ) ) {
|
|
|
|
|
$line = wc_get_formatted_variation( $variation_data, true );
|
|
|
|
|
} else {
|
2022-06-16 14:01:47 +02:00
|
|
|
$out = array();
|
2019-11-15 23:26:29 +01:00
|
|
|
$categories = get_the_terms( $product->get_id(), 'product_cat' );
|
|
|
|
|
if ( $categories ) {
|
|
|
|
|
foreach ( $categories as $category ) {
|
|
|
|
|
$out[] = $category->name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-26 10:24:36 +02:00
|
|
|
$line = implode( '/', $out );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
return $line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets a product's SKU with fallback to just ID. IDs are prepended with a hash symbol.
|
2022-06-16 14:01:47 +02:00
|
|
|
*
|
|
|
|
|
* @param WC_Product $product Product to get SKU/ID for.
|
2019-11-15 23:26:29 +01:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public static function get_product_sku_or_id( $product ) {
|
|
|
|
|
if ( ! class_exists( 'WooCommerce' ) ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ! $product ) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $product->get_sku() ? $product->get_sku() : '#' . $product->get_id();
|
|
|
|
|
}
|
2022-12-15 17:41:53 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if filter is set and dnt is enabled.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function is_dnt_enabled() {
|
|
|
|
|
/**
|
|
|
|
|
* Filter the option which decides honor DNT or not.
|
|
|
|
|
*
|
|
|
|
|
* @module google-analytics
|
|
|
|
|
* @since 11.3
|
|
|
|
|
*
|
|
|
|
|
* @param bool $honor_dnt Honors DNT for clients who don't want to be tracked. Set to true to enable.
|
|
|
|
|
*/
|
|
|
|
|
if ( false === apply_filters( 'jetpack_honor_dnt_header_for_wga', Jetpack_Google_Analytics_Options::honor_dnt_is_enabled() ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( $_SERVER as $name => $value ) {
|
|
|
|
|
if ( 'http_dnt' === strtolower( $name ) && 1 === (int) $value ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-06-16 14:01:47 +02:00
|
|
|
}
|