Skip to content
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

Move the tracking setting to the general setting tab #978

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1292,30 +1292,4 @@ private function add_account_vk( $data ) {

return $this->response->to_array();
}

/**
* API method called to toggle tracking.
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically.
*
* @param array $data The data from request.
* @return array The response.
*/
private function toggle_tracking( $data ) {
if ( ! isset( $data['tracking'] ) ) {
$this->response->set_code( '400' )
->set_message( 'Tracking data not found' )
->set_data( array() );

return $this->response->to_array();
}

$tracking = filter_var( $data['tracking'], FILTER_VALIDATE_BOOLEAN );
update_option( 'tweet_old_post_logger_flag', $tracking ? 'yes' : 'no' );

return $this->response->set_code( '200' )
->set_message( 'OK' )
->set_data( array( 'tracking' => $tracking ) )
->to_array();
}
}
3 changes: 3 additions & 0 deletions includes/admin/models/class-rop-settings-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ public function get_settings( $include_dynamic = false ) {
self::$shorteners
);
}
if ( ! isset( $this->settings['tracking'] ) ) {
$this->settings['tracking'] = 'yes' === get_option( 'tweet_old_post_logger_flag', 'no' );
}

return $this->settings;
}
Expand Down
5 changes: 3 additions & 2 deletions includes/class-rop-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public static function get_labels( $key = '' ) {
'exclude_single_post' => __( 'Exclude this post', 'tweet-old-post' ),
'no_posts_found' => __( 'No posts found.', 'tweet-old-post' ),
'load_more_posts' => __( 'Load more posts.', 'tweet-old-post' ),
'tracking_field' => __( 'Contributing', 'tweet-old-post' ),
'tracking' => __( 'Send anonymous data to help us understand how you use the plugin.', 'tweet-old-post' ),
'tracking_info' => __( 'What do we track?', 'tweet-old-post' ),
),
'post_format' => array(
'yes_text' => __( 'Yes', 'tweet-old-post' ),
Expand Down Expand Up @@ -343,8 +346,6 @@ public static function get_labels( $key = '' ) {
'to' => __( 'to', 'tweet-old-post' ),
'by' => __( 'by', 'tweet-old-post' ),
'review_it' => __( 'Leave a review', 'tweet-old-post' ),
'tracking' => __( 'Send anonymous data to help us understand how you use the plugin.', 'tweet-old-post' ),
'tracking_info' => __( 'What do we track?', 'tweet-old-post' ), 'global_settings_header' => __( 'Global Settings', 'tweet-old-post' ),
'in' => __( 'in', 'tweet-old-post' ),
'start' => __( 'Start', 'tweet-old-post' ),
'stop' => __( 'Stop', 'tweet-old-post' ),
Expand Down
52 changes: 0 additions & 52 deletions vue/src/vue-elements/main-page-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,6 @@
target="_blank"
class="btn rop-sidebar-action-btns"
>{{ labels.review_it }}</a>
<div class="rop-tracking-box">
<h5>{{ labels.global_settings_header }}</h5>
<div class="rop-tracking-item">
<label
class="form-checkbox"
>
<input
v-model="tracking"
type="checkbox"
name="rop-tracking"
@change="toggle_tracking()"
>
<i class="form-icon" />
{{ labels.tracking }}
<a
:href="tracking_info_link"
target="_blank"
>
{{ labels.tracking_info }}
</a>
</label>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -250,8 +227,6 @@
is_loading: false,
is_loading_logs: false,
status_is_error_display: false,
tracking: this.$store.state.tracking,
tracking_info_link: ropApiSettings.tracking_info_link
}
},
computed: {
Expand Down Expand Up @@ -478,23 +453,6 @@
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
this.is_loading_logs = false;
})
},

/**
* Toggle tracking from SDK (via tiTrk).
*/
toggle_tracking() {
this.$log.info('Toggling tracking');
this.$store.dispatch('fetchAJAXPromise', {
req: 'toggle_tracking',
data: { tracking: Boolean( this.tracking) }
}).then(response => {
// Update tracking state.
this.$store.commit('updateState', {stateData: {tracking: Boolean( response?.tracking)}, requestName: 'toggle_tracking'});
this.$log.info('Succesfully toggled tracking.');
}, error => {
Vue.$log.error('Got nothing from server. Prompt user to check internet connection and try again', error)
})
}
}
}
Expand All @@ -519,14 +477,4 @@
#rop_core .badge.badge-logs {
padding-right: 10px;
}

.rop-tracking-box {
display: flex;
flex-direction: column;
gap: 8px;

padding: 0.25rem 0.4rem;
border: 0.05rem solid #042440;
border-radius: 0.1rem;
}
</style>
33 changes: 32 additions & 1 deletion vue/src/vue-elements/settings-tab-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,34 @@
</div>
</div>
</div>
<span class="divider" />

<!-- tracking -->
<div class="columns py-2">
<div class="column col-6 col-sm-12 vertical-align rop-control">
<b>{{ labels.tracking_field }}</b>
<p class="text-gray">
{{ labels.tracking }}<br>
<a
:href="tracking_info_link"
target="_blank"
>
{{ labels.tracking_info }}
</a>
</p>
</div>
<div class="column col-6 col-sm-12 vertical-align text-left rop-control">
<div class="form-group">
<label class="form-checkbox">
<input
v-model="generalSettings.tracking"
type="checkbox"
>
<i class="form-icon" />{{ labels.yes_text }}
</label>
</div>
</div>
</div>
</div>
</div>
<div class="panel-footer text-right">
Expand Down Expand Up @@ -616,7 +644,9 @@
*/
rop_cron_remote: Boolean(ropApiSettings.rop_cron_remote),
rop_cron_remote_agreement: Boolean(ropApiSettings.rop_cron_remote_agreement),
is_cron_btn_active: false
is_cron_btn_active: false,
tracking: this.$store.state.tracking,
tracking_info_link: ropApiSettings.tracking_info_link
}
},
computed: {
Expand Down Expand Up @@ -813,6 +843,7 @@
instant_share_future_scheduled: this.generalSettings.instant_share_future_scheduled,
instant_share_choose_accounts_manually: this.generalSettings.instant_share_choose_accounts_manually,
housekeeping: this.generalSettings.housekeeping,
tracking: this.generalSettings.tracking
};

this.$store.dispatch('fetchAJAXPromise', {
Expand Down
Loading