Calculate formula only on page load

I would like to have a formula on each page that is calculated only on page (not doc) load. If the user views page 1, the formula will calculate once. When the user views page 2, the formula will calculate once. When the user views page 1 again, the formula will calculate once, and so on…

Can this be done?

Can you give a more thorough example including your use case?

Coda is so flexible that there are always many ways of accomplishing what you are trying to do but its hard to point you in the right direction without a more fleshed out example including the use-case at hand

Sure. I’m trying to capture usage logs for my internal portal doc. My original plan was Run custom js on doc load for usage logging. Since that doesn’t seem viable, I made a custom pack with a formula that accepts a user email and a url as parameters and sends them to a webhook. My goal is have to formula calculate once per page view so I can record the page views. I only want the formula to calculate for the page the user is viewing, and only once per page view.

Not sure if you’re aware but there is a doc/pack for collecting doc views and performance

The “Doc List Pack”

Thanks Jake.

I looked at that, but my goal is to track usage by user. It seems that even with an enterprise plan this isn’t available.

I created a pack formula and used now() as one of the input to refresh it, but it’s having 2 issues. First, it’s refreshing on every page, not just the page being viewed. Second, even though the timer is set to seconds granularity, it’s only updating approx every 30 seconds.

Is there a way to know if the page is currently being viewed by the user? Or better yet which page is currently being viewed by the user?

You could try something with images or embeds. Those usually load lazily only when brought into view. You could build your own backend for tracking when an embed or an image (with an ephemeral URL, e.g. a query param that changes with time, to prevent caching) is loaded.

Hi Paul,

Thanks for the idea. This is one step closer. Adding the time variable to prevent caching is great. Now the embed is being refreshed once per second while the page is being shown. Do you know if there’s a way to make the now() formula only refresh on page load?

Alternatively, do you know if there is support for caching specific values for use in formulas? For example, if I could cache the last page viewed for the user, I could compare the current page being recorded to see if a new function call is needed. I’m sure it would be cleaner to do this in a pack formula, but I can’t seem to get the pack formulas to only update for the page the user is currently viewing.