diff --git a/integration/youtube.php b/integration/youtube.php index 7f34d836..fae2afb2 100644 --- a/integration/youtube.php +++ b/integration/youtube.php @@ -25,9 +25,9 @@ function gtm4wp_youtube( $return, $url, $data ) { if ( false !== strpos( $return, 'youtube.com' ) ) { return str_replace( 'feature=oembed', 'feature=oembed&enablejsapi=1&origin=' . $site_url_parts['scheme'] . '://' . $site_url_parts['host'], $return ); - } else { - return $return; - } + } + + return $return; } add_filter( 'oembed_result', 'gtm4wp_youtube', 10, 3 ); diff --git a/public/frontend.php b/public/frontend.php index 58abbeda..5940f3f1 100755 --- a/public/frontend.php +++ b/public/frontend.php @@ -48,10 +48,10 @@ * * @since 1.2 */ +$GLOBALS['gtm4wp_datalayer_name'] = $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_DATALAYER_NAME ]; + if ( empty( $GLOBALS['gtm4wp_options'] ) || ( '' === $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_DATALAYER_NAME ] ) ) { $GLOBALS['gtm4wp_datalayer_name'] = 'dataLayer'; -} else { - $GLOBALS['gtm4wp_datalayer_name'] = $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_DATALAYER_NAME ]; } /** @@ -175,10 +175,10 @@ function gtm4wp_add_basic_datalayer_data( $data_layer ) { } if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_LOGGEDIN ] ) { + $data_layer['visitorLoginState'] = 'logged-out'; + if ( is_user_logged_in() ) { $data_layer['visitorLoginState'] = 'logged-in'; - } else { - $data_layer['visitorLoginState'] = 'logged-out'; } } @@ -393,10 +393,10 @@ function gtm4wp_add_basic_datalayer_data( $data_layer ) { $data_layer['siteSearchFrom'] = ''; if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { $referer_url_parts = explode( '?', esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) ); + $data_layer['siteSearchFrom'] = $referer_url_parts[0]; + if ( count( $referer_url_parts ) > 1 ) { $data_layer['siteSearchFrom'] = $referer_url_parts[0] . '?' . rawurlencode( $referer_url_parts[1] ); - } else { - $data_layer['siteSearchFrom'] = $referer_url_parts[0]; } } $data_layer['siteSearchResults'] = $wp_query->post_count; @@ -526,7 +526,8 @@ function( $class ) { if ( '' !== $client_ip ) { if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) { $weatherdata = get_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ) ); - + $data_layer['weatherDataStatus'] = 'No weather data in cache (' . esc_attr( $client_ip ) . ')'; + if ( false !== $weatherdata ) { $data_layer['weatherCategory'] = $weatherdata->weather[0]->main; $data_layer['weatherDescription'] = $weatherdata->weather[0]->description; @@ -536,8 +537,6 @@ function( $class ) { $data_layer['weatherWindDeg'] = ( isset( $weatherdata->wind->deg ) ? $weatherdata->wind->deg : '' ); $data_layer['weatherFullWeatherData'] = $weatherdata; $data_layer['weatherDataStatus'] = 'Read from cache'; - } else { - $data_layer['weatherDataStatus'] = 'No weather data in cache (' . esc_attr( $client_ip ) . ')'; } }