jpdevries / hits

Counts page hits of MODX Resources
6 stars 4 forks source link

if logged in as admin three hits counted #22

Open 70hundert opened 5 years ago

70hundert commented 5 years ago

Hi there!

I would like to use this extra, but I found an issue I guess:

when I'm logged to the manager and I visit a page with [[!Hits? &punch=[[*id]]]], the database amount gets incremented by 3. When not logged in it seems to be counting correct.

I also tried to use a snippet called "isAdmin" which checks if the user has admin-status or not. In this snippet I wanted [[!Hits? &punch=[[*id]]]] only get fired, when the user is not an admin/logged in:

[[!isAdmin:notempty=1:default=2[[!Hits? &punch=[[*id]]]]]]

So if a logged in admin loads a page, I get a "1" at the top of each page, if not logged in a "2". This is when the [[!Hits? &punch=[[*id]]]] should only be getting fired. But it does get fired even when logged in as admin.

I treid both ways, with the isAdmin-snippet and without - in both cases the result is the same (admin user 3 hits, non-admin user 1 hit).

Is there a possibility to edit the snippet to not count the admin-hits?

Kind regards from Germany, Marc

smg6511 commented 5 years ago

You could try writing your conditional a little differently (note the single quotes should be backticks): [[[[!isAdmin:empty='!Hits? &punch=[[*id]]']]]]

The issue you encounter with the way it was originally written is that the inner snippet is parsed before the outer conditional. Also, assuming you are using Mark Hamstra's example code for isAdmin, the return value will be boolean and so you should only need to test for empty.