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
    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
Exemple #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 get_user_is_authenticated(user):
            # Intercom is disabled for non-logged in users.
            html = disable_html(html, 'Intercom')
        return html
    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 get_user_is_authenticated(user):
            # Intercom is disabled for non-logged in users.
            html = disable_html(html, 'Intercom')
        return html
Exemple #5
0
 def _get_visitor(self, context):
     params = {}
     for dict_ in context:
         for var, val in dict_.items():
             if var.startswith('woopra_'):
                 params[var[7:]] = val
     if 'name' not in params and 'email' not in params:
         user = get_user_from_context(context)
         if user is not None and get_user_is_authenticated(user):
             params['name'] = get_identity(context, 'woopra',
                                           self._identify, user)
             if user.email:
                 params['email'] = user.email
     return params
Exemple #6
0
 def _get_visitor(self, context):
     params = {}
     for dict_ in context:
         for var, val in dict_.items():
             if var.startswith('woopra_'):
                 params[var[7:]] = val
     if 'name' not in params and 'email' not in params:
         user = get_user_from_context(context)
         if user is not None and get_user_is_authenticated(user):
             params['name'] = get_identity(
                 context, 'woopra', self._identify, user)
             if user.email:
                 params['email'] = user.email
     return params
Exemple #7
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['created_at'] = int(
                time.mktime(user.date_joined.timetuple()))
        else:
            params['created_at'] = None

        return params
Exemple #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 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