Commit e6f78e05 by Chris Dodge Committed by Xavier Antoviaque

make GA account code configurable as well as allow GA to appear on courseware.…

make GA account code configurable as well as allow GA to appear on courseware. Also, make the GA account ID configurable rather than hard coded in the Mako template

Conflicts:
	lms/envs/aws.py
	lms/envs/common.py
parent 6f38bcc6
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
This test file will run through some LMS test scenarios regarding access and navigation of the LMS This test file will run through some LMS test scenarios regarding access and navigation of the LMS
""" """
import time import time
import mock
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -125,3 +126,89 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -125,3 +126,89 @@ class TestNavigation(ModuleStoreTestCase, LoginEnrollmentTestCase):
self.assertRedirects(resp, reverse('courseware_chapter', self.assertRedirects(resp, reverse('courseware_chapter',
kwargs={'course_id': self.course.id, kwargs={'course_id': self.course.id,
'chapter': 'factory_chapter'})) 'chapter': 'factory_chapter'}))
@mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSEWARE_GOOGLE_ANALYTICS': True})
def test_courseware_google_analytics(self):
"""
Verifies that when we turn on the feature to get google analytics on courseware
we see the expected HTML
"""
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
# Now we directly navigate to a section in a chapter other than 'Overview'.
resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id}), follow=True)
self.assertIn("_gaq.push(['_setAccount', 'add-your-GA-account-ID-here']);", resp.content)
@mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSEWARE_GOOGLE_ANALYTICS': False})
def test_courseware_google_analytics_disabled(self):
"""
Verifies that when we turn off the feature to get google analytics on courseware
we do not see the associated HTML
"""
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
# Now we directly navigate to a section in a chapter other than 'Overview'.
resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id}), follow=True)
self.assertNotIn("_gaq", resp.content)
@mock.patch.dict('django.conf.settings.FEATURES', {'ENABLE_COURSEWARE_GOOGLE_ANALYTICS': True})
@override_settings(GOOGLE_ANALYTICS_ACCOUNT_ID='dummy')
def test_courseware_google_analytics_custom_account(self):
"""
Verifies that when we override the Google Analytics account Id, that it appears in
the Google Analytics rendering
"""
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
# Now we directly navigate to a section in a chapter other than 'Overview'.
resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id}), follow=True)
self.assertIn("_gaq.push(['_setAccount', 'dummy']);", resp.content)
def test_courseware_custom_site_verification(self):
"""
Verifies that when we override the Google Analytics account Id, that it appears in
the Google Analytics rendering
"""
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
# Now we directly navigate to a section in a chapter other than 'Overview'.
resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id}), follow=True)
self.assertIn('<meta name="google-site-verification" content="add-your-Google-site-verification-here" />',
resp.content)
@override_settings(GOOGLE_SITE_VERIFICATION='dummy')
def test_courseware_default_site_verification(self):
"""
Verifies that when we override the Google Analytics account Id, that it appears in
the Google Analytics rendering
"""
email, password = self.STUDENT_INFO[0]
self.login(email, password)
self.enroll(self.course, True)
# Now we directly navigate to a section in a chapter other than 'Overview'.
resp = self.client.get(reverse('courseware',
kwargs={'course_id': self.course.id}), follow=True)
self.assertIn('<meta name="google-site-verification" content="dummy" />', resp.content)
...@@ -396,3 +396,7 @@ THIRD_PARTY_AUTH = AUTH_TOKENS.get('THIRD_PARTY_AUTH', THIRD_PARTY_AUTH) ...@@ -396,3 +396,7 @@ THIRD_PARTY_AUTH = AUTH_TOKENS.get('THIRD_PARTY_AUTH', THIRD_PARTY_AUTH)
##### ADVANCED_SECURITY_CONFIG ##### ##### ADVANCED_SECURITY_CONFIG #####
ADVANCED_SECURITY_CONFIG = ENV_TOKENS.get('ADVANCED_SECURITY_CONFIG', {}) ADVANCED_SECURITY_CONFIG = ENV_TOKENS.get('ADVANCED_SECURITY_CONFIG', {})
##### Google Analytics and Google Web Master Tools #####
GOOGLE_ANALYTICS_ACCOUNT_ID = ENV_TOKENS.get('GOOGLE_ANALYTICS_ACCOUNT_ID', GOOGLE_ANALYTICS_ACCOUNT_ID)
GOOGLE_SITE_VERIFICATION = ENV_TOKENS.get('GOOGLE_SITE_VERIFICATION', GOOGLE_SITE_VERIFICATION)
...@@ -223,6 +223,9 @@ FEATURES = { ...@@ -223,6 +223,9 @@ FEATURES = {
# Toggle embargo functionality # Toggle embargo functionality
'EMBARGO': False, 'EMBARGO': False,
# Turn on Google Analytics for courseware
'ENABLE_COURSEWARE_GOOGLE_ANALYTICS': False,
# Whether the Wiki subsystem should be accessible via the direct /wiki/ paths. Setting this to True means # Whether the Wiki subsystem should be accessible via the direct /wiki/ paths. Setting this to True means
# that people can submit content and modify the Wiki in any arbitrary manner. We're leaving this as True in the # that people can submit content and modify the Wiki in any arbitrary manner. We're leaving this as True in the
# defaults, so that we maintain current behavior # defaults, so that we maintain current behavior
...@@ -1523,3 +1526,7 @@ THIRD_PARTY_AUTH = {} ...@@ -1523,3 +1526,7 @@ THIRD_PARTY_AUTH = {}
### ADVANCED_SECURITY_CONFIG ### ADVANCED_SECURITY_CONFIG
# Empty by default # Empty by default
ADVANCED_SECURITY_CONFIG = {} ADVANCED_SECURITY_CONFIG = {}
### configuration for Google Analytics and Google Web Master Tools
GOOGLE_ANALYTICS_ACCOUNT_ID = 'add-your-GA-account-ID-here'
GOOGLE_SITE_VERIFICATION = 'add-your-Google-site-verification-here'
<script type="text/javascript"> <script type="text/javascript">
var _gaq = _gaq || []; var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-35248639-1']); _gaq.push(['_setAccount', '${settings.GOOGLE_ANALYTICS_ACCOUNT_ID}']);
_gaq.push(['_trackPageview']); _gaq.push(['_trackPageview']);
(function() { (function() {
......
...@@ -87,9 +87,9 @@ ...@@ -87,9 +87,9 @@
<![endif]--> <![endif]-->
<meta name="path_prefix" content="${EDX_ROOT_URL}"> <meta name="path_prefix" content="${EDX_ROOT_URL}">
<meta name="google-site-verification" content="_mipQ4AtZQDNmbtOkwehQDOgCxUUV2fb_C0b6wbiRHY" /> <meta name="google-site-verification" content="${settings.GOOGLE_SITE_VERIFICATION}" />
% if not course: % if not course or settings.FEATURES["ENABLE_COURSEWARE_GOOGLE_ANALYTICS"]:
<%include file="${google_analytics_file}" /> <%include file="${google_analytics_file}" />
% endif % endif
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<link rel="icon" type="image/x-icon" href="${static.url('images/favicon.ico')}" /> <link rel="icon" type="image/x-icon" href="${static.url('images/favicon.ico')}" />
<meta name="path_prefix" content="${EDX_ROOT_URL}" /> <meta name="path_prefix" content="${EDX_ROOT_URL}" />
<meta name="google-site-verification" content="_mipQ4AtZQDNmbtOkwehQDOgCxUUV2fb_C0b6wbiRHY" /> <meta name="google-site-verification" content="${settings.GOOGLE_SITE_VERIFICATION}" />
<%static:css group='style-vendor'/> <%static:css group='style-vendor'/>
<%static:css group='style-app'/> <%static:css group='style-app'/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment