The Statistics module is useful for small and medium sites. There is a need, on some sites, to add extra data. I could easily add a hook to statistics_exit to extend the data recorded in the access log and it could be a problem if someone coded their module the wrong way. Adding a post insert hook, containing the insert id, lets people extend the statistics recording in any way they like without damaging the original database row insert.

The enclosed patch lets other modules use the statistics insert id for their purposes. I am converting some modules to use this arrangement.

The alternatives include submitting this type of patch to other modules, including the Visitors module, or writing a Statistics access log module to record the statistics.

CommentFileSizeAuthor
statistics.hook_statistics_insert_id.patch1021 bytespeterx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

peterx’s picture

I ended up also adding hook_statistics_insert_fields to add the data direct to the insert because I could not stand the though of several inserts where we only need one. I am adding content type and the premium setting from Node option premium, if anyone wants the code.

timmillwood’s picture

I am not sure I understand the need for this, or the use case.
My preference would be to remove the whole access_log from the statistics module, keeping just the node_counter.

Also I don't think the patch needs the addition of:
/**
* 2012-03-16 PeterMoulding.com Allow additions to the log.
*/

peterx’s picture

@timmillwood, you are right about a patch not needing that line. The original code needs some documentation about the source. When a patch is part of an issue, placing a link to the issue in the patch would be good documentation.

Re the use case. For some sites the Statistics module records 90% of what is needed but not all that is needed. The hook would let other modules add data without having to add an extra table and an extra database insert.

One of the problems with the statistics module is the lack of expansion. When someone wants to add one extra column, they have to replace the Statistics module with a duplicate. There is a lot of duplicate development we could avoid with one extra hook.

timmillwood’s picture

I would like to see the access_log part of the statistics module removed. Alternatives would be using the API of a third-party service such as Google Analytics. I feel any expansion on the features offered by the statistics module should be done via a third-party service.

peterx’s picture

Ok, timmillwood, I understand your feeling. External services work for big sites where people have time to learn a completely different system. You could submit a feature request for that.

This issue is for people who use the Statistics module and hate having to install a whole new module to duplicate Statistics just to record one extra item, for people who hate having to log into several different systems to find out what is happening on their site.

Without Statistics or equivalent, you have to copy inaccurate statistics from Google into your Drupal based billing and reporting systems.

timmillwood’s picture

Maybe this should be moved out to contrib along with the access_log part of statistics.module?

iamEAP’s picture

This is actually the exact use-case covered by Better Statistics.

Edit: And since accesslog support is looking unlikely in D8 and this use-case is covered in contrib for D7, this can probably be closed.

Version: 7.12 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.