From 317db4a86fdf68daf8c0ecba3398726665029a82 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Thu, 15 Mar 2018 11:21:16 +0300 Subject: [PATCH] Add user subscriptions categories to mixpanel --- apps/user/models.py | 4 ++++ apps/user/tasks.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/user/models.py b/apps/user/models.py index c9aad8e8..f4c56536 100644 --- a/apps/user/models.py +++ b/apps/user/models.py @@ -100,6 +100,7 @@ def send_user_info_to_mixpanel(sender, instance=None, created=False, **kwargs): instance.last_name, instance.date_joined, dict(User.ROLE_CHOICES).get(instance.role), + [subscription.title.lower() for subscription in instance.email_subscription.categories.all()] if hasattr(instance, 'email_subscription') else [], ) @@ -212,6 +213,9 @@ class SubscriptionCategory(models.Model): verbose_name_plural = 'Категории подписки' ordering = ('title',) + def __str__(self): + return self.title + class EmailSubscription(models.Model): ERROR = 0 diff --git a/apps/user/tasks.py b/apps/user/tasks.py index 110bf976..702c804e 100644 --- a/apps/user/tasks.py +++ b/apps/user/tasks.py @@ -6,7 +6,7 @@ from project.celery import app @app.task -def user_to_mixpanel(user_id, email, first_name, last_name, date_joined, role): +def user_to_mixpanel(user_id, email, first_name, last_name, date_joined, role, subscriptions): mix = Mixpanel(settings.MIX_TOKEN) mix.people_set( user_id, @@ -16,5 +16,6 @@ def user_to_mixpanel(user_id, email, first_name, last_name, date_joined, role): '$last_name': last_name, '$created': date_joined, 'role': role, + 'subscriptions': subscriptions, } )