Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4260454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:55:19+00:00 2026-05-21T05:55:19+00:00

I want to save everything that can be used for statistics, such as referrer,

  • 0

I want to save everything that can be used for statistics, such as referrer, os, browser etc. What is available and what’s the best way to store it?

This is only important for 1 application (1 page) in the project, the other pages some standard analytics product will be used such as google analytics.

I had a look at django-tracking, but it seems this is overkill as I only want to use it on 1 view. The ideal situation would be, passing the whole request object to a TaskQue and do the processing later. So the user is redirected first and the analytics processing will be done behind the scenes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:55:20+00:00Added an answer on May 21, 2026 at 5:55 am

    We use some simple middleware.. below is an excerpt. You can modify it to use directly within a view.

    class WebRequest(models.Model):
        time = models.DateTimeField(auto_now_add=True)
        host = models.CharField(max_length=1000)
        path = models.CharField(max_length=1000)
        method = models.CharField(max_length=50)
        uri = models.CharField(max_length=2000)
        status_code = models.IntegerField()
        user_agent = models.CharField(max_length=1000,blank=True,null=True)
        remote_addr = models.IPAddressField()
        remote_addr_fwd = models.IPAddressField(blank=True,null=True)
        meta = models.TextField()
        cookies = models.TextField(blank=True,null=True)
        get = models.TextField(blank=True,null=True)
        post = models.TextField(blank=True,null=True)
        raw_post = models.TextField(blank=True,null=True)
        is_secure = models.BooleanField()
        is_ajax = models.BooleanField()
        user = models.ForeignKey(User,blank=True,null=True)
    
    def dumps(value):
        return json.dumps(value,default=lambda o:None)
    
    class WebRequestMiddleware(object):
        def process_view(self, request, view_func, view_args, view_kwargs):
            setattr(request,'hide_post',view_kwargs.pop('hide_post',False))
    
    
        def process_response(self, request, response):
    
            if request.path.endswith('/favicon.ico'):
                return response
    
            if type(response) == HttpResponsePermanentRedirect and settings.APPEND_SLASH:
                new_location = response.get('location',None)
                content_length = response.get('content-length',None)
    
                if new_location and content_length is '0':
                    new_parsed = urlparse(new_location)
    
                    old = (('http','https')[request.is_secure()], request.get_host(), '{0}/'.format(request.path), request.META['QUERY_STRING'])
                    new = (new_parsed.scheme, new_parsed.netloc, new_parsed.path, new_parsed.query)
    
                    if old == new:
                        #dont log - it's just adding a /
                        return response
            try:
                self.save(request, response)
            except Exception as e:
                print >> sys.stderr, "Error saving request log", e
    
            return response
    
        def save(self, request, response):
            if hasattr(request, 'user'):
                user = request.user if type(request.user) == User else None
            else:
                user = None
    
            meta = request.META.copy()
            meta.pop('QUERY_STRING',None)
            meta.pop('HTTP_COOKIE',None)
            remote_addr_fwd = None
    
            if 'HTTP_X_FORWARDED_FOR' in meta:
                remote_addr_fwd = meta['HTTP_X_FORWARDED_FOR'].split(",")[0].strip()
                if remote_addr_fwd == meta['HTTP_X_FORWARDED_FOR']:
                    meta.pop('HTTP_X_FORWARDED_FOR')
    
            post = None
            uri = request.build_absolute_uri()
            if request.POST and uri != '/login/':
                post = dumps(request.POST)
    
            models.WebRequest(
                host = request.get_host(),
                path = request.path,
                method = request.method,
                uri = request.build_absolute_uri(),
                status_code = response.status_code,
                user_agent = meta.pop('HTTP_USER_AGENT',None),
                remote_addr = meta.pop('REMOTE_ADDR',None),
                remote_addr_fwd = remote_addr_fwd,
                meta = None if not meta else dumps(meta),
                cookies = None if not request.COOKIES else dumps(request.COOKIES),
                get = None if not request.GET else dumps(request.GET),
                post = None if (not request.POST or getattr(request,'hide_post') == True) else dumps(request.POST),
                raw_post = None if getattr(request,'hide_post') else request.raw_post_data,
                is_secure = request.is_secure(),
                is_ajax = request.is_ajax(),
                user = user
            ).save()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to save webpage in document directory with the images,css and javascripts etc..
I want to save a matrix to a text file, so I can read
Medium Security in IE8 states that third-party cookies that save information that can be
Software like OneNote has shown that auto-save can be implemented, and it works just
This is my class which is basically used for UnitForWork pattern i.e save everything
I want save the username and password when user login, and I added the
i want to save a variable to be global variable on all screens i
I want to save values as an ArrayList of double in a file. Whenever
I want to save my program's DataModel objects to a file, and be able
I want to save a local copy of xml being ouput by a certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.