filter_universal();
$this->google_analytics();
}
function filter_universal() {
$aiosp_ga_use_universal_analytics = $this->aiosp_ga_use_universal_analytics;
$this->aiosp_ga_use_universal_analytics = apply_filters( 'aiosp_universal_analytics', $aiosp_ga_use_universal_analytics );
}
function google_analytics() {
global $aioseop_options;
$analytics = '';
if ( ! empty( $aioseop_options['aiosp_ga_advanced_options'] ) && ! empty( $aioseop_options['aiosp_ga_exclude_users'] ) && is_user_logged_in() ) {
global $current_user;
if ( empty( $current_user ) ) {
wp_get_current_user();
}
if ( ! empty( $current_user ) ) {
$intersect = array_intersect( $aioseop_options['aiosp_ga_exclude_users'], $current_user->roles );
if ( ! empty( $intersect ) ) {
return;
}
}
}
if ( ! empty( $aioseop_options['aiosp_google_analytics_id'] ) ) {
ob_start();
$analytics = $this->universal_analytics();
echo $analytics;
if ( empty( $analytics ) ) {
?>
aiosp_ga_use_universal_analytics ) {
$allow_linker = $cookie_domain = $domain = $addl_domains = $domain_list = '';
if ( ! empty( $aioseop_options['aiosp_ga_advanced_options'] ) ) {
$cookie_domain = $this->get_analytics_domain();
}
if ( ! empty( $cookie_domain ) ) {
$cookie_domain = esc_js( $cookie_domain );
$cookie_domain = "'cookieDomain': '{$cookie_domain}'";
}
if ( empty( $cookie_domain ) ) {
$domain = ", 'auto'";
}
if ( ! empty( $aioseop_options['aiosp_ga_advanced_options'] ) && ! empty( $aioseop_options['aiosp_ga_multi_domain'] ) ) {
$allow_linker = "'allowLinker': true";
if ( ! empty( $aioseop_options['aiosp_ga_addl_domains'] ) ) {
$addl_domains = trim( $aioseop_options['aiosp_ga_addl_domains'] );
$addl_domains = preg_split( '/[\s,]+/', $addl_domains );
if ( ! empty( $addl_domains ) ) {
foreach ( $addl_domains as $d ) {
$d = $this->sanitize_domain( $d );
if ( ! empty( $d ) ) {
if ( ! empty( $domain_list ) ) {
$domain_list .= ', ';
}
$domain_list .= "'" . $d . "'";
}
}
}
}
}
$extra_options = '';
if ( ! empty( $aioseop_options['aiosp_ga_advanced_options'] ) && ! empty( $aioseop_options['aiosp_ga_display_advertising'] ) ) {
$extra_options .= "ga('require', 'displayfeatures');";
}
if ( ! empty( $aioseop_options['aiosp_ga_advanced_options'] ) && ! empty( $aioseop_options['aiosp_ga_enhanced_ecommerce'] ) ) {
if ( ! empty( $extra_options ) ) {
$extra_options .= "\n\t\t\t";
}
$extra_options .= "ga('require', 'ec');";
}
if ( ! empty( $domain_list ) ) {
if ( ! empty( $extra_options ) ) {
$extra_options .= "\n\t\t\t";
}
$extra_options .= "ga('require', 'linker');\n\t\t\tga('linker:autoLink', [{$domain_list}] );";
}
if ( ! empty( $aioseop_options['aiosp_ga_advanced_options'] ) && ! empty( $aioseop_options['aiosp_ga_link_attribution'] ) ) {
if ( ! empty( $extra_options ) ) {
$extra_options .= "\n\t\t\t";
}
$extra_options .= "ga('require', 'linkid', 'linkid.js');";
}
if ( ! empty( $aioseop_options['aiosp_ga_advanced_options'] ) && ! empty( $aioseop_options['aiosp_ga_anonymize_ip'] ) ) {
if ( ! empty( $extra_options ) ) {
$extra_options .= "\n\t\t\t";
}
$extra_options .= "ga('set', 'anonymizeIp', true);";
}
$js_options = array();
foreach ( array( 'cookie_domain', 'allow_linker' ) as $opts ) {
if ( ! empty( $$opts ) ) {
$js_options[] = $$opts;
}
}
if ( ! empty( $js_options ) ) {
$js_options = implode( ',', $js_options );
$js_options = ', { ' . $js_options . ' } ';
} else {
$js_options = '';
}
$analytics_id = esc_js( $aioseop_options['aiosp_google_analytics_id'] );
$analytics = <<
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '{$analytics_id}'{$domain}{$js_options});
{$extra_options}
ga('send', 'pageview');
EOF;
}
return $analytics;
}
/**
* @return mixed|string
*/
function get_analytics_domain() {
global $aioseop_options;
if ( ! empty( $aioseop_options['aiosp_ga_domain'] ) ) {
return $this->sanitize_domain( $aioseop_options['aiosp_ga_domain'] );
}
return '';
}
}
}