def user_pull():
    """
    
    Pull app creators Mixpanel information.
    
    
    Parameters
    ----------
    
        
        
    Global Variables
    ----------
    
    api_creator_secret: Mixpanel Creator Project API key.
        Use to make API calls to Mixpanel Creator Project.
        
    
    Returns
    ----------
    
    dataframe
        Dataframe containing app creator information from Mixpanel.
    
    """

    #generate JQL query
    query_user = JQL(api_creator_secret,
                     people=People({'user_selectors': [{}]
                                    })).group_by(keys=[
                                        "e.properties.$email",
                                        "e.properties.$username",
                                        "e.properties.$distinct_id",
                                        "e.properties.hs_mrr"
                                    ],
                                                 accumulator=Reducer.count())

    #initialize list to track emails, user IDs, distinct IDs, and mrr
    email_list = []
    user_id_list = []
    distinct_id_list = []
    hs_mrr_list = []

    #process query results
    for row in query_user.send():
        email_list.append(row['key'][0])
        user_id_list.append(row['key'][1])
        distinct_id_list.append(row['key'][2])
        hs_mrr_list.append(row['key'][3])

    #create dataframe
    data = {
        'email': email_list,
        'user_id': user_id_list,
        'distinct_id': distinct_id_list,
        'hs_mrr': hs_mrr_list
    }
    df_users = pd.DataFrame(data=data)

    return df_users
示例#2
0
    def test_people_user_selectors(self):
        def good_params():
            return {
                'user_selectors': [{
                    'selector': 'my selector',
                }]
            }

        # Test valid
        People(good_params())

        # Bad key types
        bad_params = good_params()
        bad_params['user_selectors'][0]['selector'] = 3
        e = self._try_invalid_people(bad_params)
        self.assertEqual(
            str(e),
            "people_params['user_selectors'][0].selector must be a string")

        # Bad key
        bad_params = good_params()
        bad_params['user_selectors'][0]['mrao'] = 3
        e = self._try_invalid_people(bad_params)
        self.assertEqual(
            str(e),
            "'mrao' is not a valid key in people_params['user_selectors'][0]")
def get_new_signup(yesterday):
    """
    Get yesterday new signup.
    
    
    Parameters
    ----------
    
    yesterday: date
        Yesterday's date.
        
        
    Global Variables
    ----------
    
    api_creator_secret: Mixpanel Creator Project API key.
        Use to make API calls to Mixpanel Creator Project.
        
    
    Returns
    ----------
    
    dataframe
        Dataframe containing user IDs and emails of creators who signed up yesterday.
    
    """

    # New Signup Web
    query = JQL(api_creator_secret,
                events=Events({
                    'event_selectors': [{
                        'event': "New Signup Web"
                    }],
                    'from_date': yesterday,
                    'to_date': yesterday
                }),
                people=People({'user_selectors': []}),
                join_params={
                    'type': 'full',
                    'selectors': [{
                        'event': "New Signup Web"
                    }]
                })

    #store email, user id, and sign up events
    email_list = []
    userid_list = []
    for row in query.send():
        if 'user' in list(row.keys()):
            if '$username' in list(row['user']['properties'].keys()):
                userid_list.append(row['user']['properties']['$username'])
            if '$email' in list(row['user']['properties'].keys()):
                email_list.append(row['user']['properties']['$email'])

    #create dataframe
    data = {'user_id': userid_list, 'email': email_list}
    df_new_users = pd.DataFrame(data=data)

    return df_new_users
示例#4
0
 def _try_invalid_join(self, params):
     try:
         JQL(api_secret="asas",
             events=Events(),
             people=People(),
             join_params=params)
         self.fail("Expected Events syntax error with params: %s" % params)
     except JQLSyntaxError as e:
         return e
示例#5
0
def creator_pull():
    """
    Pull app creators' info in Mixpanel.
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_creator_secret: str
        Client secret used to make calls to Mixpanel Creator Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe app creators info in Mixpanel.
           
    """

    #generate JQL query
    query = JQL(api_creator_secret,
                people=People({'user_selectors':
                               [{}]})).group_by(keys=[
                                   "e.properties.$email",
                                   "e.properties.$username",
                                   "e.properties.hs_owner"
                               ],
                                                accumulator=Reducer.count())

    #store emails, user IDs, and user journey stages in lists
    email_list = []
    user_id_list = []
    hs_owner_list = []
    for row in query.send():
        if row['key'][0] is not None:
            email_list.append(row['key'][0])
            user_id_list.append(int(row['key'][1]))
            hs_owner_list.append(row['key'][2])

    #create dataframe
    data = {
        'email': email_list,
        'user_id': user_id_list,
        'hs_owner': hs_owner_list
    }
    df_creators = pd.DataFrame(data=data)

    #only keep users with HubSpot owner field. Indicating that it exists in hubspot
    df_creators = df_creators[~df_creators.hs_owner.isnull()]

    return df_creators
示例#6
0
def app_creator_pull():
    """
    Pull app creators' info from Mixpanel.
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_creator_secret: str
        Client secret used to make calls to Mixpanel Creator Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe app creators info in Mixpanel.
           
    """

    #generate JQL query
    query_user = JQL(api_creator_secret,
                     people=People({'user_selectors': [{}]
                                    })).group_by(keys=[
                                        "e.properties.$email",
                                        "e.properties.$username",
                                        "e.properties.$distinct_id",
                                        "e.properties.active_milestone"
                                    ],
                                                 accumulator=Reducer.count())

    #store emails, user IDs, distinct_id, active_milestone in lists
    email_list = []
    user_id_list = []
    distinct_id_list = []
    active_milestone_list = []
    for row in query_user.send():
        if row['key'][1] is not None:
            email_list.append(row['key'][0])
            user_id_list.append(int(row['key'][1]))
            distinct_id_list.append(row['key'][2])
            active_milestone_list.append(row['key'][3])

    #create dataframe
    data = {
        'email': email_list,
        'app_owner_id': user_id_list,
        'distinct_id': distinct_id_list,
        'active_milestone': active_milestone_list
    }
    df_creators = pd.DataFrame(data=data)
    return df_creators
def user_pull():
    """
    Pull app creators' info in Mixpanel.
    
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_creator_secret: str
        Client secret used to make calls to Mixpanel Creator Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe contains app creators info in Mixpanel.
           
    """

    #generate JQL query
    query = JQL(api_creator_secret,
                people=People({'user_selectors':
                               [{}]})).group_by(keys=[
                                   "e.properties.$email",
                                   "e.properties.company_domain",
                                   "e.properties.$distinct_id"
                               ],
                                                accumulator=Reducer.count())

    #initiate list to store emails, user IDs, and company domains
    email_list = []
    company_domain_list = []
    distinct_id_list = []

    #process query results
    for row in query.send():
        email_list.append(row['key'][0])
        company_domain_list.append(row['key'][1])
        distinct_id_list.append(row['key'][2])

    #create dataframe
    data = {
        'email': email_list,
        'company_domain': company_domain_list,
        'distinct_id': distinct_id_list
    }
    df_users = pd.DataFrame(data=data)

    return df_users
def creator_pull():
    """
    Pull app creators' info in Mixpanel.
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_creator_secret: str
        Client secret used to make calls to Mixpanel Creator Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe contains app creators info in Mixpanel.
           
    """

    #generate JQL query
    query = JQL(api_creator_secret,
                people=People({'user_selectors':
                               [{}]})).group_by(keys=[
                                   "e.properties.$email",
                                   "e.properties.$username",
                                   "e.properties.user_journey_stage"
                               ],
                                                accumulator=Reducer.count())

    #initialize lists to store user IDs, email, and journey stage
    email_list = []
    user_id_list = []
    user_journey_stage_list = []

    #process query results
    for row in query.send():
        email_list.append(row['key'][0])
        user_id_list.append(row['key'][1])
        user_journey_stage_list.append(row['key'][2])

    #create dataframe
    data = {
        'email': email_list,
        'creator_user_id': user_id_list,
        'user_journey_stage': user_journey_stage_list
    }
    df_creators = pd.DataFrame(data=data)

    return df_creators
示例#9
0
def creator_pull():

    """
    Pull app creators' info in Mixpanel.
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_creator_secret: str
        Client secret used to make calls to Mixpanel Creator Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe app creators info in Mixpanel.
           
    """
    
    #generate JQL query
    query_user = JQL(
                api_creator_secret,
                people=People({
                    'user_selectors': [{
                    }

                ]

                })
            ).group_by(
                keys=[
                    "e.properties.$distinct_id",
                    "e.properties.$username"],
                accumulator=Reducer.count()
            )


    #store emails, user IDs, and user journey stages in lists
    distinct_id_list = []
    user_id_list = []
    for row in query_user.send():
        distinct_id_list.append(row['key'][0])
        user_id_list.append(row['key'][1])

    #create dataframe 
    data = {'distinct_id': distinct_id_list, 'user_id': user_id_list}
    df_creators = pd.DataFrame(data=data)
    return df_creators
示例#10
0
    def test_join_types(self):
        # Good types
        for t in ('full', 'left', 'right', 'inner'):
            JQL('some_key',
                events=Events(),
                people=People(),
                join_params={'type': t})

        # Bad type
        e = self._try_invalid_join({'type': 'mew'})
        self.assertEqual(
            '"mew" is not a valid join type (valid types: full, left, right, inner)',
            str(e))
示例#11
0
def pull_creators():
    """
    
    Pull app creators Mixpanel information.
    
    
    Parameters
    ----------
    
        
        
    Global Variables
    ----------
    
    api_creator_secret: Mixpanel Creator Project API key
        Use to make API calls to Mixpanel Creator Project.
        
    
    Returns
    ----------
    
    dataframe
        Dataframe containing app creator information from Mixpanel.
    
    """

    #generate JQL query
    query_category = JQL(
        api_creator_secret, people=People({'user_selectors': [{}]})).group_by(
            keys=["e.properties.$email", "e.properties.$distinct_id"],
            accumulator=Reducer.count())

    #initialize lists to store emails and distinct IDs
    email_list = []
    distinct_id_list = []

    #process query response
    for row in query_category.send():
        email_list.append(row['key'][0])
        distinct_id_list.append(row['key'][1])

    #create dataframe
    data = {'email': email_list, 'mixpanel_distinct_id': distinct_id_list}
    df_creators_mixpanel = pd.DataFrame(data=data)

    #remove creators with missing information
    df_creators_mixpanel = df_creators_mixpanel.dropna()

    return df_creators_mixpanel
示例#12
0
def user_pull():
    """
    
    Pull app creators Mixpanel information.
    
    
    Parameters
    ----------
    
        
        
    Global Variables
    ----------
    
    api_creator_secret: Mixpanel Creator Project API key.
        Use to make API calls to Mixpanel Creator Project.
        
    
    Returns
    ----------
    
    dataframe
        Dataframe containing app creator information from Mixpanel.
    
    """

    #generate JQL query
    query_user = JQL(api_creator_secret,
                     people=People({'user_selectors': [{}]
                                    })).group_by(keys=[
                                        "e.properties.$email",
                                        "e.properties.$username"
                                    ],
                                                 accumulator=Reducer.count())

    #initialize lists to record app creator information
    email_list = []
    user_id_list = []
    for row in query_user.send():
        email_list.append(row['key'][0])
        user_id_list.append(row['key'][1])

    #create dataframe
    data = {'email': email_list, 'user_id': user_id_list}
    df_users = pd.DataFrame(data=data)

    return df_users
def creator_pull():
    """
    Pull app creators' info in Mixpanel.
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_creator_secret: str
        Client secret used to make calls to Mixpanel Creator Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe app creators info in Mixpanel.
           
    """

    #generate JQL query
    query_user = JQL(api_creator_secret,
                     people=People({'user_selectors': [{}]
                                    })).group_by(keys=[
                                        "e.properties.$email",
                                        "e.properties.$unsubscribed"
                                    ],
                                                 accumulator=Reducer.count())

    #store emails, user IDs, and user journey stages in lists
    email_list = []
    unsubscribed_list = []
    for row in query_user.send():
        if ((row['key'][0] is not None) & (row['key'][1] is not None)
            ):  #only keep accounts with both email and unsubscribe status
            email_list.append(row['key'][0])
            unsubscribed_list.append(row['key'][1])

    #create dataframe
    data = {'email': email_list, 'unsubscribed': unsubscribed_list}
    df_creators = pd.DataFrame(data=data)

    return df_creators
def app_user_pull():
    """
    
    Pull app users' information in Mixpanel.
    
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_user_secret: str
        Client secret used to make calls to Mixpanel User Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe contains app users' information in Mixpanel.
           
    """

    #generate JQL query
    query_user = JQL(api_user_secret, people=People({
        'user_selectors': [{}]
    })).group_by(keys=["e.properties.$email", "e.properties.$username"],
                 accumulator=Reducer.count())

    #initialize lists to record email and user ID
    email_list = []
    user_id_list = []

    #process query results
    for row in query_user.send():
        email_list.append(row['key'][0])
        user_id_list.append(row['key'][1])

    #create dataframe
    data = {'user_email': email_list, 'app_user_id': user_id_list}
    df_app_users = pd.DataFrame(data=data)

    return df_app_users
示例#15
0
def creator_pull():

    #generate JQL query
    query = JQL(api_creator_secret,
                people=People({'user_selectors': [{}]})).group_by(
                    keys=["e.properties.$email", "e.properties.$distinct_id"],
                    accumulator=Reducer.count())

    #store emails, user IDs, and user journey stages in lists
    email_list = []
    distinct_id_list = []

    for row in query.send():
        if row['key'][0] is not None:
            email_list.append(row['key'][0])
            distinct_id_list.append(row['key'][1])

    #create dataframe
    data = {'email': email_list, 'distinct_id': distinct_id_list}
    df_creators = pd.DataFrame(data=data)

    return df_creators
示例#16
0
    def test_join_selectors(self):
        def good_params():
            return {
                'selectors': [{
                    'event': 'my_event',
                    'selector': 'my selector'
                }]
            }

        # Test valid
        JQL('some_api_key',
            events=Events(),
            people=People(),
            join_params=good_params())

        # Bad array
        bad_params = good_params()
        bad_params['selectors'] = 3
        e = self._try_invalid_join(bad_params)
        self.assertEqual(str(e), "join_params['selectors'] must be iterable")

        # Bad key types
        for key in ('event', 'selector'):
            bad_params = good_params()
            bad_params['selectors'][0][key] = 3
            e = self._try_invalid_join(bad_params)
            self.assertEqual(
                str(e),
                "join_params['selectors'][0].%s must be a string" % key)

        # Bad key
        bad_params = good_params()
        bad_params['selectors'][0]['mrao'] = 3
        e = self._try_invalid_join(bad_params)
        self.assertEqual(
            str(e), "'mrao' is not a valid key in join_params['selectors'][0]")
示例#17
0
 def test_query_plan(self):
     with warnings.catch_warnings(record=True) as w:
         q = JQL('key', events=Events(), people=People())
         q.query_plan()
         self.assertIs(w[-1].category, DeprecationWarning)
         self.assertIn('query_plan', str(w[-1].message))
示例#18
0
 def _try_invalid_people(self, params):
     try:
         People(params)
         self.fail("Expected People syntax error with params: %s" % params)
     except JQLSyntaxError as e:
         return e
def app_user_pull():
    """
    Pull app users' info in Mixpanel.
    
    
    Parameters
    ----------
    
        
    Global Variables
    ----------
    
    api_user_secret: str
        Client secret used to make calls to Mixpanel User Project.
        
        
    Returns
    ----------
    
    dataframe
        Dataframe contains app users info in Mixpanel.
           
    """

    #generate JQL query
    query = JQL(api_user_secret, people=People(
        {'user_selectors': [{}]})).group_by(
            keys=[
                "e.properties.$email",
                "e.properties.$username",
                "e.properties.$distinct_id",
                "e.properties.creator",  #pulling current creator status
                "e.properties.active_user"
            ],  #pulling current active user status
            accumulator=Reducer.count())

    #initialize lists to record email, user ID, creator status, active user status, and distinct ID
    email_list = []
    user_id_list = []
    creator_list = []
    active_user_list = []
    distinct_id_list = []

    #process query results
    for row in query.send():
        email_list.append(row['key'][0])
        user_id_list.append(row['key'][1])
        distinct_id_list.append(row['key'][2])
        creator_list.append(row['key'][3])
        active_user_list.append(row['key'][4])

    #create dataframe
    data = {
        'email': email_list,
        'app_user_id': user_id_list,
        'distinct_id': distinct_id_list,
        'creator_current': creator_list,
        'active_user_current': active_user_list
    }
    df_app_users = pd.DataFrame(data=data)
    df_app_users = df_app_users.dropna()
    df_app_users.app_user_id = df_app_users.app_user_id.astype(int)

    return df_app_users