Created
December 15, 2021 20:33
-
-
Save dpaternina9/1dd61f5f7f85dd48fd849b3768b80d2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'ampforwp_google_analytics_fields', 'monsterinsights_ampforwp_analytics_dimensions_fix', 11 ); | |
function monsterinsights_ampforwp_analytics_dimensions_fix( $ga_fields ) { | |
$options = new MonsterInsights_Frontend_Custom_Dimensions(); | |
$options = $options->output_custom_dimensions( array () ); | |
$ua = monsterinsights_get_ua_to_output( array( 'amp' => true ) ); | |
if ( empty( $ua ) ) { | |
return $ga_fields; | |
} | |
$dimensions_data = []; | |
if ( ! empty( $options ) && is_array( $options ) ) { | |
foreach ( $options as $optionname => $optionvalue ) { | |
if ( monsterinsights_string_starts_with( $optionname, 'dimension' ) ) { | |
$num = str_replace( 'dimension', '', $optionname ); | |
$dimensionname = str_replace( 'dimension', 'cd', $optionname ); | |
$optionvalue = str_replace("'set', 'dimension" . absint( $num ) . "', '", '', $optionvalue ); | |
$optionvalue = rtrim( $optionvalue,"'" ); | |
$dimensions_data[$dimensionname] = $optionvalue; | |
} | |
} | |
} | |
$ga_fields['extraUrlParams'] = $dimensions_data; | |
return $ga_fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment