External link hit counter

106 views
Skip to first unread message

Yury Lifshits

unread,
Aug 31, 2008, 9:00:09 PM8/31/08
to Django users
Dear All,

How can one implement a hit counter for external link in Django?
I am coding a directory of companies [ it's in Russian, http://shopping2.ru/business
].
Every company profile has an external link to company's website.
I want to display a number of times this link was clicked.

The link should be direct, not like /counter?serve=http://
company.com

Of course, I just add an integer field "clickcounter" in company
model. So the display part is easy.
The question is how to "catch" the click event. I know there is
"onclick" attribute and some javascript code can be called there.

Are there few lines of javascript that will send an "update counter"
message to django, while user is walking to an external website?

Thanks,
Yury.

P.S. I've found http://code.google.com/p/django-simplestats/ but it is
a general statistics engine while I only need a thing described above.

Steve Potter

unread,
Aug 31, 2008, 11:33:32 PM8/31/08
to Django users
Your best bet would be to achieve this using Ajax. Check out these
basic tutorials:

http://www.b-list.org/weblog/2006/jul/31/django-tips-simple-ajax-example-part-1/
http://www.b-list.org/weblog/2006/aug/05/django-tips-simple-ajax-example-part-2/

Steve


On Aug 31, 8:00 pm, Yury Lifshits <yury...@gmail.com> wrote:
> Dear All,
>
> How can one implement a hit counter for external link in Django?
> I am coding a directory of companies [ it's in Russian,http://shopping2.ru/business
> ].
> Every company profile has an external link to company's website.
> I want to display a number of times this link was clicked.
>
> The link should be direct, not like   /counter?serve=http://
> company.com
>
> Of course, I just add an integer field "clickcounter" in company
> model. So the display part is easy.
> The question is how to "catch" the click event. I know there is
> "onclick" attribute and some javascript code can be called there.
>
> Are there few lines of javascript that will send an "update counter"
> message to django, while user is walking to an external website?
>
> Thanks,
> Yury.
>
> P.S. I've foundhttp://code.google.com/p/django-simplestats/but it is

Yury Lifshits

unread,
Aug 31, 2008, 11:57:58 PM8/31/08
to Django users
Steve,

Thanks for the links!
I will study the tutorial and will try to apply it for my problem.
Looks promising.

Yury.
Reply all
Reply to author
Forward
0 new messages