def set_user(self, visitor_id, user): from KISSmetrics import KM km = KM(settings.KISSMETRICS_API_KEY) km.identify(visitor_id) km.set({'user_id' : user.id, 'name' : user.get_full_name() })
def label_visitor(self, visitor_id, label): from KISSmetrics import KM km = KM(settings.KISSMETRICS_API_KEY) km.identify(visitor_id) km.set({label:1})
class KissMetricsBackend(BaseBackend): template_name = 'customerevents/kissmetrics.html' def __init__(self, API_KEY, **kwargs): self.connection = KM(API_KEY) self.api_key = API_KEY super(KissMetricsBackend, self).__init__(**kwargs) def get_context(self, identity, aliases, properties, events, **kwargs): identity, aliases, properties = normalize_identity(identity, aliases, properties) context = { 'identify': identity, 'properties': json.dumps(properties), 'record': list(), 'api_key': self.api_key, 'aliases': aliases, } context.update(kwargs) for event_name, event_properties in events: context['record'].append((normalize_name(event_name), json.dumps(event_properties))) return context def send(self, identity, properties, aliases, events, request_meta): identity, aliases, properties = normalize_identity(identity, aliases, properties) self.connection.identify(identity) for alias in aliases: self.connection.alias(identity, alias) if properties: self.connection.set(properties) for event_name, event_properties in events: self.connection.record(normalize_name(event_name), event_properties)
def register_event(self, event_type, visitor_id, when=None, data={}): if event_type in ('request', 'view'): return from KISSmetrics import KM km = KM(settings.KISSMETRICS_API_KEY) km.identify(visitor_id) if when: data['_d'] = 1 data['_t'] = int(time.mktime(when.timetuple())) km.record(event_type, data)
class TestAlias(object): def setup(self): self.km = KM(KM_DEVELOPMENT_KEY) self.km.identify('pelle') @deferred() def test_alias(self): return self.km.alias('pelle', '*****@*****.**') @deferred() def test_set(self): return self.km.set({ 'gender' : 'male' }) @deferred() def test_record(self): return self.km.record('Pelle\'s test event', { 'attr' : 'shark' })
def __init__(self, API_KEY, **kwargs): self.connection = KM(API_KEY) self.api_key = API_KEY super(KissMetricsBackend, self).__init__(**kwargs)
def set_user(self, visitor_id, user): from KISSmetrics import KM km = KM(settings.KISSMETRICS_API_KEY) km.identify(visitor_id) km.set({'user_id': user.id, 'name': user.get_full_name()})
def deduplicate(self, from_visitor_id, to_visitor_id): from KISSmetrics import KM km = KM(settings.KISSMETRICS_API_KEY) km.alias(from_visitor_id, to_visitor_id)
def label_visitor(self, visitor_id, label): from KISSmetrics import KM km = KM(settings.KISSMETRICS_API_KEY) km.identify(visitor_id) km.set({label: 1})
def setup(self): self.km = KM(KM_DEVELOPMENT_KEY) self.km.identify('pelle')