Excluding own pageviews
-
Hi there!
Just a question to be sure:when using the code (adapted with my IP-address) from
https://www.kokoanalytics.com/kb/exclude-pageviews-from-certain-ip-addresses/
in the Code Snippets plugin and activating it there – will that be sufficient?Thanks and greetings,
adThe page I need help with: [log in to see the link]
-
Hello @nudnavda,
There is a setting for excluding IP addresses nowadays, so that you don’t have to use the filter hook anymore.
There is also a setting for excluding certain logged-in user roles, which may be useful as well.
If you combine these settings, then most of your visits won’t be counted anymore except for the ones made from a mobile network (because you’ll have a different IP address) unless you’re logged into your WordPress site.Hope that clarifies.
DannyGreat – thanks for the direct reply!
Best wishes,
adHi Danny,
After adjusting the settings in Koko plugin, I wonder if the settings page could be extended by adding an extra option: The publicly accessible version is only accessible for this(these) IP address(es)…
It feels somewhat awkward to just publically use the Koko dashboard address.Hope this simple question would not involve too much brain crushing work 😉
Or maybe there’s a simple (but secure) plugin that takes care of this.Excuses if this suggestion should be posted elsewhere.
Thanks for your commitment!Greetings,
adHello @nudnavda,
I am not sure I follow – are you talking about the setting to make your dashboard publicly available? That is not related to your earlier question in this topic though, or am I misunderstanding?
In any case, if you do not want your Koko Analytics dashboard to be publicly accessible then I would not use this setting and simply hide it behind your WP admin login (the default behavior).
There are probably plugins that allow you to hide certain URL’s and only make them accessible from certain IP addresses, but I am afraid that I have no recommendations in that area.
Best, DannyYes, I understand.
Found a plugin that does this.Thanks,
adHi Danny,
sorry for continuing this thread – I think it is indeed related to my initial question.
And the plugins I found did not help in this specific case.
I’ll try to explain.Koko uses an url for standalone view: https://YOUR-DOMAIN/?koko-analytics-dashboard=1
This is a useful option which can be viewed (or not) publicly.
It would be nice to have an option to restrict the viewing to my own IP-address.
So my question was: would this be possible?On Stackexchange I found the following code (but I’m afraid it only works for pages, not for a query like your settings page url):
function page_ip_restriction() {
if(is_page('yourpage'))
{
// Whitelist
$whitelist = array(
'x.x.x.x',
);
// Check if current user IP is out of the whitelist, then redirect to home
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist))
{
wp_redirect(home_url(), 403); // 403 -> Forbiden access
exit();
}
}
}
add_action('init', 'page_ip_restriction', 10);Maybe this illustrates what I’m looking for.
Hope it’s not too much of a hassle ;-(
Thanks again!Hello @nudnavda,
No worries – you can use something like this:
function page_ip_restriction() {
if (isset($_GET['koko-analytics-dashboard']))
{
// Whitelist
$whitelist = array(
'x.x.x.x',
);
// Check if current user IP is out of the whitelist, then redirect to home
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist))
{
wp_redirect(home_url());
exit();
}
}
}
add_action('init', 'page_ip_restriction', 10);Hope that helps. Good luck!
-
This reply was modified 1 year, 11 months ago by
Danny van Kooten. Reason: Remove 403 status code - unsure if it works with HTTP redirects
👍 Thanks for following up and completing this functionality!
A reassuring addition.Best wishes,
adHi Danny, I’m afraid I’ve been premature in my enthousisam.
Things don’t work out the way we intended, it seems:1 – I adjusted the IP-address in the script (see above).
2 – Installed the code in my regular Snippets plugin, and activated it.
3 – Activated on my desktop Proton VP to change IP address
4 – Purged caches (WP admin, local Chrome)
5 – Public version of Koko-analytics appears in Chrome (in stead of homepage).Now, I don’t know if you want to further investigate.
If so, I can mail you a screenshot of the Koko settings, showing the two different IP addresses: the one excluded from analysing, and the actual Vpn address.Please let me know.
Thanks and greetings,
adWell, it’s a pity.
I have reverted the Koko-settings to non-public viewing.
Would be great if you find a way to implement the above feature in a next upgrade.Thanks and best wishes,
ad -
This reply was modified 1 year, 11 months ago by
The topic ‘Excluding own pageviews’ is closed to new replies.