Skip to content

Instantly share code, notes, and snippets.

@remcotolsma remcotolsma/gist:6103897
Last active Jul 19, 2018

Embed
What would you like to do?
Analytics tracking code per language (WPML)
<?php
/**
* Google Analytics tracking code per language (WPML)
*
* @param array $options
* @see http://plugins.trac.wordpress.org/browser/google-analytics-for-wordpress/tags/4.3.3/frontend/class-frontend.php#L12
*/
function prefix_ga_init( $options ) {
global $yoast_ga;
if ( isset( $yoast_ga ) && defined( 'ICL_LANGUAGE_CODE' ) ) {
switch ( ICL_LANGUAGE_CODE ) {
case 'be':
$yoast_ga->options['uastring'] = 'UA-0000000-1';
break;
case 'de':
$yoast_ga->options['uastring'] = 'UA-0000000-2';
break;
case 'en':
$yoast_ga->options['uastring'] = 'UA-0000000-3';
break;
}
}
}
add_action( 'init', 'prefix_ga_init' );
@jonathan-soifer

This comment has been minimized.

Copy link

jonathan-soifer commented Mar 24, 2015

Hi,

This should be added to functions.php in a Wordpress Child Theme, right?

@bluantinoo

This comment has been minimized.

Copy link

bluantinoo commented Apr 21, 2016

I can't get it working with latest version of plugin (now called "monsterinsight").
$yoast_ga is NULL

@michelkusters

This comment has been minimized.

Copy link

michelkusters commented Oct 17, 2016

Following

@chriscct7

This comment has been minimized.

Copy link

chriscct7 commented Nov 2, 2016

I was pointed here by a user who came to our support. I'm the lead developer of what's now called MonsterInsights. Note, this type of on the fly altering of the global $yoast_ga option (which itself is deprecated and is getting ready to be removed from MonsterInsights), isn't supported, and it won't work in most cases as MonsterInsights pulls the UAC directly from the database, not the global.

After we get MonsterInsights 6.0 out later this month, one of the many addons we're going to be rolling out is one for WPML compatibility. If you're interested in getting updates on it's progress, I would suggest emailing us using the contact form on the MonsterInsights website so we can get you on a mailing list for that to notify you when it's ready.

@972creative

This comment has been minimized.

Copy link

972creative commented Jul 19, 2018

@chriscct7 - Can you give some more insights on how MonsterInsights 6.0+ works with WPML? I wasn't able to find any clear documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.