No. of Page Views

12 posts by 4 authors in: Forums > CMS Builder
Last Post: January 7, 2010   (RSS)

Is it possible to display the number of times a particular page or a listing has been viewed using CMS builder? Example: This ad has been viewed "X" times.

Re: [WEVOLUTIONS] No. of Page Views

By Chris - December 10, 2009

Hi WEVOLUTIONS,

Please see this forum post:

[url http://www.interactivetools.com/forum/gforum.cgi?post=63132;search_string=hit%20count;#63132]http://www.interactivetools.com/forum/gforum.cgi?post=63132;search_string=hit%20count;#63132[url]
All the best,
Chris

Re: [WEVOLUTIONS] No. of Page Views

By gkornbluth - December 15, 2009 - edited: December 16, 2009

Hi Wevolutions,

Thanks to the addition of a function built into recent versions of CMS Builder called: incrementCounterField, you can implement a counter much more easily.

Here's an excerpt from my latest edition of The CMSB Cookbook that describes how to do it.

CREATING A HIT COUNTER USING THE BUILT IN incrementCounterField FUNCTION
Using the built in incrementCounterField function, you can create a hit counter for a single record editor or a detail page of a multi record editor like this:

In the section editor, create a field called 'hits' (or whatever you want to call it). Then insert this code on your viewer page.

<?php incrementCounterField('your_table_name', 'your_field_name', $your_table_nameRecord['num']); ?>

Or if you don’t want the counter to be incremented when the page is accessed by a particular IP Address (yours for example), try Chris’s recommendation:

<?php if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') { incrementCounterField('your_table_name', 'your_field_name', $your_tableRecord['num']); } ?>

Wherever on the viewer that you want to display the number of hits, insert this code as you would for any other field.

<?php echo $your_table_name['your_field_name '] ?>

LIST PAGE IMPLEMENTATION
For a counter on the list page of a multi-record editor, the process gets a bit more complex. This is because if you used the approach above in a “foreach” loop, all the counters on all your records would increment each time the list page was accessed.

So, first create a table called “Counter” or something similar.

Create a text field in that table for each list page that you want to count. Name the fields something that will be meaningful, preferably with the same name as the editor where you’ll be implementing the count.

Insert the record call to that table at the top of your viewer:

list($counterRecords, $counterMetaData) = getRecords(array(
'tableName' => 'counter',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$counterRecord = @$counterRecords[0]; // get first record


Then insert:<?php incrementCounterField('counter', 'your_field_name', $'counter Record['num']); ?>

Or again, if you don’t want the counter to be incremented when the page is accessed by a particular IP Address (yours for example), try this version of Chris’s recommendation:

<?php if ($_SERVER['REMOTE_ADDR'] != '127.0.0.1') { incrementCounterField(‘counter', 'your_field_name', $counterRecord['num']); } ?>

Into your viewer and:

<?php echo $counter['your_field_name '] ?>

Where you want the counter to appear.

As an added plus, you can enter any starting number in any of the counter fields and the count will begin from there, so none of your pages need to show only a small number of hits.

Hope that helps,

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] No. of Page Views

Will this work for CMS Builder v1.22?

If not can I upgrade to the latest version?

And will this upgrade affect my current listings because I have over 1000 listings that cannot be interfered with.

Re: [WEVOLUTIONS] No. of Page Views

Not sure about 1.22 but if you haven't upgraded recently, there are lots of great improvements available in the newer versions. Check the change logs to see what they are and if they'll affect your current design.
http://www.interactivetools.com/upgrade/changelog.php#cmsbuilder

For peace of mind, I 'd mock up the new section editor and viewer to play with the concept before implementing it in your existing editor.

The call increments the count in a totally new text field that you create just for that purpose, so it doesn't affect existing fields or data.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] No. of Page Views

Thank you very much. Counter works great. Just as I wanted.

Re: [gkornbluth] No. of Page Views

By Codee - December 31, 2009 - edited: January 5, 2010

Question on this details page counter solution:

Can the counter be set to ONLY show to the record owner (and admin of course)...for example, in a classifieds listing site, the lister knows how many people have visited that ad but the public doesn't? Also, can one be set to show a total of all visits to all the items listed by a person?

Thanks

Re: [equinox69] No. of Page Views

I think so.

I just got the web site membership plugin and it talks about the ability to view a certain code on a page only after user login, using: <?php if (current_user): ?>
only logged in user will see this...
<? php endif ?>


I haven't played with it yet, but it seems that this, along with the user access set to author for that section only might be a direction to explore.

Best,

Happy New Year

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] No. of Page Views

Hi,

Well, this approach almost works. The call does not seem to be "author" sensitive, however I did find a workaround.

You can set up a separate (text or check box) field in the user accounts editor and assign it a value for that particular class of users. Then test with:

<?php if ($CURRENT_USER['your_field'] == "your_value"): ?>Current user will be able to see this<?php endif ?>

Only user(s) who have that value entered/selected in their user record will be able to view the protected information on the web page.

Maybe one of the IT gurus can tell us how to accomplish displaying fields to only a current user who is also the author of a record (or admin).

Til then....

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php