Esempio n. 1
0
    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
Esempio n. 2
0
    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'))
        if user_hash_data:
            user_hash = intercom_user_hash(str(user_hash_data))
            if user_hash is not None:
                params.setdefault('user_hash', user_hash)

        return params
Esempio n. 3
0
    def render(self, context):
        user = get_user_from_context(context)
        params = self._get_custom_attrs(context)
        params["app_id"] = self.app_id
        html = TRACKING_CODE % {"settings_json": json.dumps(params, sort_keys=True)}

        if is_internal_ip(context, "INTERCOM") or not user or not user.is_authenticated():
            # Intercom is disabled for non-logged in users.
            html = disable_html(html, "Intercom")
        return html
Esempio n. 4
0
 def render(self, context):
     html = ""
     user = get_user_from_context(context)
     vars = self._get_custom_attrs(context)
     vars["app_id"] = self.app_id
     html = TRACKING_CODE % {"settings_json": json.dumps(vars, sort_keys=True)}
     
     if is_internal_ip(context, 'INTERCOM') or not user or not user.is_authenticated():
         # Intercom is disabled for non-logged in users.
         html = disable_html(html, 'Intercom')
     return html
Esempio n. 5
0
 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
Esempio n. 6
0
 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
Esempio n. 7
0
    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
Esempio n. 8
0
    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
Esempio n. 9
0
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