本文整理汇总了Python中mixpanel.Mixpanel.people_track_charge方法的典型用法代码示例。如果您正苦于以下问题:Python Mixpanel.people_track_charge方法的具体用法?Python Mixpanel.people_track_charge怎么用?Python Mixpanel.people_track_charge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mixpanel.Mixpanel
的用法示例。
在下文中一共展示了Mixpanel.people_track_charge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MixpanelOnLawpal
# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import people_track_charge [as 别名]
class MixpanelOnLawpal(object):
token = None
service = None
def __init__(self, *args, **kwargs):
self.token = kwargs.get('token', MIXPANEL_SETTINGS.get('token', None))
if self.token is not None:
self.service = Mixpanel(self.token)
def mixpanel_alias(self, alias_id, original, **kwargs):
if self.service is not None:
try:
self.service.alias(alias_id=alias_id, original=original, **kwargs)
except Exception as e:
logger.error('Mixpanel error: distinct_id, missing or empty: %s :%s' % (alias_id, e))
def mixpanel_track_charge(self, user, amount, time, distinct_id=None, **kwargs):
if self.service is not None:
if distinct_id is None:
distinct_id = user.pk
try:
self.service.people_track_charge(distinct_id=distinct_id, amount=amount, properties={ '$time': time })
except Exception as e:
logger.error('Mixpanel error: %s' % e)
def event(self, key, user, distinct_id=None, **kwargs):
if self.service is not None:
if distinct_id is None:
distinct_id = user.pk
user_profile = user.profile
all_properties = {
'account_type': user_profile.account_type,
'plan': user_profile.plan,
'plan_interval': user_profile.plan_interval,
'user': user.get_full_name(),
'user_type': user_profile.type,
'via': 'web'
}
all_properties.update(kwargs)
try:
self.service.track(distinct_id=distinct_id, event_name=key, properties=all_properties)
except Exception as e:
logger.error('Mixpanel error: %s' % e)
def anon_event(self, key, distinct_id, **kwargs):
if self.service is not None:
all_properties = {
'user_id': distinct_id,
'account_type': 'anonymous',
'via': 'web'
}
all_properties.update(kwargs)
try:
self.service.track(distinct_id=distinct_id, event_name=key, properties=all_properties)
except Exception as e:
logger.error('Mixpanel error: %s' % e)
示例2: mixpanel_track_charge
# 需要导入模块: from mixpanel import Mixpanel [as 别名]
# 或者: from mixpanel.Mixpanel import people_track_charge [as 别名]
def mixpanel_track_charge(distinct_id, amount):
if not settings.DEBUG and domain_exclude and distinct_id.endswith(domain_exclude):
return
id = settings.METRICS.get('mixpanel', {}).get('id')
if not id:
logger.info('Mixpanel id not defined, task ignored')
return
mp = Mixpanel(id)
mp.people_track_charge(distinct_id, amount, {
'$time': datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
})