Skip to content

Commit

Permalink
fix: also create the stats API endpoint for no-JS tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Brinkmann authored and stklcode committed Sep 22, 2023
1 parent 9e65129 commit 69d015a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 12 additions & 10 deletions inc/class-statify-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ class Statify_Api extends Statify {
* @return void
*/
public static function init() {
register_rest_route(
self::REST_NAMESPACE,
self::REST_ROUTE_TRACK,
array(
'methods' => WP_REST_Server::CREATABLE,
'accept_json' => true,
'callback' => array( __CLASS__, 'track_visit' ),
'permission_callback' => '__return_true',
)
);
if ( Statify::is_javascript_tracking_enabled() ) {
register_rest_route(
self::REST_NAMESPACE,
self::REST_ROUTE_TRACK,
array(
'methods' => WP_REST_Server::CREATABLE,
'accept_json' => true,
'callback' => array( __CLASS__, 'track_visit' ),
'permission_callback' => '__return_true',
)
);
}

register_rest_route(
self::REST_NAMESPACE,
Expand Down
4 changes: 1 addition & 3 deletions inc/class-statify.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ public static function init() {
add_filter( 'amp_post_template_analytics', array( 'Statify_Frontend', 'amp_post_template_analytics' ) );
}
// Initialize REST API.
if ( self::is_javascript_tracking_enabled() ) {
add_filter( 'rest_api_init', array( 'Statify_Api', 'init' ) );
}
add_filter( 'rest_api_init', array( 'Statify_Api', 'init' ) );
}
}

Expand Down

0 comments on commit 69d015a

Please sign in to comment.