3

I would like to use intercom in my angular 2 application.

Intercom SPA instructions are here

I have placed the script block in the head of my index.html page, my next thought is to place the following in my app component

ngOnInit()
{
    window.Intercom("boot", {
app_id: "abcd",
name: "Jane Doe", // Full name
email: "customer@example.com", // Email address
created_at: 1312182000 // Signup date as a Unix timestamp
});

However, it wont compile saying [ts]

Property 'Intercom' does not exist on type 'Window'.

How do I get this to work using Angular2 and webpack and proceed further?

Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39

4 Answers4

4

I have found the answer to integrating intercom with angular 2

Update intercom instructions for angular 2 Instead of this:

 window.Intercom("boot", {
    app_id: "abcd",
    name: "Jane Doe",
    email: "customer@example.com", 
    created_at: 1312182000 
    });

Use this to make it work:

(<any>window).Intercom("boot", {
app_id: "abcd",
name: "Jane Doe", 
email: "customer@example.com",
created_at: 1312182000 
});
  • Thanks Marcus, saved my day! Do you also run (window).Intercom("update"); on ngOnInit() of evey router outlet component? – cyberabis Mar 06 '17 at 10:58
1

I'm happy to inform you that there is an NPM module just for this! It's available here. https://www.npmjs.com/package/ng-intercom

The latest version also has more Intercom methods and directives to make your life easier! Docs are here: https://github.com/CaliStyle/angular2-intercom/tree/1.0.0-alpha

Read the Medium post: https://medium.com/@wilsonhobbs/integrating-intercomjs-with-your-angular-app-with-ngintercom-da38b8bcd415

wilsonhobbs
  • 941
  • 8
  • 18
0

My name is Martin I'm one of the Customer Support leads at Intercom. Came across this question.

That error looks like the Intercom Library isn't loading. Have you included this script somewhere else in your code. Switching {app_id} with your apps app_id? Is it definitely being called?

(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{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://widget.intercom.io/widget/{app_id}';
    var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()

If you have, and it is, yet you are still seeing this issue, it might be best to drop onto Intercom and get in touch via our messenger in the bottom right hand corner. Or send an email to team@intercom.io and we can follow up with you there!

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • Hi Martin, this question is specifc to angular 2, it is a compile error and really about how to reference and access this script in angular 2. I have contact intercom support and they have no help or examples beyond the SPA instructions listed in my question, to answer you question yes i am using my appid and i cant call the function. – Marcus Diamond Jul 18 '16 at 02:20
0

You can declare window as: declare let window:any;

and then just use window.Intercom normally: window.Intercom('update');