def insert_google_analytics(self, request, response): from google_analytics import WEBANALYTICS_HTML_CODE code = WEBANALYTICS_HTML_CODE.format(settings.GOOGLE_ANALYTICS_ID) content = response.content index = content.upper().find('</HEAD>') if index == -1: return response response.content = content[:index] + code + content[index:] return response
def insert_piwik(self, request, response): from piwik import WEBANALYTICS_HTML_CODE code = WEBANALYTICS_HTML_CODE.format(settings.PIWIK_HOST, settings.PIWIK_SITE_ID) content = response.content index = content.upper().find('</BODY>') if index == -1: return response response.content = content[:index] + code + content[index:] return response