from experiments.utils import participant

class ExperimentsRetentionMiddleware(object):
    def process_response(self, request, response):
        #  We detect widgets by relying on the fact that they are flagged as being embedable, and don't include these in visit tracking
        if getattr(response, 'xframe_options_exempt', False):
            return response

        experiment_user = participant(request)
        experiment_user.visit()

        return response
from experiments.utils import participant

class ExperimentsRetentionMiddleware(object):
    def process_response(self, request, response):
        # Don't track, failed pages, ajax requests, logged out users or widget impressions.
        # We detect widgets by relying on the fact that they are flagged as being embedable
        if response.status_code != 200 or request.is_ajax() or getattr(response, 'xframe_options_exempt', False):
            return response

        experiment_user = participant(request)
        experiment_user.visit()

        return response
Revert "tidy up ajax page loads so they count towards experiments"
Revert "tidy up ajax page loads so they count towards experiments"

This reverts commit a37cacb96c4021fcc2f9e23e024d8947bb4e644f.

  from experiments.utils import participant
  
  class ExperimentsRetentionMiddleware(object):
      def process_response(self, request, response):
+         # Don't track, failed pages, ajax requests, logged out users or widget impressions.
-         #  We detect widgets by relying on the fact that they are flagged as being embedable, and don't include these in visit tracking
+         # We detect widgets by relying on the fact that they are flagged as being embedable
-         if getattr(response, 'xframe_options_exempt', False):
+         if response.status_code != 200 or request.is_ajax() or getattr(response, 'xframe_options_exempt', False):
              return response
  
          experiment_user = participant(request)
          experiment_user.visit()
  
          return response
Revert "tidy up ajax page loads so they count towards experiments"
## Code Before:
from experiments.utils import participant

class ExperimentsRetentionMiddleware(object):
    def process_response(self, request, response):
        #  We detect widgets by relying on the fact that they are flagged as being embedable, and don't include these in visit tracking
        if getattr(response, 'xframe_options_exempt', False):
            return response

        experiment_user = participant(request)
        experiment_user.visit()

        return response
## Instruction:
Revert "tidy up ajax page loads so they count towards experiments"
## Code After:
from experiments.utils import participant

class ExperimentsRetentionMiddleware(object):
    def process_response(self, request, response):
        # Don't track, failed pages, ajax requests, logged out users or widget impressions.
        # We detect widgets by relying on the fact that they are flagged as being embedable
        if response.status_code != 200 or request.is_ajax() or getattr(response, 'xframe_options_exempt', False):
            return response

        experiment_user = participant(request)
        experiment_user.visit()

        return response