本文整理匯總了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')
})