Closed 1BJK903 closed 4 years ago
Hi there,
What does that file do?
Why is this happening?
This JS file is keeping track of page views.
It's only a few bytes in size, yes, but it also sends a POST
request to the server asking it to register the current page view to the database.
The loading time you're seeing here is how long it takes the browser to load and parse the JS file itself (and since the file is quite small this should happen almost instantly) + the time it takes your server to process the AJAX request.
Can we remove it from certain pages (like dequeuing?)? If so, how?
No, there's no way to do this at the moment (that I know of that works reliably at least.)
Maybe this question is better: can we, by default, exclude all pages to track? I only want my posts to be tracked and not my pages.
Yes, you can: wpp_trackable_post_types.
Hi Hector,
Thank you for the fast response. This is clear and it helps! Will there be an option coming later on to disable pages by default?
Anyhow, last question:
/**
* Have WPP track only 'post' and 'review' post types page views, ignore the rest.
*
* @param array $post_types
* @return array
*/
function my_trackable_post_types($post_types){
$track_these_post_types_only = array('post', 'review');
return $track_these_post_types_only;
}
add_filter('wpp_trackable_post_types', 'my_trackable_post_types', 10, 1);
So this is for post types. But I just want the default page type. Can I use this snippet for that as well? Can you give an example?
Thank you for the fast response. This is clear and it helps!
Don't mention it. Glad I could help!
Will there be an option coming later on to disable pages by default?
No need. Read below why.
So this is for post types. But I just want the default page type.
I think you're a bit confused here. The default post types WordPress includes are:
(More details here.)
By "default page type" I assume you're talking about posts here. So, based on what you mentioned on your previous comment, if you want WPP to only track posts and not pages (nor other post types) then that's what this filter hook is for.
Here's how you should use it so WPP only keeps track of posts:
/**
* Have WPP track only posts, ignore the rest (pages, attachments, custom post types, etc.)
*
* @param array $post_types
* @return array
*/
function my_trackable_post_types($post_types){
// Here is where you specify which post type(s) to track:
$track_these_post_types_only = array('post');
return $track_these_post_types_only;
}
add_filter('wpp_trackable_post_types', 'my_trackable_post_types', 10, 1);
Hope that clarifies things a bit.
Hi Hector, thanks again. Maybe I wasn't clear enough, but I actually wanted to remove the plugin from tracking pages (like Contact, etc.). It is there now and I want to get rid of all non-single-posts, if that makes sense.
Can I use the snippet for that as well?
Ah, well, that code snippet asks WPP not to track views unless it's a single post. The JS file will still be loaded though but it won't send a POST
request to the server unless we're viewing a single post.
Does that make sense or do you need more details?
I understand and that is exactly where I was at this moment haha. The next step for me would be: how can I make sure it's not even loaded on the page when it's not a single post? As you have seen, it was causing a 1.3 second delay for me, while there is nothing to track on that page....
So I could use your help there.
That doesn't sound right. The script doesn't do anything unless it's executed by WPP when certain conditions are met (the current page is trackable, or there's a WPP widget on the page using it, etc.)
I'd do some testing but I'm busy at the moment (I work as a full-time remote developer so the quarantine doesn't really affect me). I'll get back to you once I find some spare time for this.
What's your site's URL, by the way?
Alright, so I'm testing the code snippet now and it's working as intended for me.
Without the code snippet:
WPP is tracking everything - including pages, which is the default behavior.
Here's what the Network inspector shows when I visit my About page (I'm displaying only AJAX requests here for simplicity):
With the code snippet:
Now with the code snippet in place, here's what my Network inspector shows when I visit my About page:
The plugin is no longer sending POST
requests even though the JS file is still being loaded by the browser when visiting my About page:
If you're seeing a different behavior then my guess is that you either placed the code snippet on the wrong place and it is not being run at all or that you have a caching system in place (WP Super Cache, Varnish, etc) and forgot to clear the cache after adding the code snippet to your site.
Closing issue due to inactivity.
Hello there,
First of all, thank you for the nice plugin. It works great. I have thought of adding a bug here or simply removing the plugin, as I didn't know if there would be a solution or not, but let's try. I like the app, so I want to keep it.
Here is my issue. https://ibb.co/xjrrVDy
As you can see, it's a file (?) that is 620 bites, but it takes more than 1.3 seconds to load. This is not cool regarding performance.
I have a couple of questions: 1) Why is this happening? 2) What does that file do? Guessing it's tracking the clicks, right? Because I am not outputting any widget or whatsoever in the front-end. 3) Can we remove it from certain pages (like dequeuing?)? If so, how? 4) Maybe this question is better: can we, by default, exclude all pages to track? I only want my posts to be tracked and not my pages.
Thanks in advance for your answer.