def render(self, context): custom_variables = context.get('matomo_vars', ()) complete_variables = (var if len(var) >= 4 else var + (DEFAULT_SCOPE,) for var in custom_variables) variables_code = (VARIABLE_CODE % MatomoVar(*var)._asdict() for var in complete_variables) commands = [] if getattr(settings, 'MATOMO_DISABLE_COOKIES', False): commands.append(DISABLE_COOKIES_CODE) userid = get_identity(context, 'matomo') if userid is not None: variables_code = chain(variables_code, ( IDENTITY_CODE % {'userid': userid}, )) html = TRACKING_CODE % { 'url': self.domain_path, 'siteid': self.site_id, 'variables': '\n '.join(variables_code), 'commands': '\n '.join(commands) } if is_internal_ip(context, 'MATOMO'): html = disable_html(html, 'Matomo') return html
def render(self, context): commands = [] identity = get_identity(context, 'kiss_metrics') if identity is not None: commands.append(IDENTIFY_CODE % identity) try: properties = context[ALIAS_CONTEXT_KEY] key, value = properties.popitem() commands.append(ALIAS_CODE % (key, value)) except KeyError: pass try: name, properties = context[EVENT_CONTEXT_KEY] commands.append(EVENT_CODE % {'name': name, 'properties': json.dumps(properties, sort_keys=True)}) except KeyError: pass try: properties = context[PROPERTY_CONTEXT_KEY] commands.append(PROPERTY_CODE % { 'properties': json.dumps(properties, sort_keys=True)}) except KeyError: pass html = TRACKING_CODE % {'api_key': self.api_key, 'commands': " ".join(commands)} if is_internal_ip(context, 'KISS_METRICS'): html = disable_html(html, 'KISSmetrics') return html
def render(self, context): extra_code = [] try: extra_code.append(NICKNAME_CODE % context[NICKNAME_CONTEXT_KEY]) except KeyError: identity = get_identity(context, 'olark', self._get_nickname) if identity is not None: extra_code.append(NICKNAME_CODE % identity) try: extra_code.append(FULLNAME_CODE.format(context[FULLNAME_CONTEXT_KEY])) except KeyError: pass try: extra_code.append(EMAIL_CODE.format(context[EMAIL_CONTEXT_KEY])) except KeyError: pass try: extra_code.append(STATUS_CODE % json.dumps(context[STATUS_CONTEXT_KEY], sort_keys=True)) except KeyError: pass extra_code.extend(self._get_configuration(context)) html = SETUP_CODE % {'site_id': self.site_id, 'extra_code': " ".join(extra_code)} return html
def _get_custom_attrs(self, context): params = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('intercom_'): params[var[9:]] = val user = get_user_from_context(context) if user is not None and get_user_is_authenticated(user): if 'name' not in params: params['name'] = get_identity( context, 'intercom', self._identify, user) if 'email' not in params and user.email: params['email'] = user.email params.setdefault('user_id', user.pk) params['created_at'] = int(_timestamp(user.date_joined)) else: params['created_at'] = None # Generate a user_hash HMAC to verify the user's identity, if configured. # (If both user_id and email are present, the user_id field takes precedence.) # See: # https://www.intercom.com/help/configure-intercom-for-your-product-or-site/staying-secure/enable-identity-verification-on-your-web-product user_hash_data = params.get('user_id', params.get('email')) # type: Optional[str] if user_hash_data: user_hash = intercom_user_hash(str(user_hash_data)) # type: Optional[str] if user_hash is not None: params.setdefault('user_hash', user_hash) return params
def render(self, context): html = SETUP_CODE % {'api_key': self.api_key} identity = get_identity(context, 'performable') if identity is not None: html = "%s%s" % (IDENTIFY_CODE % identity, html) if is_internal_ip(context, 'PERFORMABLE'): html = disable_html(html, 'Performable') return html
def render(self, context): re_vars = {} for dict_ in context: for var, val in dict_.items(): if var.startswith("reinvigorate_"): re_vars[var[13:]] = val if "name" not in re_vars: identity = get_identity(context, "reinvigorate", lambda u: u.get_full_name()) if identity is not None: re_vars["name"] = identity if "context" not in re_vars: email = get_identity(context, "reinvigorate", lambda u: u.email) if email is not None: re_vars["context"] = email tags = " ".join("var re_%s_tag = %s;" % (tag, simplejson.dumps(value)) for tag, value in re_vars.items()) html = TRACKING_CODE % {"tracking_id": self.tracking_id, "tags": tags} if is_internal_ip(context, "REINVIGORATE"): html = disable_html(html, "Reinvigorate") return html
def render(self, context): configs = [TOKEN_CODE % self.site_token] identity = get_identity(context, 'gosquared', self._identify) if identity: configs.append(IDENTIFY_CODE % identity) html = TRACKING_CODE % { 'token': self.site_token, 'config': ' '.join(configs), } if is_internal_ip(context, 'GOSQUARED'): html = disable_html(html, 'GoSquared') return html
def render(self, context): commands = [] identity = get_identity(context, 'kiss_insights') if identity is not None: commands.append(IDENTIFY_CODE % identity) try: commands.append(SHOW_SURVEY_CODE % context[SHOW_SURVEY_CONTEXT_KEY]) except KeyError: pass html = SETUP_CODE % {'account_number': self.account_number, 'site_code': self.site_code, 'commands': " ".join(commands)} return html
def render(self, context): re_vars = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('reinvigorate_'): re_vars[var[13:]] = val if 'name' not in re_vars: identity = get_identity(context, 'reinvigorate', lambda u: u.get_full_name()) if identity is not None: re_vars['name'] = identity if 'context' not in re_vars: email = get_identity(context, 'reinvigorate', lambda u: u.email) if email is not None: re_vars['context'] = email tags = " ".join("var re_%s_tag = %s;" % (tag, json.dumps(value, sort_keys=True)) for tag, value in re_vars.items()) html = TRACKING_CODE % {'tracking_id': self.tracking_id, 'tags': tags} if is_internal_ip(context, 'REINVIGORATE'): html = disable_html(html, 'Reinvigorate') return html
def _get_visitor(self, context): vars = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('woopra_'): vars[var[7:]] = val if 'name' not in vars and 'email' not in vars: user = get_user_from_context(context) if user is not None and user.is_authenticated(): vars['name'] = get_identity(context, 'woopra', self._identify, user) if user.email: vars['email'] = user.email return vars
def render(self, context): widget_key = context.get("uservoice_widget_key") if not widget_key: widget_key = self.default_widget_key if not widget_key: return "" options = {} options["enabled"] = context.get("uservoice_show_tab", True) options["custom_fields"] = context.get("uservoice_fields", {}) identity = get_identity(context, "uservoice") if identity is not None: # Enable SSO pass html = TRACKING_CODE % {"widget_key": widget_key, "options": simplejson.dumps(options)} return html
def render(self, context): commands = [] identity = get_identity(context, 'kiss_metrics') if identity is not None: commands.append(IDENTIFY_CODE % identity) try: name, properties = context[EVENT_CONTEXT_KEY] commands.append(EVENT_CODE % {'name': name, 'properties': simplejson.dumps(properties)}) except KeyError: pass html = TRACKING_CODE % {'api_key': self.api_key, 'commands': " ".join(commands)} if is_internal_ip(context, 'KISS_METRICS'): html = disable_html(html, 'KISSmetrics') return html
def render(self, context): custom = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('clicky_'): custom[var[7:]] = val if 'username' not in custom.get('session', {}): identity = get_identity(context, 'clicky') if identity is not None: custom.setdefault('session', {})['username'] = identity html = TRACKING_CODE % {'site_id': self.site_id, 'custom': simplejson.dumps(custom)} if is_internal_ip(context, 'CLICKY'): html = disable_html(html, 'Clicky') return html
def render(self, context): commands = [] identity = get_identity(context, 'mixpanel') if identity is not None: commands.append(IDENTIFY_CODE % identity) try: name, properties = context[EVENT_CONTEXT_KEY] commands.append(EVENT_CODE % {'name': name, 'properties': simplejson.dumps(properties)}) except KeyError: pass html = TRACKING_CODE % {'token': self.token, 'commands': " ".join(commands)} if is_internal_ip(context, 'MIXPANEL'): html = disable_html(html, 'Mixpanel') return html
def render(self, context): widget_key = context.get('uservoice_widget_key') if not widget_key: widget_key = self.default_widget_key if not widget_key: return '' options = {} options['enabled'] = context.get('uservoice_show_tab', True) options['custom_fields'] = context.get('uservoice_fields', {}) identity = get_identity(context, 'uservoice') if identity is not None: # Enable SSO pass html = TRACKING_CODE % {'widget_key': widget_key, 'options': json.dumps(options)} return html
def render(self, context): custom = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('spring_metrics_'): custom[var[15:]] = val if 'email' not in custom: identity = get_identity(context, 'spring_metrics', lambda u: u.email) if identity is not None: custom['email'] = identity html = TRACKING_CODE % {'tracking_id': self.tracking_id, 'custom_commands': self._generate_custom_javascript(custom)} if is_internal_ip(context, 'SPRING_METRICS'): html = disable_html(html, 'Spring Metrics') return html
def render(self, context): custom_variables = context.get("piwik_vars", ()) complete_variables = (var if len(var) >= 4 else var + (DEFAULT_SCOPE,) for var in custom_variables) variables_code = (VARIABLE_CODE % PiwikVar(*var)._asdict() for var in complete_variables) userid = get_identity(context, "piwik") if userid is not None: variables_code = chain(variables_code, (IDENTITY_CODE % {"userid": userid},)) html = TRACKING_CODE % { "url": self.domain_path, "siteid": self.site_id, "variables": "\n ".join(variables_code), } if is_internal_ip(context, "PIWIK"): html = disable_html(html, "Piwik") return html
def _get_custom_attrs(self, context): vars = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('intercom_'): vars[var[9:]] = val user = get_user_from_context(context) if user is not None and user.is_authenticated(): if 'name' not in vars: vars['name'] = get_identity(context, 'intercom', self._identify, user) if 'email' not in vars and user.email: vars['email'] = user.email vars['created_at'] = int(time.mktime(user.date_joined.timetuple())) else: vars['created_at'] = None return vars
def _get_custom_attrs(self, context): params = {} for dict_ in context: for var, val in dict_.items(): if var.startswith("intercom_"): params[var[9:]] = val user = get_user_from_context(context) if user is not None and user.is_authenticated(): if "name" not in params: params["name"] = get_identity(context, "intercom", self._identify, user) if "email" not in params and user.email: params["email"] = user.email params["created_at"] = int(time.mktime(user.date_joined.timetuple())) else: params["created_at"] = None return params
def render(self, context): commands = [] identity = get_identity(context, 'mixpanel') if identity is not None: if isinstance(identity, dict): commands.append(IDENTIFY_CODE % identity.get('id', identity.get('username'))) commands.append(IDENTIFY_PROPERTIES % json.dumps(identity, sort_keys=True)) else: commands.append(IDENTIFY_CODE % identity) try: name, properties = context[EVENT_CONTEXT_KEY] commands.append(EVENT_CODE % {'name': name, 'properties': json.dumps(properties, sort_keys=True)}) except KeyError: pass html = TRACKING_CODE % {'token': self._token, 'commands': " ".join(commands)} if is_internal_ip(context, 'MIXPANEL'): html = disable_html(html, 'Mixpanel') return mark_safe(html)
def _get_custom_attrs(self, context): params = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('intercom_'): params[var[9:]] = val user = get_user_from_context(context) if user is not None and get_user_is_authenticated(user): if 'name' not in params: params['name'] = get_identity(context, 'intercom', self._identify, user) if 'email' not in params and user.email: params['email'] = user.email params['created_at'] = int( time.mktime(user.date_joined.timetuple())) else: params['created_at'] = None return params
def render(self, context): commands = [] identity = get_identity(context, 'kiss_metrics') if identity is not None: commands.append(IDENTIFY_CODE % identity) try: name, properties = context[EVENT_CONTEXT_KEY] commands.append(EVENT_CODE % {'name': name, 'properties': simplejson.dumps(properties)}) except KeyError: pass try: properties = context[PROPERTY_CONTEXT_KEY] commands.append(PROPERTY_CODE % { 'properties': simplejson.dumps(properties)}) except KeyError: pass html = TRACKING_CODE % {'api_key': self.api_key, 'commands': " ".join(commands)} if is_internal_ip(context, 'KISS_METRICS'): html = disable_html(html, 'KISSmetrics') return html
def render(self, context): other_fields = {} identity = get_identity(context, 'google_analytics_gtag', self.identity_function) if identity is not None: other_fields['user_id'] = identity commands = [ GTAG_SET_CODE.format(key=key, value=value) for key, value in other_fields.items() ] commands += self._get_event_commands(context) extra = '\n'.join(commands) html = SETUP_CODE.format( property_id=self.property_id, extra=extra, ) if is_internal_ip(context, 'GOOGLE_ANALYTICS'): html = disable_html(html, 'Google Analytics') return html
def render(self, context): custom_variables = context.get('piwik_vars', ()) complete_variables = (var if len(var) >= 4 else var + (DEFAULT_SCOPE,) for var in custom_variables) variables_code = (VARIABLE_CODE % PiwikVar(*var)._asdict() for var in complete_variables) userid = get_identity(context, 'piwik') if userid is not None: variables_code = chain(variables_code, ( IDENTITY_CODE % {'userid': userid}, )) html = TRACKING_CODE % { 'url': self.domain_path, 'siteid': self.site_id, 'variables': '\n '.join(variables_code) } if is_internal_ip(context, 'PIWIK'): html = disable_html(html, 'Piwik') return html
def render(self, context): widget_key = context.get('uservoice_widget_key') if not widget_key: widget_key = self.default_widget_key if not widget_key: return '' # default options = {} options.update(getattr(settings, 'USERVOICE_WIDGET_OPTIONS', {})) options.update(context.get('uservoice_widget_options', {})) identity = get_identity(context, 'uservoice', self._identify) if identity: identity = IDENTITY % {'options': json.dumps(identity, sort_keys=True)} trigger = context.get('uservoice_add_trigger', getattr(settings, 'USERVOICE_ADD_TRIGGER', True)) html = TRACKING_CODE % {'widget_key': widget_key, 'options': json.dumps(options, sort_keys=True), 'trigger': TRIGGER if trigger else '', 'identity': identity if identity else ''} return html
def render(self, context): if settings.get("DISABLE_TRACKING_CODE", False): return "" commands = [] identity = get_identity(context, 'kiss_metrics') if identity is not None: commands.append(IDENTIFY_CODE % identity) try: properties = context[ALIAS_CONTEXT_KEY] key, value = properties.popitem() commands.append(ALIAS_CODE % (key, value)) except KeyError: pass try: name, properties = context[EVENT_CONTEXT_KEY] commands.append( EVENT_CODE % { 'name': name, 'properties': json.dumps(properties, sort_keys=True), }) except KeyError: pass try: properties = context[PROPERTY_CONTEXT_KEY] commands.append( PROPERTY_CODE % { 'properties': json.dumps(properties, sort_keys=True), }) except KeyError: pass html = TRACKING_CODE % { 'api_key': self.api_key, 'commands': " ".join(commands), } if is_internal_ip(context, 'KISS_METRICS'): html = disable_html(html, 'KISSmetrics') return html
def _get_additional_calls(context): pretrack = '' vars = {} for dict_ in context: for var, val in dict_.items(): if var.startswith('piwik_'): vars[var[6:]] = val if 'userid' not in vars: user = get_user_from_context(context) if user is not None and user.is_authenticated(): userid = get_identity(context, 'piwik', _identify, user) pretrack += '_paq.push(["setUserId", "%s"]);\n' % userid else: pretrack += '_paq.push(["setUserId", "%s"]);\n' % vars['userid'] del vars['userid'] var_str = '' if 'document_title' in vars: var_str += '_paq.push(["setDocumentTitle", "%s"]);\n' % vars[ 'document_title'] del vars['document_title'] for index, (raw_name, value) in enumerate(vars.items()): name, scope = raw_name.split('_') var_str += "_paq.push(['setCustomVariable', %(index)d, '%(name)s', '%(value)s', '%(scope)s']);\n" % { 'index': index, 'name': name, 'value': value, 'scope': scope, } pretrack = var_str + pretrack return pretrack
def render(self, context): commands = [] identity = get_identity(context, 'mixpanel') if identity is not None: if isinstance(identity, dict): commands.append(IDENTIFY_CODE % identity.get('id', identity.get('username'))) commands.append(IDENTIFY_PROPERTIES % json.dumps(identity, sort_keys=True)) else: commands.append(IDENTIFY_CODE % identity) try: name, properties = context[EVENT_CONTEXT_KEY] commands.append(EVENT_CODE % { 'name': name, 'properties': json.dumps(properties, sort_keys=True), }) except KeyError: pass html = TRACKING_CODE % { 'token': self._token, 'commands': " ".join(commands), } if is_internal_ip(context, 'MIXPANEL'): html = disable_html(html, 'Mixpanel') return mark_safe(html)
def test_custom_username_field(self): get_id = get_identity(Context({}), user=MyUser(identity='fake_id')) assert get_id == 'fake_id'
def render(self, context): settings_code = [] domain = self._get_setting(context, "snapengage_domain", "SNAPENGAGE_DOMAIN") if domain is not None: settings_code.append(DOMAIN_CODE % domain) secure_connection = self._get_setting( context, "snapengage_secure_connection", "SNAPENGAGE_SECURE_CONNECTION", False ) if secure_connection: settings_code.append(SECURE_CONNECTION_CODE) email = context.get("snapengage_email") if email is None: email = get_identity(context, "snapengage", lambda u: u.email) if email is not None: if self._get_setting(context, "snapengage_readonly_email", "SNAPENGAGE_READONLY_EMAIL", False): readonly_tail = ",true" else: readonly_tail = "" settings_code.append(SETEMAIL_CODE % (email, readonly_tail)) locale = self._get_setting(context, "snapengage_locale", "SNAPENGAGE_LOCALE") if locale is None: locale = translation.to_locale(translation.get_language()) settings_code.append(SETLOCALE_CODE % locale) form_position = self._get_setting(context, "snapengage_form_position", "SNAPENGAGE_FORM_POSITION") if form_position is not None: settings_code.append(FORM_POSITION_CODE % form_position) form_top_position = self._get_setting(context, "snapengage_form_top_position", "SNAPENGAGE_FORM_TOP_POSITION") if form_top_position is not None: settings_code.append(FORM_TOP_POSITION_CODE % form_top_position) show_offline = self._get_setting(context, "snapengage_show_offline", "SNAPENGAGE_SHOW_OFFLINE", True) if not show_offline: settings_code.append(DISABLE_OFFLINE_CODE) screenshots = self._get_setting(context, "snapengage_screenshots", "SNAPENGAGE_SCREENSHOTS", True) if not screenshots: settings_code.append(DISABLE_SCREENSHOT_CODE) offline_screenshots = self._get_setting( context, "snapengage_offline_screenshots", "SNAPENGAGE_OFFLINE_SCREENSHOTS", True ) if not offline_screenshots: settings_code.append(DISABLE_OFFLINE_SCREENSHOT_CODE) if not context.get("snapengage_proactive_chat", True): settings_code.append(DISABLE_PROACTIVE_CHAT_CODE) sounds = self._get_setting(context, "snapengage_sounds", "SNAPENGAGE_SOUNDS", True) if not sounds: settings_code.append(DISABLE_SOUNDS_CODE) button_effect = self._get_setting(context, "snapengage_button_effect", "SNAPENGAGE_BUTTON_EFFECT") if button_effect is not None: settings_code.append(BUTTONEFFECT_CODE % button_effect) button = self._get_setting(context, "snapengage_button", "SNAPENGAGE_BUTTON", BUTTON_STYLE_DEFAULT) if button == BUTTON_STYLE_NONE: settings_code.append(INIT_CODE % self.widget_id) else: if not isinstance(button, int): # Assume button as a URL to a custom image settings_code.append(SETBUTTON_CODE % button) button_location = self._get_setting( context, "snapengage_button_location", "SNAPENGAGE_BUTTON_LOCATION", BUTTON_LOCATION_LEFT ) button_offset = self._get_setting( context, "snapengage_button_location_offset", "SNAPENGAGE_BUTTON_LOCATION_OFFSET", "55%" ) settings_code.append( ADDBUTTON_CODE % { "id": self.widget_id, "location": button_location, "offset": button_offset, "dynamic_tail": ",true" if (button == BUTTON_STYLE_LIVE) else "", } ) html = SETUP_CODE % {"widget_id": self.widget_id, "settings_code": " ".join(settings_code)} return html
def render(self, context): settings_code = [] domain = self._get_setting(context, 'snapengage_domain', 'SNAPENGAGE_DOMAIN') if domain is not None: settings_code.append(DOMAIN_CODE % domain) secure_connection = self._get_setting(context, 'snapengage_secure_connection', 'SNAPENGAGE_SECURE_CONNECTION', False) if secure_connection: settings_code.append(SECURE_CONNECTION_CODE) email = context.get('snapengage_email') if email is None: email = get_identity(context, 'snapengage', lambda u: u.email) if email is not None: if self._get_setting(context, 'snapengage_readonly_email', 'SNAPENGAGE_READONLY_EMAIL', False): readonly_tail = ',true' else: readonly_tail = '' settings_code.append(SETEMAIL_CODE % (email, readonly_tail)) locale = self._get_setting(context, 'snapengage_locale', 'SNAPENGAGE_LOCALE') if locale is None: locale = translation.to_locale(translation.get_language()) settings_code.append(SETLOCALE_CODE % locale) form_position = self._get_setting(context, 'snapengage_form_position', 'SNAPENGAGE_FORM_POSITION') if form_position is not None: settings_code.append(FORM_POSITION_CODE % form_position) form_top_position = self._get_setting(context, 'snapengage_form_top_position', 'SNAPENGAGE_FORM_TOP_POSITION') if form_top_position is not None: settings_code.append(FORM_TOP_POSITION_CODE % form_top_position) show_offline = self._get_setting(context, 'snapengage_show_offline', 'SNAPENGAGE_SHOW_OFFLINE', True) if not show_offline: settings_code.append(DISABLE_OFFLINE_CODE) screenshots = self._get_setting(context, 'snapengage_screenshots', 'SNAPENGAGE_SCREENSHOTS', True) if not screenshots: settings_code.append(DISABLE_SCREENSHOT_CODE) offline_screenshots = self._get_setting( context, 'snapengage_offline_screenshots', 'SNAPENGAGE_OFFLINE_SCREENSHOTS', True) if not offline_screenshots: settings_code.append(DISABLE_OFFLINE_SCREENSHOT_CODE) if not context.get('snapengage_proactive_chat', True): settings_code.append(DISABLE_PROACTIVE_CHAT_CODE) sounds = self._get_setting(context, 'snapengage_sounds', 'SNAPENGAGE_SOUNDS', True) if not sounds: settings_code.append(DISABLE_SOUNDS_CODE) button_effect = self._get_setting(context, 'snapengage_button_effect', 'SNAPENGAGE_BUTTON_EFFECT') if button_effect is not None: settings_code.append(BUTTONEFFECT_CODE % button_effect) button = self._get_setting(context, 'snapengage_button', 'SNAPENGAGE_BUTTON', BUTTON_STYLE_DEFAULT) if button == BUTTON_STYLE_NONE: settings_code.append(INIT_CODE % self.widget_id) else: if not isinstance(button, int): # Assume button as a URL to a custom image settings_code.append(SETBUTTON_CODE % button) button_location = self._get_setting(context, 'snapengage_button_location', 'SNAPENGAGE_BUTTON_LOCATION', BUTTON_LOCATION_LEFT) button_offset = self._get_setting( context, 'snapengage_button_location_offset', 'SNAPENGAGE_BUTTON_LOCATION_OFFSET', '55%') settings_code.append( ADDBUTTON_CODE % { 'id': self.widget_id, 'location': button_location, 'offset': button_offset, 'dynamic_tail': ',true' if (button == BUTTON_STYLE_LIVE) else '', }) html = SETUP_CODE % { 'widget_id': self.widget_id, 'settings_code': " ".join(settings_code), } return html
def test_custom_username_field(self): get_id = get_identity(Context({}), user=MyUser(identity='fake_id')) self.assertEqual(get_id, 'fake_id')
def render(self, context): settings_code = [] domain = self._get_setting(context, 'snapengage_domain', 'SNAPENGAGE_DOMAIN') if domain is not None: settings_code.append(DOMAIN_CODE % domain) secure_connection = self._get_setting(context, 'snapengage_secure_connection', 'SNAPENGAGE_SECURE_CONNECTION', False) if secure_connection: settings_code.append(SECURE_CONNECTION_CODE) email = context.get('snapengage_email') if email is None: email = get_identity(context, 'snapengage', lambda u: u.email) if email is not None: if self._get_setting(context, 'snapengage_readonly_email', 'SNAPENGAGE_READONLY_EMAIL', False): readonly_tail = ',true' else: readonly_tail = '' settings_code.append(SETEMAIL_CODE % (email, readonly_tail)) locale = self._get_setting(context, 'snapengage_locale', 'SNAPENGAGE_LOCALE') if locale is None: locale = translation.to_locale(translation.get_language()) settings_code.append(SETLOCALE_CODE % locale) form_position = self._get_setting(context, 'snapengage_form_position', 'SNAPENGAGE_FORM_POSITION') if form_position is not None: settings_code.append(FORM_POSITION_CODE % form_position) form_top_position = self._get_setting(context, 'snapengage_form_top_position', 'SNAPENGAGE_FORM_TOP_POSITION') if form_top_position is not None: settings_code.append(FORM_TOP_POSITION_CODE % form_top_position) show_offline = self._get_setting(context, 'snapengage_show_offline', 'SNAPENGAGE_SHOW_OFFLINE', True) if not show_offline: settings_code.append(DISABLE_OFFLINE_CODE) screenshots = self._get_setting(context, 'snapengage_screenshots', 'SNAPENGAGE_SCREENSHOTS', True) if not screenshots: settings_code.append(DISABLE_SCREENSHOT_CODE) offline_screenshots = self._get_setting(context, 'snapengage_offline_screenshots', 'SNAPENGAGE_OFFLINE_SCREENSHOTS', True) if not offline_screenshots: settings_code.append(DISABLE_OFFLINE_SCREENSHOT_CODE) if not context.get('snapengage_proactive_chat', True): settings_code.append(DISABLE_PROACTIVE_CHAT_CODE) sounds = self._get_setting(context, 'snapengage_sounds', 'SNAPENGAGE_SOUNDS', True) if not sounds: settings_code.append(DISABLE_SOUNDS_CODE) button_effect = self._get_setting(context, 'snapengage_button_effect', 'SNAPENGAGE_BUTTON_EFFECT') if button_effect is not None: settings_code.append(BUTTONEFFECT_CODE % button_effect) button = self._get_setting(context, 'snapengage_button', 'SNAPENGAGE_BUTTON', BUTTON_STYLE_DEFAULT) if button == BUTTON_STYLE_NONE: settings_code.append(INIT_CODE % self.widget_id) else: if not isinstance(button, int): # Assume button as a URL to a custom image settings_code.append(SETBUTTON_CODE % button) button_location = self._get_setting( context, 'snapengage_button_location', 'SNAPENGAGE_BUTTON_LOCATION', BUTTON_LOCATION_LEFT) button_offset = self._get_setting( context, 'snapengage_button_location_offset', 'SNAPENGAGE_BUTTON_LOCATION_OFFSET', '55%') settings_code.append(ADDBUTTON_CODE % { 'id': self.widget_id, 'location': button_location, 'offset': button_offset, 'dynamic_tail': ',true' if (button == BUTTON_STYLE_LIVE) else '', }) html = SETUP_CODE % { 'widget_id': self.widget_id, 'settings_code': " ".join(settings_code), } return html