• Resolved Gal Baras

    (@galbaras)


    Steps:

    1. Visit CAOS admin page – shows a notice about analytics.js being missing or old
    2. Run site’s wp-cron.php
    3. Reload admin page – notice still showing

    Manually, analytics.js is downloaded and the site tracks data in GA, but the script keeps going out of date, despite running wp-cron.php every 15 minutes.

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Hi Gal,

    You’re running it through a cronjob I assume?

    If not, is it a low traffic site?

    15 minutes is quite a high interval for WP’s cron. Try lowering it to 5 minutes, or every minute even (with a filelock enabled).

    With an interval of 15 minutes, CAOS’ cron task might miss its schedule.

    Thread Starter Gal Baras

    (@galbaras)

    Dude, 15 minutes is way shorter than 2 days. In 2 days, there were 192 opportunities to update the script, but it didn’t happen.

    Also, it doesn’t happen when I run wp-cron.php manually, so the problem is not the frequency.

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Dude? Okay…

    There are other tasks that need to be finished within PHP’s max execution time, when WP cron is triggered. Not just CAOS’ task. And CAOS’ task is scheduled twice a day. Not 192 times.

    The longer the interval, the more tasks build up i.e. it might miss its schedule.

    The fact that the notice is still there, doesn’t necessarily mean the file isn’t updated. The notice is set with a transient and contains static text. It’ll expire eventually, or you can just close it.

    If analytics.js is getting outdated, it could also be that something is preventing the task to be scheduled. This could be due to the high interval, because scheduling tasks is a cron task on its own (and its simpy not getting arounnd to it). Or something else is causing it. Try installing WP Crontrol and see if CAOS’ cronjob is scheduled, it’s called something like caos_update_analytics.

    If not, add it manually using WP Crontrol. You only have to do that once. After that, you can remove WP crontrol.

    Lastly, triggering wp-cron.php manually doesn’t do anything for CAOS if CAOS’ task isn’t scheduled within that timeframe (of the last time since wp-cron.php ran)

    Hope it helps.

    Thread Starter Gal Baras

    (@galbaras)

    Daan, the interval is not missed, and when I run wp-cron.php manually, it immediately returns, so there’s nothing to do before updating analytics.js. This is not a problem of frequency or load.

    Also, I checked the file date. Yes, I’m that thorough. It’s not updating.

    Using WP Control, I saw a Stealth Mode task, but not “caos_update_analytics”, so I added it twice daily. I then ran wp-cron.php, which rescheduled the task for 12 hours later, but … didn’t update the file.

    So first, the plugin should double check that the task is there on activation, including every time it is updated.

    And second, something is still preventing the script update, but no errors in my logs.

    Is there some debug level that will get this logged?

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Hi again Gal,

    I think you’re missing a bit of understanding of how a cron schedule works. I’ll try to clarify.

    When I run wp-cron.php manually, it immediately returns, so there’s nothing to do before updating analytics.js

    If the task is not scheduled within the timeframe since the last time it ran, it makes sense that the update didn’t run. Again, it’s scheduled twice a day, and it’s not like it’ll run tasks ahead of schedule if it has nothing else to do.

    Using WP Crontrol […] I added it twice daily. I then ran wp-cron.php, which rescheduled the task for 12 hours later, but … didn’t update the file.

    That’s great! That means that now the task will run twice daily. But again, just running wp-cron.php doesn’t mean that it’ll update it immediately. What happens if you run the specific task in WP Crontrol? Is the file updated then?

    You can trigger the specific cron task in Tools > Cron Events: https://imgur.com/a/pmAorkL

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Ah, btw. The cron task is called caos_update_analytics_js. Could you try adding that using WP Crontrol?

    Thread Starter Gal Baras

    (@galbaras)

    I think you’re missing a bit of understanding of how a cron schedule works. I’ll try to clarify.

    I understand very well that if a task’s schedule has already passed, the next cron run will execute it.

    Unlike caos_update_analytics, which didn’t have an action, caos_update_analytics_js has one. It didn’t update the file when scheduled “now”, but when I ran it manually, the file was updated.

    I think we’re good now.

    Back to the plugin, I think it should ensure that the correct task is scheduled, and schedule it if it isn’t. Can you please add this to the plugin’s activation (I’m assuming this is now only done on registration)?

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Hi Gal,

    Apologies for the late response. Our daughter was born the 9th of July! So, I kind of had my hands full the past weeks. 🙂

    This is already present in the code. I don’t know, why on some instances it doesn’t add the cronjob. It happens occasionally. I had it myself once while developing a site.

    I’ll dive into this at a later date.

    Thread Starter Gal Baras

    (@galbaras)

    Wow, congratulations, man! Look at your code when you’ve had enough sleep 😀

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘analytics.js not updated by running wp-cron.php’ is closed to new replies.