예제 #1
0
def _send_form_to_hubspot(form_id, webuser, hubspot_cookie, meta, extra_fields=None, email=False):
    """
    This sends hubspot the user's first and last names and tracks everything they did
    up until the point they signed up.
    """
    if ((webuser and not webuser.analytics_enabled)
            or (not webuser and not analytics_enabled_for_email(email))):
        # This user has analytics disabled
        return

    hubspot_id = settings.ANALYTICS_IDS.get('HUBSPOT_API_ID')
    if hubspot_id and hubspot_cookie:
        url = u"https://forms.hubspot.com/uploads/form/v2/{hubspot_id}/{form_id}".format(
            hubspot_id=hubspot_id,
            form_id=form_id
        )
        data = {
            'email': email if email else webuser.username,
            'hs_context': json.dumps({"hutk": hubspot_cookie, "ipAddress": _get_client_ip(meta)}),
        }
        if webuser:
            data.update({'firstname': webuser.first_name,
                         'lastname': webuser.last_name,
                         })
        if extra_fields:
            data.update(extra_fields)

        response = _send_hubspot_form_request(url, data)
        _log_response('HS', data, response)
        response.raise_for_status()
예제 #2
0
def _send_form_to_hubspot(form_id, webuser, hubspot_cookie, meta, extra_fields=None, email=False):
    """
    This sends hubspot the user's first and last names and tracks everything they did
    up until the point they signed up.
    """
    if ((webuser and not webuser.analytics_enabled)
            or (not webuser and not analytics_enabled_for_email(email))):
        # This user has analytics disabled
        return

    hubspot_id = settings.ANALYTICS_IDS.get('HUBSPOT_API_ID')
    if hubspot_id and hubspot_cookie:
        url = "https://forms.hubspot.com/uploads/form/v2/{hubspot_id}/{form_id}".format(
            hubspot_id=hubspot_id,
            form_id=form_id
        )
        data = {
            'email': email if email else webuser.username,
            'hs_context': json.dumps({"hutk": hubspot_cookie, "ipAddress": _get_client_ip(meta)}),
        }
        if webuser:
            data.update({
                'firstname': webuser.first_name,
                'lastname': webuser.last_name,
            })
        if extra_fields:
            data.update(extra_fields)

        response = _send_hubspot_form_request(url, data)
        _log_response('HS', data, response)
        response.raise_for_status()
예제 #3
0
def track_workflow(email, event, properties=None):
    """
    Record an event in KISSmetrics.
    :param email: The email address by which to identify the user.
    :param event: The name of the event.
    :param properties: A dictionary or properties to set on the user.
    :return:
    """
    if analytics_enabled_for_email(email):
        timestamp = unix_time(datetime.utcnow())   # Dimagi KISSmetrics account uses UTC
        _track_workflow_task.delay(email, event, properties, timestamp)
예제 #4
0
def identify(email, properties):
    """
    Set the given properties on a KISSmetrics user.
    :param email: The email address by which to identify the user.
    :param properties: A dictionary or properties to set on the user.
    :return:
    """
    api_key = settings.ANALYTICS_IDS.get("KISSMETRICS_KEY", None)
    if api_key and analytics_enabled_for_email(email):
        km = KISSmetrics.Client(key=api_key)
        res = km.set(email, properties)
        _log_response("KM", {'email': email, 'properties': properties}, res)
        # TODO: Consider adding some better error handling for bad/failed requests.
        _raise_for_urllib3_response(res)
예제 #5
0
def identify_v2(email, properties):
    """
    Set the given properties on a KISSmetrics user.
    :param email: The email address by which to identify the user.
    :param properties: A dictionary or properties to set on the user.
    :return:
    """
    api_key = settings.ANALYTICS_IDS.get("KISSMETRICS_KEY", None)
    if api_key and analytics_enabled_for_email(email):
        km = KISSmetrics.Client(key=api_key)
        res = km.set(email, properties)
        _log_response("KM", {'email': email, 'properties': properties}, res)
        # TODO: Consider adding some better error handling for bad/failed requests.
        _raise_for_urllib3_response(res)
예제 #6
0
def track_workflow(email, event, properties=None):
    """
    Record an event in KISSmetrics.
    :param email: The email address by which to identify the user.
    :param event: The name of the event.
    :param properties: A dictionary or properties to set on the user.
    :return:
    """
    try:
        if analytics_enabled_for_email(email):
            timestamp = unix_time(datetime.utcnow())   # Dimagi KISSmetrics account uses UTC
            _track_workflow_task_v2.delay(email, event, properties, timestamp)
    except Exception:
        notify_exception(None, "Error tracking kissmetrics workflow")
예제 #7
0
def send_HTML_email(subject, recipient, html_content, *args, **kwargs):
    kwargs['ga_track'] = kwargs.get(
        'ga_track', False) and analytics_enabled_for_email(recipient)
    return _send_HTML_email(subject, recipient, html_content, *args, **kwargs)