0

I am a Python beginner working on a very basic real-time analytics tool using Python and MongoDB. I have a function that updates a collection of URLs and pageviews stored in MongoDB:

def track(url):
   hour = datetime.utcnow().replace(minute = 0, second = 0, microsecond = 0)
   db.hourly.update({"hour": hour, "url":url}, {"$inc": {"views": 1}}, upsert = True)
   db.hourly_totals.update({"hour": hour}, {"$inc": {"views": 1}}, upsert = True)

Whenever track gets executed for a given URL, the collection of documents gets updated accordingly with pageviews for each URL incremented for collection "hourly", and total pageviews for all urls incremented for collection "hourly_totals".

What is the best way to automate this process such that track gets executed every time somebody visits a page on my website? Could I do this in Python or do I have to embed this in a Javascript tag?

1 Answer 1

1

You can place javascript (JQuery) code (in document.ready() method) which makes a call to a web service which in turn executes this track method. If you just want a simple web server for your webservice, use bottle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.