Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions intercom/templates/intercom/_intercom_js.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% if email %}
<script>
<script id="IntercomSettingsScriptTag">
var intercomSettings = {
app_id: '{{ app_id }}',
email: '{{ email }}',{% if user_hash %}
user_hash: '{{ user_hash }}',{% endif %}
email: '{{ email }}',
user_id: '{{ user.id }}',
{% if user_hash %}user_hash: '{{ user_hash }}',{% endif %}
custom_data: {{ custom_data|safe }},
created_at: {{ created_at }},
widget: {
Expand All @@ -14,19 +15,6 @@
}
},
};
(function() {
function async_load() {
var s = document.createElement('script');
s.type = 'text/javascript'; s.async = true;
s.src = 'https://api.intercom.io/api/js/library.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent) {
window.attachEvent('onload', async_load);
} else {
window.addEventListener('load', async_load, false);
};
})();
</script>
<script>(function(){var w=window;var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://api.intercom.io/api/js/library.js';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}})();</script>
{% endif %}
38 changes: 19 additions & 19 deletions intercom/templatetags/intercom_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

@register.inclusion_tag("intercom/_intercom_js.html")
def intercom_js(user):
if hasattr(settings, "INTERCOM_APP_ID") and user.is_authenticated():
if hasattr(settings, "INTERCOM_USER_HASH_KEY"):
user_hash = sha_constructor(settings.INTERCOM_USER_HASH_KEY + user.email).hexdigest()
else:
user_hash = None

custom_data = {}
for app in getattr(settings, "INTERCOM_APPS", []):
m = __import__(app + ".intercom", globals(), locals(), ["intercom"])
custom_data.update(m.custom_data(user))

return {
"app_id": settings.INTERCOM_APP_ID,
"email": user.email,
"user_hash": user_hash,
"created_at": int(time.mktime(user.date_joined.timetuple())),
"custom_data": simplejson.dumps(custom_data, ensure_ascii=False)
}
else:
if not (hasattr(settings, "INTERCOM_APP_ID") and user.is_authenticated()):
return {}

if hasattr(settings, "INTERCOM_USER_HASH_KEY"):
user_hash = sha_constructor(settings.INTERCOM_USER_HASH_KEY + user.id).hexdigest()
else:
user_hash = None

custom_data = {}
for app in getattr(settings, "INTERCOM_APPS", []):
m = __import__(app + ".intercom", globals(), locals(), ["intercom"])
custom_data.update(m.custom_data(user))

return {
"app_id": settings.INTERCOM_APP_ID,
"email": user.email,
"user_hash": user_hash,
"created_at": int(time.mktime(user.date_joined.timetuple())),
"custom_data": simplejson.dumps(custom_data, ensure_ascii=False)
}