Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pythonpro/core/tests/test_lead_landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions pythonpro/domain/tests/test_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions pythonpro/domain/user_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions pythonpro/email_marketing/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand All @@ -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:
Expand Down