WordPress.org

Forums

How to exclude jetpack stats module from rocketloader of cloudflare (10 posts)

  1. jayantkumar.iitr
    Member
    Posted 1 year ago #

    I want to change the script type of Jetpack stats from "text/rocketscript" to "text/javascript"so that it would work correctly. I found the stats.php in wp-contents/plugins/jetpack/modules but i can't change the script in there(there is no javascript in there) and i can't find which function is calling stats.php in the page source.

    Please help me in this case.

    Thanks

    URL: http://jackguide.com

  2. Brad
    Member
    Posted 1 year ago #

    I am not sure this will work or not, but try this, and please report back.

    1. Log into CloudFlare, and select the drop down for the domain JackGuide.com.

    2. Select "Page Rules". Then look for "Add New Rule".

    For the URL pattern, use the exact address to that folder followed my an asterisk to wildcard that entire folder.

    URL pattern should be something like:

    http://jackguide.com/wp-contents/plugins/jetpack/modules/*

    3. Click the Performance dropdown and select "Off". This will disable RocketLoader and any other optimization or minification options for files under this entire folder.

    4. Select "Add Rule". I like to then purge the entire cache and also purge any caching plugins you may have installed on your WordPress site. Don't forget to also clear your browser cache as well.

  3. jayantkumar.iitr
    Member
    Posted 1 year ago #

    Thanks, i tried that but i didn't off the performance option. i inserted as
    *jackguide.com/wp-contents/plugins/jetpack/*

    and turned off the rocket loader. Even after that there was a huge difference between analytics and WP stats. Normally, it is between 100-200. but with rocket loader, it is more than 1000.

    I viewed the page source in chrome and i see this code:

    view-source:http://jackguide.com/

    Last function

  4. Brad
    Member
    Posted 1 year ago #

    When using CloudFlare, there will be a huge difference between on-server analytics and CloudFlare's or 3rd parties since not all hosts utilize mod_cloudflare in their server setup which allows the origin server to see the IP address of the requester through CloudFlare.

    This is because CloudFlare acts as a reverse proxy and your server does not see all clients connecting to it, since they only connect to CloudFlare, and CloudFlare connects to your server.

    I would suggest using a 3rd party analytics provider for accurate stats.

  5. Brad
    Member
    Posted 1 year ago #

    If Page Rules did not work, you may have to disable RocketLoader on your entire site.

  6. jayantkumar.iitr
    Member
    Posted 1 year ago #

    I am using google analytics for stats but actually WPstats was an inbuilt function within the dashboard so it was quite handy.

    Google analytics code too wasn't working properly after activating rocket loader but i excluded it by adding this:

    <script data-cfasync="false" type="text/javascript">
    ---analytics code---
    </script>

    so, if there is a way to change the wp stats code in a similar way?

    Thanks :)

  7. Brad
    Member
    Posted 1 year ago #

    There may be if you can find that function in the plugin PHP code, but that is above the support of most at this help desk.

    Try looking in the plugin PHP files for something similar to:

    <script type=“text/javascript”> and replace it with <script data-cfasync="false" type="text/javascript">

    That should continue to work until you update the plugin.

  8. jayantkumar.iitr
    Member
    Posted 1 year ago #

    Thanks, i will try it out if i find it by any chance (trying since hours :))

  9. jayantkumar.iitr
    Member
    Posted 1 year ago #

    Solution for the problem if anyone looking for this:

    Login to wordpress dashboard>Plugins>editor.

    Now click drop down menu after "Select plugin to edit" and select "jetpack by wordpress". click select.

    Now, scroll down and click "jetpack/modules/stats.php"

    Scroll down in the editor window and look for the function something like this:

    <script src="http://stats.wordpress.com/*****.js" type="text/javascript"></script>
    <script type="text/javascript">
    {function here}
    </script>

    Add "data-cfasync="false" after script so that it would look something like this:

    <script "data-cfasync="false" src="http://stats.wordpress.com/*****.js" type="text/javascript"></script>
    <script "data-cfasync="false" type="text/javascript">
    {function here}
    </script>

    Click "update" to update the file and now, rocket loader is off for jetpack stats code.

    Hope it helps someone.

  10. jayantkumar.iitr
    Member
    Posted 1 year ago #

    Make sure to repeat the steps after the plugin update.

Topic Closed

This topic has been closed to new replies.

About this Topic