-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogleanalytics.php
More file actions
1641 lines (1448 loc) · 72.8 KB
/
Copy pathgoogleanalytics.php
File metadata and controls
1641 lines (1448 loc) · 72.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Google Analytics for WordPress
Plugin URI: http://yoast.com/wordpress/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v420
Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. custom variables and automatic clickout and download tracking.
Author: Joost de Valk
Version: 4.2.8
Requires at least: 3.0
Author URI: http://yoast.com/
License: GPL v3
Google Analytics for WordPress
Copyright (C) 2008-2012, Joost de Valk - joost@yoast.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics
define( 'GAWP_VERSION', '4.2.8' );
/*
* Admin User Interface
*/
if ( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) && !class_exists( 'GA_Admin' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'yst_plugin_tools.php';
require_once plugin_dir_path( __FILE__ ) . '/wp-gdata/wp-gdata.php';
$options = get_option( 'Yoast_Google_Analytics' );
global $wp_version;
if ( version_compare( $wp_version, '3.3', '>=' ) && !isset( $options['tracking_popup'] ) )
require_once plugin_dir_path( __FILE__ ) . 'class-pointer.php';
if ( isset( $options['yoast_tracking'] ) && ( 'on' == $options['yoast_tracking'] || true === $options['yoast_tracking'] ) )
require_once plugin_dir_path( __FILE__ ) . 'class-tracking.php';
class GA_Admin extends Yoast_GA_Plugin_Admin {
var $hook = 'google-analytics-for-wordpress';
var $filename = 'google-analytics-for-wordpress/googleanalytics.php';
var $longname = 'Google Analytics Configuration';
var $shortname = 'Google Analytics';
var $ozhicon = 'images/chart_curve.png';
var $optionname = 'Yoast_Google_Analytics';
var $homepage = 'http://yoast.com/wordpress/google-analytics/';
var $toc = '';
/**
* PHP4 Constructor
*/
function GA_Admin() {
$this->__construct();
}
/**
* Constructur, load all required stuff.
*/
function __construct() {
$this->upgrade();
$this->plugin_url = plugins_url( '', __FILE__ ) . '/';
// Register the settings page
add_action( 'admin_menu', array( &$this, 'register_settings_page' ) );
// Register the contextual help for the settings page
// add_action( 'contextual_help', array(&$this, 'plugin_help'), 10, 3 );
// Give the settings page a nice icon in Ozh's menu
add_filter( 'ozh_adminmenu_icon', array( &$this, 'add_ozh_adminmenu_icon' ) );
// Give the plugin a settings link in the plugin overview
add_filter( 'plugin_action_links', array( &$this, 'add_action_link' ), 10, 2 );
// Print Scripts and Styles
add_action( 'admin_print_scripts', array( &$this, 'config_page_scripts' ) );
add_action( 'admin_print_styles', array( &$this, 'config_page_styles' ) );
// Print stuff in the settings page's head
add_action( 'admin_head', array( &$this, 'config_page_head' ) );
// Drop a warning on each page of the admin when Google Analytics hasn't been configured
add_action( 'admin_footer', array( &$this, 'warning' ) );
// Save settings
// TODO: replace with Options API
add_action( 'admin_init', array( &$this, 'save_settings' ) );
// Authenticate
add_action( 'admin_init', array( &$this, 'authenticate' ) );
}
function config_page_head() {
if ( isset( $_GET['allow_tracking'] ) ) {
$options = get_option( 'Yoast_Google_Analytics' );
$options['tracking_popup'] = 'done';
if ( $_GET['allow_tracking'] == 'yes' )
$options['yoast_tracking'] = true;
else
$options['yoast_tracking'] = false;
update_option( 'Yoast_Google_Analytics', $options );
}
global $current_screen;
if ( 'settings_page_' . $this->hook == $current_screen->id ) {
$options = get_option( $this->optionname );
if ( !empty( $options['uastring'] ) ) {
$uastring = $options['uastring'];
} else {
$uastring = '';
}
?>
<script type="text/javascript">
function makeSublist(parent, child, childVal) {
jQuery("body").append("<select style='display:none' id='" + parent + child + "'></select>");
jQuery('#' + parent + child).html(jQuery("#" + child + " option"));
var parentValue = jQuery('#' + parent).val();
jQuery('#' + child).html(jQuery("#" + parent + child + " .sub_" + parentValue).clone());
childVal = (typeof childVal == "undefined") ? "" : childVal;
jQuery("#" + child).val(childVal).attr('selected', 'selected');
jQuery('#' + parent).change(function () {
var parentValue = jQuery('#' + parent).val();
jQuery('#' + child).html(jQuery("#" + parent + child + " .sub_" + parentValue).clone());
jQuery('#' + child).trigger("change");
jQuery('#' + child).focus();
});
}
jQuery(document).ready(function () {
makeSublist('ga_account', 'uastring_sel', '<?php echo $uastring; ?>');
jQuery('#position').change(function () {
if (jQuery('#position').val() == 'header') {
jQuery('#position_header').css("display", "block");
jQuery('#position_manual').css("display", "none");
} else {
jQuery('#position_header').css("display", "none");
jQuery('#position_manual').css("display", "block");
}
}).change();
jQuery('#switchtomanual').change(function () {
if (jQuery('#switchtomanual').is(':checked')) {
jQuery('#uastring_manual').css('display', 'block');
jQuery('#uastring_automatic').css('display', 'none');
} else {
jQuery('#uastring_manual').css('display', 'none');
jQuery('#uastring_automatic').css('display', 'block');
}
}).change();
jQuery('#trackoutbound').change(function () {
if (jQuery('#trackoutbound').is(':checked')) {
jQuery('#internallinktracking').css("display", "block");
jQuery('.internallinktracking').css("display", "list-item");
} else {
jQuery('#internallinktracking').css("display", "none");
jQuery('.internallinktracking').css("display", "none");
}
}).change();
jQuery('#advancedsettings').change(function () {
if (jQuery('#advancedsettings').is(':checked')) {
jQuery('#advancedgasettings').css("display", "block");
jQuery('#customvarsettings').css("display", "block");
jQuery('.advancedgasettings').css("display", "list-item");
jQuery('.customvarsettings').css("display", "list-item");
} else {
jQuery('#advancedgasettings').css("display", "none");
jQuery('#customvarsettings').css("display", "none");
jQuery('.advancedgasettings').css("display", "none");
jQuery('.customvarsettings').css("display", "none");
}
}).change();
jQuery('#extrase').change(function () {
if (jQuery('#extrase').is(':checked')) {
jQuery('#extrasebox').css("display", "block");
} else {
jQuery('#extrasebox').css("display", "none");
}
}).change();
jQuery('#gajslocalhosting').change(function () {
if (jQuery('#gajslocalhosting').is(':checked')) {
jQuery('#localhostingbox').css("display", "block");
} else {
jQuery('#localhostingbox').css("display", "none");
}
}).change();
jQuery('#customvarsettings :input').change(function () {
if (jQuery("#customvarsettings :input:checked").size() > 5) {
alert("<?php _e( 'The maximum number of allowed custom variables in Google Analytics is 5, please unselect one of the other custom variables before selecting this one.' ); ?>");
jQuery(this).attr('checked', false);
}
;
});
jQuery('#uastring').change(function () {
if (jQuery('#switchtomanual').is(':checked')) {
if (!jQuery(this).val().match(/^UA-[\d-]+$/)) {
alert("<?php _e( 'That\'s not a valid UA ID, please make sure it matches the expected pattern of: UA-XXXXXX-X, and that there are no spaces or other characters in the input field.' ); ?>");
jQuery(this).focus();
}
}
});
});
</script>
<link rel="shortcut icon" href="<?php echo $this->plugin_url; ?>images/favicon.ico"/>
<?php
}
}
function plugin_help( $contextual_help, $screen_id, $screen ) {
if ( $screen_id == 'settings_page_' . $this->hook ) {
$contextual_help = '<h2>' . __( 'Having problems?' ) . '</h2>' .
'<p>' . sprintf( __( "If you're having problems with this plugin, please refer to its <a href='%s'>FAQ page</a>." ), 'http://yoast.com/wordpress/google-analytics/ga-wp-faq/' ) . '</p>';
}
return $contextual_help;
}
function toc( $modules ) {
$output = '<ul>';
foreach ( $modules as $module => $key ) {
$output .= '<li class="' . $key . '"><a href="#' . $key . '">' . $module . '</a></li>';
}
$output .= '</ul>';
return $output;
}
function save_settings() {
$options = get_option( $this->optionname );
if ( isset( $_REQUEST['reset'] ) && $_REQUEST['reset'] == "true" && isset( $_REQUEST['plugin'] ) && $_REQUEST['plugin'] == 'google-analytics-for-wordpress' ) {
$options = $this->set_defaults();
$options['msg'] = "<div class=\"updated\"><p>" . __( 'Google Analytics settings reset.' ) . "</p></div>\n";
} elseif ( isset( $_POST['submit'] ) && isset( $_POST['plugin'] ) && $_POST['plugin'] == 'google-analytics-for-wordpress' ) {
if ( !current_user_can( 'manage_options' ) ) die( __( 'You cannot edit the Google Analytics for WordPress options.' ) );
check_admin_referer( 'analyticspp-config' );
foreach ( array( 'uastring', 'dlextensions', 'domainorurl', 'position', 'domain', 'customcode', 'ga_token', 'extraseurl', 'gajsurl', 'gfsubmiteventpv', 'trackprefix', 'ignore_userlevel', 'internallink', 'internallinklabel', 'primarycrossdomain', 'othercrossdomains' ) as $option_name ) {
if ( isset( $_POST[$option_name] ) )
$options[$option_name] = $_POST[$option_name];
else
$options[$option_name] = '';
}
foreach ( array( 'extrase', 'trackoutbound', 'admintracking', 'trackadsense', 'allowanchor', 'allowlinker', 'allowhash', 'rsslinktagging', 'advancedsettings', 'trackregistration', 'theme_updated', 'cv_loggedin', 'cv_authorname', 'cv_category', 'cv_all_categories', 'cv_tags', 'cv_year', 'cv_post_type', 'outboundpageview', 'downloadspageview', 'trackcrossdomain', 'gajslocalhosting', 'manual_uastring', 'taggfsubmit', 'wpec_tracking', 'shopp_tracking', 'anonymizeip', 'trackcommentform', 'debug', 'firebuglite', 'yoast_tracking' ) as $option_name ) {
if ( isset( $_POST[$option_name] ) && $_POST[$option_name] == 'on' )
$options[$option_name] = true;
else
$options[$option_name] = false;
}
if ( isset( $_POST['manual_uastring'] ) && isset( $_POST['uastring_man'] ) ) {
$options['uastring'] = $_POST['uastring_man'];
}
if ( $options['trackcrossdomain'] ) {
if ( !$options['allowlinker'] )
$options['allowlinker'] = true;
if ( empty( $options['primarycrossdomain'] ) ) {
$origin = GA_Filter::ga_get_domain( $_SERVER["HTTP_HOST"] );
$options['primarycrossdomain'] = $origin["domain"];
}
}
if ( function_exists( 'w3tc_pgcache_flush' ) )
w3tc_pgcache_flush();
if ( function_exists( 'w3tc_dbcache_flush' ) )
w3tc_dbcache_flush();
if ( function_exists( 'w3tc_minify_flush' ) )
w3tc_minify_flush();
if ( function_exists( 'w3tc_objectcache_flush' ) )
w3tc_objectcache_flush();
if ( function_exists( 'wp_cache_clear_cache' ) )
wp_cache_clear_cache();
$options['msg'] = "<div id=\"updatemessage\" class=\"updated fade\"><p>Google Analytics <strong>settings updated</strong>.</p></div>\n";
$options['msg'] .= "<script type=\"text/javascript\">setTimeout(function(){jQuery('#updatemessage').hide('slow');}, 3000);</script>";
}
update_option( $this->optionname, $options );
}
function save_button() {
return '<div class="alignright"><input type="submit" class="button-primary" name="submit" value="' . __( 'Update Google Analytics Settings »' ) . '" /></div><br class="clear"/>';
}
function upgrade() {
$options = get_option( $this->optionname );
if ( isset( $options['version'] ) && $options['version'] < '4.04' ) {
if ( !isset( $options['ignore_userlevel'] ) || $options['ignore_userlevel'] == '' )
$options['ignore_userlevel'] = 11;
}
if ( !isset( $options['version'] ) || $options['version'] != GAWP_VERSION ) {
$options['version'] = GAWP_VERSION;
}
update_option( $this->optionname, $options );
}
function config_page() {
$options = get_option( $this->optionname );
if ( isset( $options['msg'] ) )
echo $options['msg'];
$options['msg'] = '';
update_option( $this->optionname, $options );
if ( !isset( $options['uastring'] ) )
$options = $this->set_defaults();
$modules = array();
if ( !isset( $options['manual_uastring'] ) )
$options['manual_uastring'] = '';
?>
<div class="wrap">
<a href="http://yoast.com/">
<div id="yoast-icon"
style="background: url(<?php echo $this->plugin_url; ?>images/ga-icon-32x32.png) no-repeat;"
class="icon32"><br/></div>
</a>
<h2><?php _e( "Google Analytics for WordPress Configuration" ) ?></h2>
<div class="postbox-container" style="width:65%;">
<div class="metabox-holder">
<div class="meta-box-sortables">
<form action="<?php echo $this->plugin_options_url(); ?>" method="post" id="analytics-conf">
<input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
<?php
wp_nonce_field( 'analyticspp-config' );
if ( empty( $options['uastring'] ) && empty( $options['ga_token'] ) ) {
$query = $this->plugin_options_url() . '&reauth=true';
$line = 'Please authenticate with Google Analytics to retrieve your tracking code:<br/><br/> <a class="button-primary" href="' . $query . '">Click here to authenticate with Google</a><br/><br/><strong>Note</strong>: if you have multiple Google accounts, you\'ll want to switch to the right account first, since Google doesn\'t let you switch accounts on the authentication screen.';
} else if ( isset( $options['ga_token'] ) && !empty( $options['ga_token'] ) ) {
$token = $options['ga_token'];
require_once plugin_dir_path( __FILE__ ) . 'xmlparser.php';
if ( file_exists( ABSPATH . 'wp-includes/class-http.php' ) )
require_once( ABSPATH . 'wp-includes/class-http.php' );
if ( !isset( $options['ga_api_responses'][$token] ) ) {
$options['ga_api_responses'] = array();
if ( $oauth = $options['gawp_oauth'] ) {
if ( isset( $oauth['params']['oauth_token'], $oauth['params']['oauth_token_secret'] ) ) {
$options['gawp_oauth']['access_token'] = array(
'oauth_token' => base64_decode( $oauth['params']['oauth_token'] ),
'oauth_token_secret' => base64_decode( $oauth['params']['oauth_token_secret'] )
);
unset( $options['gawp_oauth']['params'] );
update_option( $this->optionname, $options );
}
}
$args = array(
'scope' => 'https://www.google.com/analytics/feeds/',
'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
);
$access_token = $options['gawp_oauth']['access_token'];
$gdata = new WP_Gdata( $args, $access_token['oauth_token'], $access_token['oauth_token_secret'] );
$response = $gdata->get( 'https://www.google.com/analytics/feeds/accounts/default' );
$http_code = wp_remote_retrieve_response_code( $response );
$response = wp_remote_retrieve_body( $response );
if ( $http_code == 200 ) {
$options['ga_api_responses'][$token] = array(
'response'=> array( 'code'=> $http_code ),
'body' => $response
);
$options['ga_token'] = $token;
update_option( 'Yoast_Google_Analytics', $options );
}
}
if ( isset( $options['ga_api_responses'][$token] ) && is_array( $options['ga_api_responses'][$token] ) && $options['ga_api_responses'][$token]['response']['code'] == 200 ) {
$arr = yoast_xml2array( $options['ga_api_responses'][$token]['body'] );
$ga_accounts = array();
if ( isset( $arr['feed']['entry'][0] ) ) {
foreach ( $arr['feed']['entry'] as $site ) {
$ua = $site['dxp:property']['3_attr']['value'];
$account = $site['dxp:property']['1_attr']['value'];
if ( !isset( $ga_accounts[$account] ) || !is_array( $ga_accounts[$account] ) )
$ga_accounts[$account] = array();
$ga_accounts[$account][$site['title']] = $ua;
}
} else {
$ua = $arr['feed']['entry']['dxp:property']['3_attr']['value'];
$account = $arr['feed']['entry']['dxp:property']['1_attr']['value'];
$title = $arr['feed']['entry']['title'];
if ( !isset( $ga_accounts[$account] ) || !is_array( $ga_accounts[$account] ) )
$ga_accounts[$account] = array();
$ga_accounts[$account][$title] = $ua;
}
$select1 = '<select style="width:150px;" name="ga_account" id="ga_account">';
$select1 .= "\t<option></option>\n";
$select2 = '<select style="width:150px;" name="uastring" id="uastring_sel">';
$i = 1;
$currentua = '';
if ( !empty( $options['uastring'] ) )
$currentua = $options['uastring'];
foreach ( $ga_accounts as $account => $val ) {
$accountsel = false;
foreach ( $val as $title => $ua ) {
$sel = selected( $ua, $currentua, false );
if ( !empty( $sel ) ) {
$accountsel = true;
}
$select2 .= "\t" . '<option class="sub_' . $i . '" ' . $sel . ' value="' . $ua . '">' . $title . ' - ' . $ua . '</option>' . "\n";
}
$select1 .= "\t" . '<option ' . selected( $accountsel, true, false ) . ' value="' . $i . '">' . $account . '</option>' . "\n";
$i++;
}
$select1 .= '</select>';
$select2 .= '</select>';
$line = '<input type="hidden" name="ga_token" value="' . $token . '"/>';
$line .= 'Please select the correct Analytics profile to track:<br/>';
$line .= '<table class="form_table">';
$line .= '<tr><th width="15%">Account:</th><td width="85%">' . $select1 . '</td></tr>';
$line .= '<tr><th>Profile:</th><td>' . $select2 . '</td></tr>';
$line .= '</table>';
$try = 1;
if ( isset( $_GET['try'] ) )
$try = $_GET['try'] + 1;
if ( $i == 1 && $try < 4 && isset( $_GET['token'] ) ) {
$line .= '<script type="text/javascript">
window.location="' . $this->plugin_options_url() . '&switchua=1&token=' . $token . '&try=' . $try . '";
</script>';
}
$line .= 'Please note that if you have several profiles of the same website, it doesn\'t matter which profile you select, and in fact another profile might show as selected later. You can check whether they\'re profiles for the same site by checking if they have the same UA code. If that\'s true, tracking will be correct.<br/>';
$line .= '<br/>Refresh this listing or switch to another account: ';
} else {
$line = 'Unfortunately, an error occurred while connecting to Google, please try again:';
}
$query = $this->plugin_options_url() . '&reauth=true';
$line .= '<a class="button" href="' . $query . '">Re-authenticate with Google</a>';
} else {
$line = '<input id="uastring" name="uastring" type="text" size="20" maxlength="40" value="' . $options['uastring'] . '"/><br/><a href="' . $this->plugin_options_url() . '&switchua=1">Select another Analytics Profile »</a>';
}
$line = '<div id="uastring_automatic">' . $line . '</div><div style="display:none;" id="uastring_manual">Manually enter your UA code: <input id="uastring" name="uastring_man" type="text" size="20" maxlength="40" value="' . $options['uastring'] . '"/></div>';
$rows = array();
$content = '';
$rows[] = array(
'id' => 'uastring',
'label' => 'Analytics Profile',
'desc' => '<input type="checkbox" name="manual_uastring" ' . checked( $options['manual_uastring'], true, false ) . ' id="switchtomanual"/> <label for="switchtomanual">Manually enter your UA code</label>',
'content' => $line
);
$temp_content = $this->select( 'position', array( 'header' => 'In the header (default)', 'manual' => 'Insert manually' ) );
if ( $options['theme_updated'] && $options['position'] == 'manual' ) {
$temp_content .= '<input type="hidden" name="theme_updated" value="off"/>';
echo '<div id="message" class="updated" style="background-color:lightgreen;border-color:green;"><p><strong>Notice:</strong> You switched your theme, please make sure your Google Analytics tracking is still ok. Save your settings to make sure Google Analytics gets loaded properly.</p></div>';
remove_action( 'admin_footer', array( &$this, 'theme_switch_warning' ) );
}
$desc = '<div id="position_header">The header is by far the best spot to place the tracking code. If you\'d rather place the code manually, switch to manual placement. For more info <a href="http://yoast.com/wordpress/google-analytics/manual-placement/">read this page</a>.</div>';
$desc .= '<div id="position_manual"><a href="http://yoast.com/wordpress/google-analytics/manual-placement/">Follow the instructions here</a> to choose the location for your tracking code manually.</div>';
$rows[] = array(
'id' => 'position',
'label' => 'Where should the tracking code be placed',
'desc' => $desc,
'content' => $temp_content,
);
$rows[] = array(
'id' => 'trackoutbound',
'label' => 'Track outbound clicks & downloads',
'desc' => 'Clicks & downloads will be tracked as events, you can find these under Content » Event Tracking in your Google Analytics reports.',
'content' => $this->checkbox( 'trackoutbound' ),
);
$rows[] = array(
'id' => 'advancedsettings',
'label' => 'Show advanced settings',
'desc' => 'Only adviced for advanced users who know their way around Google Analytics',
'content' => $this->checkbox( 'advancedsettings' ),
);
$rows[] = array(
'id' => 'yoast_tracking',
'label' => 'Allow tracking of anonymous data',
'desc' => 'By allowing us to track anonymous data we can better help you, because we know with which WordPress configurations, themes and plugins we should test. No personal data will be submitted.',
'content' => $this->checkbox( 'yoast_tracking' ),
);
$this->postbox( 'gasettings', 'Google Analytics Settings', $this->form_table( $rows ) . $this->save_button() );
$rows = array();
$pre_content = '<p>Google Analytics allows you to save up to 5 custom variables on each page, and this plugin helps you make the most use of these! Check which custom variables you\'d like the plugin to save for you below. Please note that these will only be saved when they are actually available.</p><p>If you want to start using these custom variables, go to Visitors » Custom Variables in your Analytics reports.</p>';
$rows[] = array(
'id' => 'cv_loggedin',
'label' => 'Logged in Users',
'desc' => 'Allows you to easily remove logged in users from your reports, or to segment by different user roles. The users primary role will be logged.',
'content' => $this->checkbox( 'cv_loggedin' ),
);
$rows[] = array(
'id' => 'cv_post_type',
'label' => 'Post type',
'desc' => 'Allows you to see pageviews per post type, especially useful if you use multiple custom post types.',
'content' => $this->checkbox( 'cv_post_type' ),
);
$rows[] = array(
'id' => 'cv_authorname',
'label' => 'Author Name',
'desc' => 'Allows you to see pageviews per author.',
'content' => $this->checkbox( 'cv_authorname' ),
);
$rows[] = array(
'id' => 'cv_tags',
'label' => 'Tags',
'desc' => 'Allows you to see pageviews per tags using advanced segments.',
'content' => $this->checkbox( 'cv_tags' ),
);
$rows[] = array(
'id' => 'cv_year',
'label' => 'Publication year',
'desc' => 'Allows you to see pageviews per year of publication, showing you if your old posts still get traffic.',
'content' => $this->checkbox( 'cv_year' ),
);
$rows[] = array(
'id' => 'cv_category',
'label' => 'Single Category',
'desc' => 'Allows you to see pageviews per category, works best when each post is in only one category.',
'content' => $this->checkbox( 'cv_category' ),
);
$rows[] = array(
'id' => 'cv_all_categories',
'label' => 'All Categories',
'desc' => 'Allows you to see pageviews per category using advanced segments, should be used when you use multiple categories per post.',
'content' => $this->checkbox( 'cv_all_categories' ),
);
$modules['Custom Variables'] = 'customvarsettings';
$this->postbox( 'customvarsettings', 'Custom Variables Settings', $pre_content . $this->form_table( $rows ) . $this->save_button() );
$rows = array();
$rows[] = array(
'id' => 'ignore_userlevel',
'label' => 'Ignore users',
'desc' => 'Users of the role you select and higher will be ignored, so if you select Editor, all Editors and Administrators will be ignored.',
'content' => $this->select( 'ignore_userlevel', array(
'11' => 'Ignore no-one',
'8' => 'Administrator',
'5' => 'Editor',
'2' => 'Author',
'1' => 'Contributor',
'0' => 'Subscriber (ignores all logged in users)',
) ),
);
$rows[] = array(
'id' => 'outboundpageview',
'label' => 'Track outbound clicks as pageviews',
'desc' => 'You do not need to enable this to enable outbound click tracking, this changes the default behavior of tracking clicks as events to tracking them as pageviews. This is therefore not recommended, as this would skew your statistics, but <em>is</em> sometimes necessary when you need to set outbound clicks as goals.',
'content' => $this->checkbox( 'outboundpageview' ),
);
$rows[] = array(
'id' => 'downloadspageview',
'label' => 'Track downloads as pageviews',
'desc' => 'Not recommended, as this would skew your statistics, but it does make it possible to track downloads as goals.',
'content' => $this->checkbox( 'downloadspageview' ),
);
$rows[] = array(
'id' => 'dlextensions',
'label' => 'Extensions of files to track as downloads',
'content' => $this->textinput( 'dlextensions' ),
);
if ( $options['outboundpageview'] ) {
$rows[] = array(
'id' => 'trackprefix',
'label' => 'Prefix to use in Analytics before the tracked pageviews',
'desc' => 'This prefix is used before all pageviews, they are then segmented automatically after that. If nothing is entered here, <code>/yoast-ga/</code> is used.',
'content' => $this->textinput( 'trackprefix' ),
);
}
$rows[] = array(
'id' => 'domainorurl',
'label' => 'Track full URL of outbound clicks or just the domain',
'content' => $this->select( 'domainorurl', array(
'domain' => 'Just the domain',
'url' => 'Track the complete URL',
)
),
);
$rows[] = array(
'id' => 'domain',
'label' => 'Subdomain Tracking',
'desc' => 'This allows you to set the domain that\'s set by <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for tracking subdomains, if empty this will not be set.',
'content' => $this->textinput( 'domain' ),
);
$rows[] = array(
'id' => 'trackcrossdomain',
'label' => 'Enable Cross Domain Tracking',
'desc' => 'This allows you to enable <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html">Cross-Domain Tracking</a> for this site. When endabled <code>_setAllowLinker:</code> will be enabled if it is not already.',
'content' => $this->checkbox( 'trackcrossdomain' ),
);
$rows[] = array(
'id' => 'primarycrossdomain',
'label' => 'Cross-Domain Tracking, Primary Domain',
'desc' => 'Set the primary domain used in <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for cross domain tracking (eg. <code>example-petstore.com</code> ), if empty this will default to your configured Home URL.',
'content' => $this->textinput( 'primarycrossdomain' ),
);
$rows[] = array(
'id' => 'othercrossdomains',
'label' => 'Cross-Domain Tracking, Other Domains',
'desc' => 'All links to these domains will have the <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#multipleDomains"><code>_link</code></a> code automatically attached. Separate domains/sub-domains with commas (eg. <code>dogs.example-petstore.com, cats.example-petstore.com</code>)',
'content' => $this->textinput( 'othercrossdomains' ),
);
$rows[] = array(
'id' => 'customcode',
'label' => 'Custom Code',
'desc' => 'Not for the average user: this allows you to add a line of code, to be added before the <code>trackPageview</code> call.',
'content' => $this->textinput( 'customcode' ),
);
$rows[] = array(
'id' => 'trackadsense',
'label' => 'Track AdSense',
'desc' => 'This requires integration of your Analytics and AdSense account, for help, <a href="http://google.com/support/analytics/bin/answer.py?answer=92625">look here</a>.',
'content' => $this->checkbox( 'trackadsense' ),
);
$rows[] = array(
'id' => 'gajslocalhosting',
'label' => 'Host ga.js locally',
'content' => $this->checkbox( 'gajslocalhosting' ) . '<div id="localhostingbox">
You have to provide a URL to your ga.js file:
<input type="text" name="gajsurl" size="30" value="' . $options['gajsurl'] . '"/>
</div>',
'desc' => 'For some reasons you might want to use a locally hosted ga.js file, or another ga.js file, check the box and then please enter the full URL including http here.'
);
$rows[] = array(
'id' => 'extrase',
'label' => 'Track extra Search Engines',
'content' => $this->checkbox( 'extrase' ) . '<div id="extrasebox">
You can provide a custom URL to the extra search engines file if you want:
<input type="text" name="extraseurl" size="30" value="' . $options['extraseurl'] . '"/>
</div>',
);
$rows[] = array(
'id' => 'rsslinktagging',
'label' => 'Tag links in RSS feed with campaign variables',
'desc' => 'Do not use this feature if you use FeedBurner, as FeedBurner can do this automatically, and better than this plugin can. Check <a href="http://www.google.com/support/feedburner/bin/answer.py?hl=en&answer=165769">this help page</a> for info on how to enable this feature in FeedBurner.',
'content' => $this->checkbox( 'rsslinktagging' ),
);
$rows[] = array(
'id' => 'trackregistration',
'label' => 'Add tracking to the login and registration forms',
'content' => $this->checkbox( 'trackregistration' ),
);
$rows[] = array(
'id' => 'trackcommentform',
'label' => 'Add tracking to the comment forms',
'content' => $this->checkbox( 'trackcommentform' ),
);
$rows[] = array(
'id' => 'allowanchor',
'label' => 'Use # instead of ? for Campaign tracking',
'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJSApiCampaignTracking.html#_gat.GA_Tracker_._setAllowAnchor">_setAllowAnchor</a></code> call to your tracking code, and makes RSS link tagging use a # as well.',
'content' => $this->checkbox( 'allowanchor' ),
);
$rows[] = array(
'id' => 'allowlinker',
'label' => 'Add <code>_setAllowLinker</code>',
'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowLinker">_setAllowLinker</a></code> call to your tracking code, allowing you to use <code>_link</code> and related functions.',
'content' => $this->checkbox( 'allowlinker' ),
);
$rows[] = array(
'id' => 'allowhash',
'label' => 'Set <code>_setAllowHash</code> to false',
'desc' => 'This sets <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowHash">_setAllowHash</a></code> to false, allowing you to track subdomains etc.',
'content' => $this->checkbox( 'allowhash' ),
);
$rows[] = array(
'id' => 'anonymizeip',
'label' => 'Anonymize IP\'s',
'desc' => 'This adds <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gat.html#_gat._anonymizeIp">_anonymizeIp</a></code>, telling Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage.',
'content' => $this->checkbox( 'anonymizeip' ),
);
$modules['Advanced Settings'] = 'advancedgasettings';
$this->postbox( 'advancedgasettings', 'Advanced Settings', $this->form_table( $rows ) . $this->save_button() );
$rows = array();
$rows[] = array(
'id' => 'internallink',
'label' => 'Internal links to track as outbound',
'desc' => 'If you want to track all internal links that begin with <code>/out/</code>, enter <code>/out/</code> in the box above. If you have multiple prefixes you can separate them with comma\'s: <code>/out/,/recommends/</code>',
'content' => $this->textinput( 'internallink' ),
);
$rows[] = array(
'id' => 'internallinklabel',
'label' => 'Label to use',
'desc' => 'The label to use for these links, this will be added to where the click came from, so if the label is "aff", the label for a click from the content of an article becomes "outbound-article-aff".',
'content' => $this->textinput( 'internallinklabel' ),
);
$modules['Internal Link Tracking'] = 'internallinktracking';
$this->postbox( 'internallinktracking', 'Internal Links to Track as Outbound', $this->form_table( $rows ) . $this->save_button() );
/* if (class_exists('RGForms') && GFCommon::$version >= '1.3.11') {
$pre_content = 'This plugin can automatically tag your Gravity Forms to track form submissions as either events or pageviews';
$rows = array();
$rows[] = array(
'id' => 'taggfsubmit',
'label' => 'Tag Gravity Forms',
'content' => $this->checkbox('taggfsubmit'),
);
$rows[] = array(
'id' => 'gfsubmiteventpv',
'label' => 'Tag Gravity Forms as',
'content' => '<select name="gfsubmiteventpv">
<option value="events" '.selected($options['gfsubmiteventpv'],'events',false).'>Events</option>
<option value="pageviews" '.selected($options['gfsubmiteventpv'],'pageviews',false).'>Pageviews</option>
</select>',
);
$this->postbox('gravityforms','Gravity Forms Settings',$pre_content.$this->form_table($rows).$this->save_button());
$modules['Gravity Forms'] = 'gravityforms';
}
*/
if ( defined( 'WPSC_VERSION' ) ) {
$pre_content = 'The WordPress e-Commerce plugin has been detected. This plugin can automatically add transaction tracking for you. To do that, <a href="http://yoast.com/wordpress/google-analytics/enable-ecommerce/">enable e-commerce for your reports in Google Analytics</a> and then check the box below.';
$rows = array();
$rows[] = array(
'id' => 'wpec_tracking',
'label' => 'Enable transaction tracking',
'content' => $this->checkbox( 'wpec_tracking' ),
);
$this->postbox( 'wpecommerce', 'WordPress e-Commerce Settings', $pre_content . $this->form_table( $rows ) . $this->save_button() );
$modules['WordPress e-Commerce'] = 'wpecommerce';
}
global $Shopp;
if ( isset( $Shopp ) ) {
$pre_content = 'The Shopp e-Commerce plugin has been detected. This plugin can automatically add transaction tracking for you. To do that, <a href="http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55528">enable e-commerce for your reports in Google Analytics</a> and then check the box below.';
$rows = array();
$rows[] = array(
'id' => 'shopp_tracking',
'label' => 'Enable transaction tracking',
'content' => $this->checkbox( 'shopp_tracking' ),
);
$this->postbox( 'shoppecommerce', 'Shopp e-Commerce Settings', $pre_content . $this->form_table( $rows ) . $this->save_button() );
$modules['Shopp'] = 'shoppecommerce';
}
$pre_content = '<p>If you want to confirm that tracking on your blog is working as it should, enable this option and check the console in <a href="http://getfirebug.com/">Firebug</a> (for Firefox), <a href="http://getfirebug.com/firebuglite">Firebug Lite</a> (for other browsers) or Chrome & Safari\'s Web Inspector. Be absolutely sure to disable debugging afterwards, as it is slower than normal tracking.</p><p><strong>Note</strong>: the debugging and firebug scripts are only loaded for admins.</p>';
$rows = array();
$rows[] = array(
'id' => 'debug',
'label' => 'Enable debug mode',
'content' => $this->checkbox( 'debug' ),
);
$rows[] = array(
'id' => 'firebuglite',
'label' => 'Enable Firebug Lite',
'content' => $this->checkbox( 'firebuglite' ),
);
$this->postbox( 'debugmode', 'Debug Mode', $pre_content . $this->form_table( $rows ) . $this->save_button() );
$modules['Debug Mode'] = 'debugmode';
?>
</form>
<form action="<?php echo $this->plugin_options_url(); ?>" method="post"
onsubmit="javascript:return(confirm('Do you really want to reset all settings?'));">
<input type="hidden" name="reset" value="true"/>
<input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
<div class="submit"><input type="submit" value="Reset All Settings »"/></div>
</form>
</div>
</div>
</div>
<div class="postbox-container side" style="width:20%;">
<div class="metabox-holder">
<div class="meta-box-sortables">
<?php
if ( count( $modules ) > 0 )
$this->postbox( 'toc', 'List of Available Modules', $this->toc( $modules ) );
$this->postbox( 'donate', '<strong class="red">' . __( 'Help Spread the Word!' ) . '</strong>', '<p><strong>' . __( 'Want to help make this plugin even better? All donations are used to improve this plugin, so donate $20, $50 or $100 now!' ) . '</strong></p><form style="width:160px;margin:0 auto;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="FW9FK4EBZ9FVJ">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>'
. '<p>' . __( 'Or you could:' ) . '</p>'
. '<ul>'
. '<li><a href="http://wordpress.org/extend/plugins/google-analytics-for-wordpress/">' . __( 'Rate the plugin 5★ on WordPress.org' ) . '</a></li>'
. '<li><a href="http://wordpress.org/tags/google-analytics-for-wordpress">' . __( 'Help out other users in the forums' ) . '</a></li>'
. '<li>' . sprintf( __( 'Blog about it & link to the %1$splugin page%2$s' ), '<a href="http://yoast.com/wordpress/google-analytics/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>' ) . '</li>' );
$this->postbox( 'sitereview', '<strong>' . __( 'Want to Improve your Site?' ) . '</strong>', '<p>' . sprintf( __( 'If you want to improve your site, but don\'t know where to start, you should order a %1$swebsite review%2$s from Yoast!' ), '<a href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>' ) . '</p>' . '<p>' . __( 'The results of this review contain a full report of improvements for your site, encompassing my findings for improvements in different key areas such as SEO to Usability to Site Speed & more.' ) . '</p>' . '<p><a class="button-secondary" href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=button&utm_campaign=wpgaplugin">' . __( 'Click here to read more »' ) . '</a></p>' );
$this->plugin_support();
$this->news();
?>
</div>
<br/><br/><br/>
</div>
</div>
</div>
<?php
}
function set_defaults() {
$options = array(
'advancedsettings' => false,
'allowanchor' => false,
'allowhash' => false,
'allowlinker' => false,
'anonymizeip' => false,
'customcode' => '',
'cv_loggedin' => false,
'cv_authorname' => false,
'cv_category' => false,
'cv_all_categories' => false,
'cv_tags' => false,
'cv_year' => false,
'cv_post_type' => false,
'debug' => false,
'dlextensions' => 'doc,exe,js,pdf,ppt,tgz,zip,xls',
'domain' => '',
'domainorurl' => 'domain',
'extrase' => false,
'extraseurl' => '',
'firebuglite' => false,
'ga_token' => '',
'ga_api_responses' => array(),
'gajslocalhosting' => false,
'gajsurl' => '',
'ignore_userlevel' => '11',
'internallink' => false,
'internallinklabel' => '',
'outboundpageview' => false,
'downloadspageview' => false,
'othercrossdomains' => '',
'position' => 'footer',
'primarycrossdomain' => '',
'theme_updated' => false,
'trackcommentform' => true,
'trackcrossdomain' => false,
'trackadsense' => false,
'trackoutbound' => true,
'trackregistration' => false,
'rsslinktagging' => true,
'uastring' => '',
'version' => GAWP_VERSION,
);
update_option( $this->optionname, $options );
return $options;
}
function warning() {
$options = get_option( $this->optionname );
if ( !isset( $options['uastring'] ) || empty( $options['uastring'] ) ) {
echo "<div id='message' class='error'><p><strong>Google Analytics is not active.</strong> You must <a href='" . $this->plugin_options_url() . "'>select which Analytics Profile to track</a> before it can work.</p></div>";
}
} // end warning()
function authenticate() {
if ( isset( $_REQUEST['ga_oauth_callback'] ) ) {
$o = get_option( $this->optionname );
if ( isset( $o['gawp_oauth']['oauth_token'] ) && $o['gawp_oauth']['oauth_token'] == $_REQUEST['oauth_token'] ) {
$gdata = new WP_GData(
array(
'scope' => 'https://www.google.com/analytics/feeds/',
'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
),
$o['gawp_oauth']['oauth_token'],
$o['gawp_oauth']['oauth_token_secret']
);
$o['gawp_oauth']['access_token'] = $gdata->get_access_token( $_REQUEST['oauth_verifier'] );
unset( $o['gawp_oauth']['oauth_token'] );
unset( $o['gawp_oauth']['oauth_token_secret'] );
$o['ga_token'] = $o['gawp_oauth']['access_token']['oauth_token'];
}
update_option( $this->optionname, $o );
wp_redirect( menu_page_url( $this->hook, false ) );
exit;
}
if ( !empty( $_GET['reauth'] ) ) {
$gdata = new WP_GData(
array(
'scope' => 'https://www.google.com/analytics/feeds/',
'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
)
);
$oauth_callback = add_query_arg( array( 'ga_oauth_callback' => 1 ), menu_page_url( 'google-analytics-for-wordpress', false ) );
$request_token = $gdata->get_request_token( $oauth_callback );
$options = get_option( $this->optionname );
unset( $options['ga_token'] );
unset( $options['gawp_oauth']['access_token'] );
$options['gawp_oauth']['oauth_token'] = $request_token['oauth_token'];
$options['gawp_oauth']['oauth_token_secret'] = $request_token['oauth_token_secret'];
update_option( $this->optionname, $options );
wp_redirect( $gdata->get_authorize_url( $request_token ) );
exit;
}
} //end reauthenticate()
} // end class GA_Admin
$ga_admin = new GA_Admin();
} //endif
/**
* Code that actually inserts stuff into pages.
*/
if ( !class_exists( 'GA_Filter' ) ) {
class GA_Filter {
/**
* Cleans the variable to make it ready for storing in Google Analytics
*/
function ga_str_clean( $val ) {
return remove_accents( str_replace( '---', '-', str_replace( ' ', '-', strtolower( html_entity_decode( $val ) ) ) ) );
}
/*
* Insert the tracking code into the page
*/
function spool_analytics() {
global $wp_query;
// echo '<!--'.print_r($wp_query,1).'-->';
$options = get_option( 'Yoast_Google_Analytics' );
if ( !isset( $options['uastring'] ) || $options['uastring'] == '' ) {
if ( current_user_can( 'manage_options' ) )
echo "<!-- Google Analytics tracking code not shown because yo haven't chosen a Google Analytics account yet. -->\n";
return;
}
/**
* The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
*/
$customvarslot = 1;
if ( yoast_ga_do_tracking() && !is_preview() ) {
$push = array();
if ( $options['allowanchor'] )
$push[] = "'_setAllowAnchor',true";
if ( $options['allowlinker'] )
$push[] = "'_setAllowLinker',true";
if ( $options['anonymizeip'] )
$push[] = "'_gat._anonymizeIp'";
if ( isset( $options['domain'] ) && $options['domain'] != "" )
$push[] = "'_setDomainName','" . $options['domain'] . "'";
if ( isset( $options['trackcrossdomain'] ) && $options['trackcrossdomain'] )
$push[] = "'_setDomainName','" . $options['primarycrossdomain'] . "'";
if ( isset( $options['allowhash'] ) && $options['allowhash'] )
$push[] = "'_setAllowHash',false";
if ( $options['cv_loggedin'] ) {
$current_user = wp_get_current_user();
if ( $current_user && $current_user->ID != 0 )
$push[] = "'_setCustomVar',$customvarslot,'logged-in','" . $current_user->roles[0] . "',1";
// Customvar slot needs to be upped even when the user is not logged in, to make sure the variables below are always in the same slot.
$customvarslot++;
}
if ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
if ( $options['cv_post_type'] ) {
$post_type = get_post_type();
if ( $post_type ) {
$push[] = "'_setCustomVar'," . $customvarslot . ",'post_type','" . $post_type . "',3";
$customvarslot++;
}
}
} else if ( is_singular() && !is_home() ) {