Mehmet
Forum Replies Created
-
Hi @taojing10,
Thanks for the follow-up questions.
There are two separate points here, and it’s important to keep them distinct.
First, why tracker.js is loading in the header.
This behavior is always controlled by code.
There is no WordPress setting that globally moves scripts from the footer to the header.
This usually happens if the script was enqueued with
$in_footer = false,or if another script depends on it and must load in the header,
or if the theme or template does not call
wp_footer().Second, how to load tracker.js only on a specific page.
If the page is a normal WordPress page and includes
wp_head()andwp_footer(),you can safely use conditionals inside
wp_enqueue_scripts.Example: load only on a page by slug.
add_action( 'wp_enqueue_scripts', 'my_enqueue_tracker_js', 11 ); function my_enqueue_tracker_js() { if ( ! is_page( 'example_page' ) ) { return; } wp_enqueue_script( 'my-tracker-js', plugin_dir_url( __FILE__ ) . 'js/tracker.js', array(), '1.0.0', true ); wp_localize_script( 'my-tracker-js', 'MyTrackerObject', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'siteUrl' => site_url(), ) ); }You can also target pages in other ways.
is_page( 123 ); // Page ID is_page( 'example-page' ); // Page slug is_page_template( 'custom.php' ); // Page template is_singular( 'post' ); // Post typeThe critical issue in your case.
If the page does not include
wp_head()andwp_footer(),WordPress cannot inject scripts at all.
This means
wp_enqueue_script,wp_localize_script,and most plugins (including WP Statistics) will not work.
Best solution: fix the template.
Add these hooks to the page template.
<head> <?php wp_head(); ?> </head> <body> ... <?php wp_footer(); ?> </body>This immediately restores compatibility with tracking and other plugins.
Last resort: manual output.
If the page is truly standalone and cannot use WP hooks,
you must manually output both the script and its configuration.
<script src="/path/to/tracker.js"></script>
<script>
var MyTrackerObject = {
ajaxUrl: "<?php echo admin_url('admin-ajax.php'); ?>",
siteUrl: "<?php echo site_url(); ?>",
option: {
dntEnabled: false,
bypassAdBlockers: false,
isPreview: false
},
hitParams: {}
};
</script>This approach bypasses WordPress and is harder to maintain.
If you’d like, you can share how
/example_pageis built(page template, custom PHP file, or plugin output),
and I can tell you exactly where the fix should go.
Best regards,
Hi @marloese1,
Since some time has passed, I’m going ahead and resolving this thread.
Feel free to reopen or post a new question anytime if needed.
Best regards,
Hi @taojing10,
Since some time has passed, I’m going ahead and resolving this thread.
Feel free to reopen or post a new question anytime if needed.
Best regards,- This reply was modified 5 months, 3 weeks ago by Mehmet.
Hi @taojing10,
Thanks for your message. The tracker.js file alone is not enough to enable tracking. This file relies on a configuration object that is passed from PHP to JavaScript usingwp_localize_script. Without this object, the tracker cannot initialize properly.
For example, to add the tracker to a specific page, you can use the following approach in yourfunctions.php:<?php
// Hook into wp_enqueue_scripts
add_action('wp_enqueue_scripts', 'my_enqueue_tracker_js', 11);
function my_enqueue_tracker_js() {
// Define your data to pass to JavaScript
$tracker_data = array(
'ajaxUrl' => admin_url('admin-ajax.php'),
'siteUrl' => site_url(),
'option' => array(
'dntEnabled' => false,
'bypassAdBlockers' => false,
'isPreview' => is_preview(),
// Add your custom options here
'customOption' => 'your_value',
),
'customParams' => array(
// Your custom parameters
'key1' => 'value1',
'key2' => 'value2',
),
);
// Dependencies (if tracker.js depends on other scripts)
$dependencies = array('jquery'); // Add any dependencies here
// Enqueue the script
wp_enqueue_script(
'my-tracker-js', // Handle
plugin_dir_url(__FILE__) . 'js/tracker.js', // Path to your tracker.js
$dependencies, // Dependencies
'1.0.0', // Version
true // Load in footer
);
// Localize script - passes data to JavaScript
wp_localize_script(
'my-tracker-js', // Same handle as above
'MyTrackerObject', // JavaScript object name
$tracker_data // The data array
);
}This ensures both the JS file and its configuration are properly loaded for that page.
For more details and a working example, you can check this link: WP Statistics FluentCommunity Tracking Example
Best regards,Hi @arifkuhudak,
At the moment, there isn’t a reliable solution to fully track FluentCommunity pages using WP Statistics. This snippet can be used, but it won’t record the actual page URLs because these pages are endpoints, not standard WordPress pages.
The best approach is to wait for official support for FluentCommunity in WP Statistics. You can still use the snippet, but please note it has limited functionality and won’t provide meaningful tracking results.
Best regards,/**
* Add WP Statistics tracking to FluentCommunity pages
* Add this to your theme's functions.php or a custom plugin
*/
add_action('fluent_community/portal_footer', 'add_wp_statistics_to_fluent_community', 99);
add_action('fluent_community/headless/footer', 'add_wp_statistics_to_fluent_community', 99);
function add_wp_statistics_to_fluent_community() {
// Check if WP Statistics is active
if (!defined('WP_STATISTICS_VERSION') || !class_exists('WP_STATISTICS\Option')) {
return;
}
// Check if cache/JS tracking mode is enabled
if (!\WP_STATISTICS\Option::get('use_cache_plugin')) {
return;
}
// Define our custom source type
$source_type = 'fluent_community';
$source_id = 0;
// Build hit params
$hitParams = [
'wp_statistics_hit' => 1,
'source_type' => $source_type,
'source_id' => $source_id,
'search_query' => '',
];
// Add signature if enabled
if (\WP_STATISTICS\Helper::isRequestSignatureEnabled()) {
$hitParams['signature'] = \WP_Statistics\Utils\Signature::generate([
$source_type,
(int) $source_id
]);
}
// Handle bypass ad blockers option
if (\WP_STATISTICS\Option::get('bypass_ad_blockers', false)) {
$requestUrl = get_site_url();
$hitParams['action'] = 'wp_statistics_hit_record';
} else {
$requestUrl = get_rest_url(null, \WP_STATISTICS\RestAPI::$namespace);
$hitParams['endpoint'] = \WP_Statistics\Api\v2\Hit::$endpoint;
}
// Build the tracker object
$jsArgs = [
'requestUrl' => $requestUrl,
'ajaxUrl' => admin_url('admin-ajax.php'),
'hitParams' => $hitParams,
'option' => [
'dntEnabled' => (bool) \WP_STATISTICS\Option::get('do_not_track'),
'bypassAdBlockers' => (bool) \WP_STATISTICS\Option::get('bypass_ad_blockers', false),
'consentIntegration' => \WP_Statistics\Service\Integrations\IntegrationHelper::getIntegrationStatus(),
'isPreview' => false,
'userOnline' => false,
'trackAnonymously' => \WP_Statistics\Service\Integrations\IntegrationHelper::shouldTrackAnonymously(),
'isWpConsentApiActive' => \WP_Statistics\Service\Integrations\IntegrationHelper::isIntegrationActive('wp_consent_api'),
'consentLevel' => \WP_STATISTICS\Option::get('consent_level_integration', 'functional'),
],
'isLegacyEventLoaded' => false,
'customEventAjaxUrl' => add_query_arg(
['action' => 'wp_statistics_custom_event', 'nonce' => wp_create_nonce('wp_statistics_custom_event')],
admin_url('admin-ajax.php')
),
];
$trackerUrl = plugins_url('wp-statistics/assets/js/tracker.js');
?>
<script id="wp-statistics-tracker-js-extra">
var WP_Statistics_Tracker_Object = <?php echo wp_json_encode($jsArgs); ?>;
</script>
<script src="<?php echo esc_url($trackerUrl); ?>?ver=<?php echo esc_attr(WP_STATISTICS_VERSION); ?>" id="wp-statistics-tracker-js"></script>
<?php
}Forum: Plugins
In reply to: [SlimStat Analytics] Slow admin after installing analyticsHi @anavato,
Thank you for your feedback and for pointing this out.
Currently, the plugin does not have a built-in feature to disable stats fetching on admin load and fetch only when opening the widget. However, I’ve forwarded this suggestion to our development team for consideration.
We appreciate your input and your patience.
Best regards,
Forum: Plugins
In reply to: [SlimStat Analytics] Filter problemHi @dtornkq550,
Apologies for the delay in updating you.
We’re currently working on fixing the bugs you mentioned, including the issue with the comparison chart always showing in Reports.
This will be part of a major upcoming update that will address many of these problems and improve the plugin overall.
Thanks for your patience and for helping us improve the plugin!
Best regards,Hi Arif,
Thank you for your message and for submitting the feature request.
We appreciate your patience and will get back to you soon with an update or possible workaround.
Best regards,
Hi @jonaldo,
Thank you so much for your kind words!
We’re glad you’re enjoying the real-time visitor tracking feature.
Best regards,Hi @arifkuhudak,
Thank you for reaching out.
I’ve checked this, and it seems that currently our scripts, like many other WordPress scripts, are not loaded on the admin-like pages of FluentCommunity. For example, the
tracker.jsfile, which is essential for tracking, is not enqueued on these pages. This is why WP Statistics does not track activity there.To request official support for FluentCommunity, you can submit a feature request here: https://feedback.veronalabs.com/boards/wp-statistics
Also, to see if a hook or workaround could enable tracking on these pages, I would need to investigate further and will get back to you once I have more details.
Best regards,
Hi @vahidpoor ,
Thank you for your message and for your interest in our plugins.
We really appreciate your support!
Best regards,Hi @taojing10,
Thanks for your message.
This notice is shown to prevent your database from growing too large and to keep your site optimized.
WP Statistics normally stores detailed visitor data such as browser, device, and location.For optimization, these details can be removed while keeping only visit and visitor counts.
You can manage this from:
Statistics → Settings → Advanced Options → Purge Old Data DailyIf you prefer to keep all detailed data, you can set this option to Never.
You can also fully delete old data from:
Statistics → Optimization → Data Cleanup → Delete Records Older ThanBefore making any changes, please make sure to take a database backup.
Let me know if you need help with the settings.
Best regards,
Hi @taojing10,
Thank you for your message.
Just to clarify, which instructions did you follow exactly?
In WP Statistics, data purging can work in two different ways.
In the first case, the data is optimized.
Only essential visit and visitor information is kept.
The summarized values are stored in the historical tables.
Unnecessary raw data is removed to optimize the database.In the second case, the data is completely deleted from the database.
Since all statistics, including total visits, are calculated directly from the database,
the result depends on which method was used.Could you please let us know which option you selected?
This will help us review the behavior more accurately.No worries, we’ll be happy to clarify everything for you once we have this detail.
Looking forward to your reply.
Hi @marloese1,
Thanks for reaching out.
The issue may be caused by a conflict with another plugin, especially one that affects caching or security.
Please start by checking this troubleshooting guide from our official documentation:
Troubleshoot the TrackerIf you find that a caching plugin is causing the problem, follow this guide to exclude WP Statistics’ tracker JS from caching or minification:
Exclude Tracker JS from CachingI look forward to your reply.
Best regards,Thank you for the update, Iain.
It happens to the best of us .htaccess can be tricky sometimes!
Glad you found the issue and everything is working now.