當前位置: 首頁>>代碼示例>>Python>>正文


Python mixpanel.Mixpanel類代碼示例

本文整理匯總了Python中mixpanel.Mixpanel的典型用法代碼示例。如果您正苦於以下問題:Python Mixpanel類的具體用法?Python Mixpanel怎麽用?Python Mixpanel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Mixpanel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_events_batch

 def test_events_batch(self):
     events_list = [
         {
             "event": "Signed Up",
             "properties": {
                 "distinct_id": "13793",
                  "token": "e3bc4100330c35722740fb8c6f5abddc",
                  "Referred By": "Friend",
                  "time": 1371002000
             }
         },
         {
             "event": "Uploaded Photo",
             "properties": {
                 "distinct_id": "13793",
                 "token": "e3bc4100330c35722740fb8c6f5abddc",
                 "Topic": "Vacation",
                 "time": 1371002104
             }
         }
     ]
     token = "e3bc4100330c35722740fb8c6f5abddc"
     mp = Mixpanel(token)
     mock_response = Mock()
     mock_response.read.return_value = '1'
     data = mp._prepare_data(events_list)
     with patch('urllib2.Request', return_value = mock_response) as mock_Request:
         with patch('urllib2.urlopen', return_value = mock_response) as mock_urlopen:
             mp.send_events_batch(events_list)
     mock_Request.assert_called_once_with(self.track_request_url, data)
開發者ID:daemonburrito,項目名稱:mixpanel-python,代碼行數:30,代碼來源:test.py

示例2: check_update

def check_update():
    """
    Check if there is a later version of Screenly OSE
    available. Only do this update once per day.
    Return True if up to date was written to disk,
    False if no update needed and None if unable to check.
    """

    sha_file = path.join(settings.get_configdir(), 'latest_screenly_sha')
    device_id_file = path.join(settings.get_configdir(), 'device_id')

    if path.isfile(sha_file):
        sha_file_mtime = path.getmtime(sha_file)
        last_update = datetime.fromtimestamp(sha_file_mtime)
    else:
        last_update = None

    if not path.isfile(device_id_file):
        device_id = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(15))
        with open(device_id_file, 'w') as f:
            f.write(device_id)
    else:
        with open(device_id_file, 'r') as f:
            device_id = f.read()

    logging.debug('Last update: %s' % str(last_update))

    git_branch = sh.git('rev-parse', '--abbrev-ref', 'HEAD').strip()
    git_hash = sh.git('rev-parse', '--short', 'HEAD').strip()

    if last_update is None or last_update < (datetime.now() - timedelta(days=1)):

        if not settings['analytics_opt_out'] and not is_ci():
            mp = Mixpanel('d18d9143e39ffdb2a4ee9dcc5ed16c56')
            try:
                mp.track(device_id, 'Version', {
                    'Branch': str(git_branch),
                    'Hash': str(git_hash),
                })
            except MixpanelException:
                pass
            except AttributeError:
                pass

        if remote_branch_available(git_branch):
            latest_sha = fetch_remote_hash(git_branch)

            if latest_sha:
                with open(sha_file, 'w') as f:
                    f.write(latest_sha)
                return True
            else:
                logging.debug('Unable to fetch latest hash.')
                return
        else:
            touch(sha_file)
            logging.debug('Unable to check if branch exist. Checking again tomorrow.')
            return
    else:
        return False
開發者ID:viaict,項目名稱:screenly-ose,代碼行數:60,代碼來源:viewer.py

示例3: users

def users(email, name=None, ip=None):
	mp = Mixpanel(TOKEN)
	params = {'$email': email}
	if name:
		params['$name'] = name
	if ip:
		params['$ip'] = ip
	mp.people_set(email, params)
開發者ID:aiyappaganesh,項目名稱:underdogs,代碼行數:8,代碼來源:api.py

示例4: test_alias

 def test_alias(self):
     token = '12345'
     mp = Mixpanel(token)
     mock_response = Mock()
     mock_response.read.return_value = '1'
     with patch('urllib2.urlopen', return_value = mock_response) as mock_urlopen:
         mp.alias('amq','3680')
     data = mp._prepare_data({'event': '$create_alias', 'properties': {'distinct_id': '3680', 'alias': 'amq', 'token': '12345'}})
     mock_urlopen.assert_called_once_with(self.engage_request_url, data)
開發者ID:daemonburrito,項目名稱:mixpanel-python,代碼行數:9,代碼來源:test.py

示例5: test_people_set

 def test_people_set(self):
     token = '12345'
     mp = Mixpanel(token)
     mock_response = Mock()
     mock_response.read.return_value = '1'
     with patch('urllib2.urlopen', return_value = mock_response) as mock_urlopen:
         mp.people_set('amq', {'birth month': 'october', 'favorite color': 'purple'})
     data = mp._prepare_data({'$token': '12345', '$distinct_id': 'amq', '$set': {'birth month': 'october', 'favorite color': 'purple'}})
     mock_urlopen.assert_called_once_with(self.engage_request_url, data)
開發者ID:daemonburrito,項目名稱:mixpanel-python,代碼行數:9,代碼來源:test.py

示例6: test_track

 def test_track(self):
     token = '12345'
     mp = Mixpanel(token)
     mock_response = Mock()
     mock_response.read.return_value = '1'
     with patch('urllib2.urlopen', return_value = mock_response) as mock_urlopen:
         mp.track('button press', {'size': 'big', 'color': 'blue'})
     data = mp._prepare_data({'event': 'button press', 'properties': {'token': '12345', 'size': 'big', 'color': 'blue'}})
     mock_urlopen.assert_called_once_with(self.track_request_url, data)
開發者ID:daemonburrito,項目名稱:mixpanel-python,代碼行數:9,代碼來源:test.py

示例7: track_event

def track_event(user, event_name, event_properties={}):
    # Don't track events during unit tests
    if in_testing_mode():
        return

    mixpanel_token = getattr(settings, 'MIXPANEL_TOKEN', None)
    if mixpanel_token:
        mixpanel = Mixpanel(mixpanel_token)
        mixpanel.track(str(user.id), event_name, event_properties)
開發者ID:shotvibe,項目名稱:shotvibe-web,代碼行數:9,代碼來源:event_tracking.py

示例8: mixpanel_alias

def mixpanel_alias(new_id, old_id):
    if not settings.DEBUG and domain_exclude and new_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.alias(new_id, old_id)
開發者ID:,項目名稱:,代碼行數:10,代碼來源:

示例9: mixpanel_track_charge

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')
    })
開發者ID:,項目名稱:,代碼行數:12,代碼來源:

示例10: track

def track(id, metric, data, **kwargs):
    """
    Sends a metrics event to mixpanel

    :param id: The unique ID for this event
    :param metric: The name of the metric event
    :param data: A dictionary containing additional properties associated with this event
    :param kwargs: Additional arguments that will be passed through to Mixpanel's track function
    """
    global _mp

    if _mp is None:
        _mp = Mixpanel(Config.MIXPANEL_TOKEN, EnqueuingConsumer())

    _mp.track(id, metric, data, **kwargs)
開發者ID:cassiehilbig,項目名稱:MrWorldWideBot,代碼行數:15,代碼來源:metrics.py

示例11: _trace_mixpanel

def _trace_mixpanel(action_name, auth_user, client_user, client_token, kwargs):
    from mixpanel import Mixpanel
    from mixpanel_async import AsyncBufferedConsumer

    some_user_id = auth_user or client_user or client_token
    try:
        if action_name in ["get_server_info", "publish"]:
            mp = Mixpanel(BII_MIXPANEL_TOKEN, consumer=AsyncBufferedConsumer())
            properties = {'action': action_name, 'anonymous': (some_user_id == client_token)}
            if action_name == "get_server_info":
                properties["os"] = kwargs["bson_data"]["data"][0]["family"]
                properties["biicode_version"] = kwargs["bson_data"]["data"][1]
            mp.track(some_user_id, BII_API_MIXPANEL_EVENT_NAME, properties)
    except Exception as e:
        logger.warning("Error sending action to mixpanel: %s" % e)
開發者ID:biicode,項目名稱:bii-server,代碼行數:15,代碼來源:bii_user_trace_bottle_plugin.py

示例12: get_event_data

def get_event_data(events, unit=DEFAULT_UNIT, interval=DEFAULT_INTERVAL):
    """Retrieve event data for a list of events"""

    MIXPANEL_API_KEY = os.environ["MIXPANEL_API_KEY"]
    MIXPANEL_API_SECRET = os.environ["MIXPANEL_API_SECRET"]

    client = Mixpanel(api_key=MIXPANEL_API_KEY, api_secret=MIXPANEL_API_SECRET)

    response = client.request('events', 'general', {
        'event' : events,
        'unit' : unit,
        'interval' : interval
    })

    return response['data']['values']
開發者ID:bradjasper,項目名稱:Mixpanel-Statistics,代碼行數:15,代碼來源:utils.py

示例13: do_tracking

def do_tracking(project_token, distinct_id, queue):
    """
    This process represents the work process where events
    and updates are generated. This might be the service
    thread of a web service, or some other process that
    is mostly concerned with getting time-sensitive work
    done.
    """
    consumer = QueueWriteConsumer(queue)
    mp = Mixpanel(project_token, consumer)
    for i in xrange(100):
        event = "Tick"
        mp.track(distinct_id, "Tick", {"Tick Number": i})
        print "tick {0}".format(i)

    queue.put(None)  # tell worker we're out of jobs
開發者ID:karpitsky,項目名稱:mixpanel-python,代碼行數:16,代碼來源:subprocess_consumer.py

示例14: __init__

	def __init__(self):
		with open('etc/mp.yml', 'r') as f:
			mp = yaml.load(f)
		self.api = Mixpanel(
			api_key=mp['api_key'],
			api_secret=mp['api_secret']
		)
開發者ID:alexanderfabry,項目名稱:abtest,代碼行數:7,代碼來源:mixpanel_test.py

示例15: MixpanelOnLawpal

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)
開發者ID:rosscdh,項目名稱:toolkit,代碼行數:57,代碼來源:analytics.py


注:本文中的mixpanel.Mixpanel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。