Created
April 27, 2021 01:11
-
-
Save chavesm/8b86c58e66b3d1ca21bc3b4fd6412bd6 to your computer and use it in GitHub Desktop.
Send user agent as a custom dimension via MonsterInsights action hook
This file contains 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 // Remove this line when adding to child functions.php | |
/** | |
* This example sets custom dimension #14 to be the HTTP | |
* user agent. | |
* | |
* This is compatible with MonsterInsights gtag code. This filter supercedes | |
* the monsterinsights_frontend_tracking_options_analytics_before_pageview | |
* filter. | |
* | |
* Change the number 14 to your custom dimension index number in GA. | |
*/ | |
add_filter( | |
monsterinsights_frontend_tracking_options_persistent_gtag_before_pageview, | |
function( $options ) { | |
$options[ 'dimension14'] = $_SERVER['HTTP_USER_AGENT']; | |
return $options; | |
}, | |
20 // priority | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GA doc for creating a custom dimension in a UA property: https://support.google.com/analytics/answer/2709829