def test_site_config_override(self): site_config = SiteConfigurationFactory.create( site_values=dict(GOOGLE_ANALYTICS_ACCOUNT='UA-654321-1'), values=dict(GOOGLE_ANALYTICS_ACCOUNT='UA-654321-1')) pixel = GoogleAnalyticsTrackingPixel(site=site_config.site) self.assert_query_string_parameters_equal(pixel.generate_image_url(), tid='UA-654321-1')
def test_custom_dimension_without_user_id(self): pixel = GoogleAnalyticsTrackingPixel(campaign_source=None, campaign_medium=None) self.assertIsNotNone(pixel.generate_image_url()) self.assert_url_components_equal( pixel.generate_image_url(), query= 'v=1&t=event&ec=email&ea=edx.bi.email.opened&cid={cid}&tid=UA-123456-1' .format( cid=GoogleAnalyticsTrackingPixel.ANONYMOUS_USER_CLIENT_ID, ))
def test_default_parameters(self): pixel = GoogleAnalyticsTrackingPixel() self.assertIsNotNone(pixel.generate_image_url()) self.assert_url_components_equal( pixel.generate_image_url(), scheme='https', netloc='www.google-analytics.com', path='/collect', query= 'v=1&t=event&cs={cs}&cm={cm}&ec=email&ea=edx.bi.email.opened&cid={cid}&tid=UA-123456-1' .format( cs=DEFAULT_CAMPAIGN_SOURCE, cm=DEFAULT_CAMPAIGN_MEDIUM, cid=GoogleAnalyticsTrackingPixel.ANONYMOUS_USER_CLIENT_ID, ))
def _get_google_analytics_tracking_url(context): site, user, message = _get_variables_from_context( context, 'google_analytics_tracking_pixel') pixel = GoogleAnalyticsTrackingPixel( site=site, user_id=user.id, campaign_source=message.app_label, campaign_name=message.name, campaign_content=message.uuid, document_path='/email/{}/{}/{}/{}'.format( message.app_label, message.name, message.send_uuid, message.uuid, ), document_host=site.domain.rstrip('/')) course_ids = context.get('course_ids') if course_ids is not None and len(course_ids) > 0: pixel.course_id = course_ids[0] return pixel.generate_image_url()
def test_all_parameters(self): pixel = GoogleAnalyticsTrackingPixel( version=2, hit_type='ev', campaign_source='test_cs', campaign_medium='test_cm', campaign_name='test_cn', campaign_content='test_cc', event_category='test_ec', event_action='test_ea', event_label='test_el', document_path='test_dp', client_id='123456.123456', ) self.assertIsNotNone(pixel.generate_image_url()) self.assert_url_components_equal( pixel.generate_image_url(), scheme='https', netloc='www.google-analytics.com', path='/collect', query= 'tid=UA-123456-1&v=2&t=ev&cs=test_cs&cm=test_cm&cn=test_cn&ec=test_ec&ea=test_ea&el=test_el' '&dp=test_dp&cid=123456.123456&cc=test_cc')
def test_course_id_with_event_label(self): pixel = GoogleAnalyticsTrackingPixel(course_id='foo/bar/baz', event_label='test_label') self.assertIsNotNone(pixel.generate_image_url()) self.assert_query_string_parameters_equal(pixel.generate_image_url(), el='test_label')
def test_course_id(self): course_id = 'foo/bar/baz' pixel = GoogleAnalyticsTrackingPixel(course_id=course_id) self.assertIsNotNone(pixel.generate_image_url()) self.assert_query_string_parameters_equal(pixel.generate_image_url(), el=course_id)
def test_missing_settings(self): pixel = GoogleAnalyticsTrackingPixel() self.assertIsNone(pixel.generate_image_url())