Jump to content

Howto call/run a function in cached pages?


Torsten Baldes
 Share

Recommended Posts

Hi,

i want to build a simple tracking system, where i can see how the users navigate through my site.

Right now i insert a row in a custom db-table with a unique id, the page a user visits, the page the user came and a timestamp. I do this with a after-hook to »ProcessPageView:finished«, which is setup in an _init.php template which is prepend to any other template.

This works fine.

The problem is that this doesn't work on cached templates/pages.

How can I use the template-cache-feature AND update my db-table via this hook or any other technique?

Thanks!

Link to comment
Share on other sites

Yes, I thought about ajax, but I do not like the detour. This way i have to send all the needed data (page-id, referer, action, submitted form etc.) via ajax.

I hoped for a better way (e.g. a hook, which get's called regardless of cache) to do this.

Is there a better way to setup this hook, instead if doing this in a template?

Link to comment
Share on other sites

Such calls should never been put in the init.php (well you have to be careful). If you use render inside your template to render partials for example the init will get called each time.

Anyway you should add your hook in a autoload module. See HelloWorld.module.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...