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()
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()
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)
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)
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)
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")
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)