-
Notifications
You must be signed in to change notification settings - Fork 815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Google Analytics module #5603
Changes from 42 commits
4b59284
3607470
885fad4
498b5f7
826da93
b479e5b
94b9c1c
9c31612
61dc4d4
339d057
d3c7c05
ba504ee
7a59438
00a5646
29faa7b
67c5f6e
17c429c
857ade3
e37d1f3
7bc5265
a83338a
0011846
fc3597a
4c9ad80
88d5bed
afb6967
0bc5782
811b199
fb7dafe
8f097d2
2bd58f7
2a77d8a
0b72134
650cca5
d604658
b8546c4
88b2af4
71bdff6
92e236a
41af2a8
921f864
386a85d
ac17e57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,7 +199,7 @@ public function get_settings_response() { | |
'moderation_keys' => get_option( 'moderation_keys' ), | ||
'blacklist_keys' => get_option( 'blacklist_keys' ), | ||
'lang_id' => get_option( 'lang_id' ), | ||
'wga' => get_option( 'wga' ), | ||
'wga' => $this->get_google_analytics(), | ||
'disabled_likes' => (bool) get_option( 'disabled_likes' ), | ||
'disabled_reblogs' => (bool) get_option( 'disabled_reblogs' ), | ||
'jetpack_comment_likes_enabled' => (bool) get_option( 'jetpack_comment_likes_enabled', false ), | ||
|
@@ -266,6 +266,10 @@ protected function get_locale( $key ) { | |
return false; | ||
} | ||
|
||
protected function get_google_analytics () { | ||
$option_name = defined( 'IS_WPCOM' ) && IS_WPCOM ? 'wga' : 'jetpack_wga'; | ||
return get_option( $option_name ); | ||
} | ||
|
||
/** | ||
* Updates site settings for authorized users | ||
|
@@ -352,12 +356,18 @@ public function update_settings() { | |
} | ||
break; | ||
case 'wga': | ||
case 'jetpack_wga': | ||
if ( ! isset( $value['code'] ) || ! preg_match( '/^$|^UA-[\d-]+$/i', $value['code'] ) ) { | ||
return new WP_Error( 'invalid_code', 'Invalid UA ID' ); | ||
} | ||
$wga = get_option( 'wga', array() ); | ||
|
||
$is_wpcom = ! $is_jetpack && defined( 'IS_WPCOM' ) && IS_WPCOM; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This triggers a PHP Notice when saving the tracking ID on wpcom:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can just remove that variable, it's not used in jetpack |
||
$option_name = $is_wpcom ? 'wga' : 'jetpack_wga'; | ||
|
||
$wga = get_option( $option_name, array() ); | ||
$wga['code'] = $value['code']; // maintain compatibility with wp-google-analytics | ||
if ( update_option( 'wga', $wga ) ) { | ||
|
||
if ( update_option( $option_name, $wga ) ) { | ||
$updated[ $key ] = $value; | ||
} | ||
|
||
|
@@ -366,10 +376,11 @@ public function update_settings() { | |
/** This action is documented in modules/widgets/social-media-icons.php */ | ||
do_action( 'jetpack_bump_stats_extras', 'google-analytics', $enabled_or_disabled ); | ||
|
||
$business_plugins = WPCOM_Business_Plugins::instance(); | ||
$business_plugins->activate_plugin( 'wp-google-analytics' ); | ||
if ( $is_wpcom ) { | ||
$business_plugins = WPCOM_Business_Plugins::instance(); | ||
$business_plugins->activate_plugin( 'wp-google-analytics' ); | ||
} | ||
break; | ||
|
||
case 'jetpack_testimonial': | ||
case 'jetpack_portfolio': | ||
case 'jetpack_comment_likes_enabled': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
/** | ||
* Module Name: Google Analytics | ||
* Module Description: Lets you use Google Analytics to track your WordPress site statistics. | ||
* First Introduced: 4.5 | ||
* Sort Order: 37 | ||
* Requires Connection: Yes | ||
* Auto Activate: No | ||
* Feature: Engagement | ||
* Additional Search Queries: webmaster, google, analytics, console | ||
*/ | ||
|
||
include dirname( __FILE__ ) . "/google-analytics/wp-google-analytics.php"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense -- can you please update the
isModuleActivated( element[0] )
still used for wordads below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 88b2af4.