Skip to content

Commit

Permalink
Merge pull request #335 from hans2103/patch-3
Browse files Browse the repository at this point in the history
Update frontend.php
  • Loading branch information
duracelltomi authored Mar 18, 2024
2 parents 5081325 + eaf9010 commit 309de01
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions public/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}

/**
Expand Down Expand Up @@ -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';
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 ) . ')';
}
}

Expand Down

0 comments on commit 309de01

Please sign in to comment.