def test_query_string_with_existing_utm_parameters(self):
     campaign = CampaignTrackingInfo(
         source='test_source',
         medium=None
     )
     self.assert_query_string_equal(
         'utm_source=test_source&utm_medium=custom_medium',
         campaign.to_query_string('utm_source=custom_source&utm_medium=custom_medium')
     )
 def test_query_string_with_existing_repeated_parameters(self):
     campaign = CampaignTrackingInfo(
         source='test_source',
         medium=None
     )
     self.assert_query_string_equal(
         'some_parameter=testing&utm_source=test_source&other=test2&some_parameter=baz',
         campaign.to_query_string('some_parameter=testing&other=test2&some_parameter=baz')
     )
Esempio n. 3
0
 def test_to_query_string(self):
     campaign = CampaignTrackingInfo(source='test_source with spaces',
                                     medium='test_medium',
                                     campaign='test_campaign',
                                     term='test_term',
                                     content='test_content')
     self.assert_query_string_equal(
         'utm_source=test_source%20with%20spaces&utm_medium=test_medium&utm_campaign=test_campaign'
         '&utm_term=test_term&utm_content=test_content',
         campaign.to_query_string(),
     )
 def test_to_query_string(self):
     campaign = CampaignTrackingInfo(
         source='test_source with spaces',
         medium='test_medium',
         campaign='test_campaign',
         term='test_term',
         content='test_content'
     )
     self.assert_query_string_equal(
         'utm_source=test_source%20with%20spaces&utm_medium=test_medium&utm_campaign=test_campaign'
         '&utm_term=test_term&utm_content=test_content',
         campaign.to_query_string(),
     )
Esempio n. 5
0
def modify_url_to_track_clicks(url, campaign=None):
    """
    Given a URL, this method modifies the query string parameters to include UTM tracking parameters.

    These UTM codes are used to by Google Analytics to identify the source of traffic. This will help us better
    understand how users behave when they come to the site by clicking a link in this email.

    Arguments:
        url (str): pass
        campaign (CampaignTrackingInfo): pass

    Returns:
        str: The url with appropriate query string parameters.
    """
    parsed_url = urlparse(url)
    if campaign is None:
        campaign = CampaignTrackingInfo()
    modified_url = parsed_url._replace(query=campaign.to_query_string(parsed_url.query))
    return modified_url.geturl()  # pylint: disable=no-member
Esempio n. 6
0
def modify_url_to_track_clicks(url, campaign=None):
    """
    Given a URL, this method modifies the query string parameters to include UTM tracking parameters.

    These UTM codes are used to by Google Analytics to identify the source of traffic. This will help us better
    understand how users behave when they come to the site by clicking a link in this email.

    Arguments:
        url (str): pass
        campaign (CampaignTrackingInfo): pass

    Returns:
        str: The url with appropriate query string parameters.
    """
    parsed_url = urlparse(url)
    if campaign is None:
        campaign = CampaignTrackingInfo()
    modified_url = parsed_url._replace(query=campaign.to_query_string(parsed_url.query))
    return modified_url.geturl()
Esempio n. 7
0
 def test_query_string_with_existing_utm_parameters(self):
     campaign = CampaignTrackingInfo(source='test_source', medium=None)
     self.assert_query_string_equal(
         'utm_source=test_source&utm_medium=custom_medium',
         campaign.to_query_string(
             'utm_source=custom_source&utm_medium=custom_medium'))
Esempio n. 8
0
 def test_query_string_with_existing_repeated_parameters(self):
     campaign = CampaignTrackingInfo(source='test_source', medium=None)
     self.assert_query_string_equal(
         'some_parameter=testing&utm_source=test_source&other=test2&some_parameter=baz',
         campaign.to_query_string(
             'some_parameter=testing&other=test2&some_parameter=baz'))