Пример #1
0
 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() })
Пример #2
0
 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})
Пример #3
0
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)
Пример #4
0
 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)
Пример #5
0
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' })
Пример #6
0
 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)
Пример #7
0
 def __init__(self, API_KEY, **kwargs):
     self.connection = KM(API_KEY)
     self.api_key = API_KEY
     super(KissMetricsBackend, self).__init__(**kwargs)
Пример #8
0
 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()})
Пример #9
0
 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)
Пример #10
0
 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})
Пример #11
0
 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)
Пример #12
0
 def setup(self):
     self.km = KM(KM_DEVELOPMENT_KEY)
     self.km.identify('pelle')