diff --git a/pythonpro/core/tests/test_lead_landing_page.py b/pythonpro/core/tests/test_lead_landing_page.py index 6aea3cc8..4275b09c 100644 --- a/pythonpro/core/tests/test_lead_landing_page.py +++ b/pythonpro/core/tests/test_lead_landing_page.py @@ -189,7 +189,7 @@ def test_user_has_role(resp_lead_creation, django_user_model): def test_user_created_as_lead_on_email_marketing(resp_lead_creation, django_user_model, create_lead_mock: Mock): user = django_user_model.objects.first() create_lead_mock.assert_called_once_with(user.first_name, user.email, 'offer-funnel-0', 'utm_source=facebook', - id=user.id) + id=user.id, utm_source='facebook') def test_user_source_was_saved_from_url(resp_lead_creation, django_user_model, create_lead_mock: Mock): @@ -292,7 +292,8 @@ def test_should_send_utms_to_email_marketing_as_tags(create_lead_mock, resp_lead "utm_campaign=a00f00", "utm_content=content", "utm_term=term", - id=ANY + id=ANY, + utm_source='facebook-ads' ) ] create_lead_mock.assert_has_calls(calls) diff --git a/pythonpro/domain/tests/test_lead.py b/pythonpro/domain/tests/test_lead.py index 03629221..a341a0d0 100644 --- a/pythonpro/domain/tests/test_lead.py +++ b/pythonpro/domain/tests/test_lead.py @@ -15,7 +15,7 @@ def sync_user_delay(mocker): def test_creation(db, django_user_model, create_or_update_lead_mock, sync_user_delay): user = user_domain.register_lead('Renzo Nuccitelli', 'renzo@python.pro.br', 'google_ads') - create_or_update_lead_mock.assert_called_once_with(user.first_name, user.email, id=user.id) + create_or_update_lead_mock.assert_called_once_with(user.first_name, user.email, id=user.id, utm_source='google_ads') assert not sync_user_delay.called assert django_user_model.objects.all().get() == user @@ -25,6 +25,8 @@ def test_should_create_lead_with_extra_tags( user = user_domain.register_lead( 'Renzo Nuccitelli', 'renzo@python.pro.br', 'google_ads', tags=['tag-1', 'tag-2'] ) - create_or_update_lead_mock.assert_called_once_with(user.first_name, user.email, 'tag-1', 'tag-2', id=user.id) + create_or_update_lead_mock.assert_called_once_with( + user.first_name, user.email, 'tag-1', 'tag-2', id=user.id, utm_source='google_ads' + ) assert not sync_user_delay.called assert django_user_model.objects.all().get() == user diff --git a/pythonpro/domain/user_domain.py b/pythonpro/domain/user_domain.py index 6d3f62f4..d659cd3c 100644 --- a/pythonpro/domain/user_domain.py +++ b/pythonpro/domain/user_domain.py @@ -12,8 +12,8 @@ from pythonpro.core import facade as _core_facade from pythonpro.core.models import User as _User from pythonpro.discourse.facade import MissingDiscourseAPICredentials, generate_sso_payload_and_signature -from pythonpro.email_marketing import facade as _email_marketing_facade from pythonpro.domain.subscription_domain import subscribe_with_no_role +from pythonpro.email_marketing import facade as _email_marketing_facade _logger = Logger(__file__) @@ -43,7 +43,7 @@ def register_lead(first_name: str, email: str, source: str = 'unknown', tags: li source = 'unknown' _core_facade.validate_user(first_name, email, source) lead = _core_facade.register_lead(first_name, email, source) - _email_marketing_facade.create_or_update_lead.delay(first_name, email, *tags, id=lead.id) + _email_marketing_facade.create_or_update_lead.delay(first_name, email, *tags, id=lead.id, utm_source=source) return lead diff --git a/pythonpro/email_marketing/facade.py b/pythonpro/email_marketing/facade.py index 14446dbc..e089c71a 100644 --- a/pythonpro/email_marketing/facade.py +++ b/pythonpro/email_marketing/facade.py @@ -26,8 +26,8 @@ @run_until_available -def create_or_update_with_no_role(name: str, email: str, *tags, id='0', phone=None): - return create_or_update_user(name, email, '', *tags, id=id, phone=phone) +def create_or_update_with_no_role(name: str, email: str, *tags, id='0', phone=None, utm_source=None): + return create_or_update_user(name, email, '', *tags, id=id, phone=phone, utm_source=utm_source) @run_until_available @@ -79,7 +79,7 @@ def _normalise_id(id): @run_until_available -def create_or_update_user(name: str, email: str, role: str, *tags, id='0', phone=None): +def create_or_update_user(name: str, email: str, role: str, *tags, id='0', phone=None, utm_source=None): if settings.ACTIVE_CAMPAIGN_TURNED_ON is False: return prospect_list_id = _get_lists()['Prospects'] @@ -95,6 +95,8 @@ def create_or_update_user(name: str, email: str, role: str, *tags, id='0', phone } if phone is not None: data['phone'] = phone + if utm_source is not None: + data['field[%utm_source%]'] = utm_source if id == _normalise_id('0'): contact = _client.contacts.create_contact(data) else: