CaliStyle / ng-intercom

Angular 7+ Wrapper for Intercom.com
MIT License
54 stars 46 forks source link

Automatically send update pings when user navigates in the app to simulate page loads #17

Closed flore2003 closed 7 years ago

flore2003 commented 7 years ago

Usually, Intercom track the user on their journey through the app using page loads. However, when using Intercom with a SPA, the user navigation is not automatically recorded, rather, the Intercom JavaScript SDK provides an update method that can be called whenever the URL changes without a real page load to tell Intercom that the user has navigated (https://developers.intercom.com/v2.0/docs/integrate-intercom-in-a-single-page-app)

It would be a nice addition to this library to automatically listen for Router events and send the update pings to Intercom, whenever the user navigates in the app. It would be probably best to make this an optional behavior that can be turned on using some kind of configuration flag.

wbhob commented 7 years ago

I'll work on this today, thanks for the request!

wbhob commented 7 years ago

Released 1.0.0-beta.1 with a new option updateOnRouterChange. Set it to true to automatically handle router events.

scott-wyatt commented 7 years ago

Just a heads up, you nessecarily don't have to log to intercom on a route change in a spa, they watch window.location. Unless you are bypassing the angular routers native functionality to perhaps add something like query strings or something using the navigator and ignoring the history API. Still a cool feature, but it can double log an event, so it's best to use with caution.

flore2003 commented 7 years ago

@scott-wyatt Could you point me to where this is stated? I've looked through the documentation but could not find mention of this behavior.

wbhob commented 7 years ago

Good note @scott-wyatt, can you add that to the docs?

scott-wyatt commented 7 years ago

@flore2003 I was just going through their docs and it says it does require you to send an Itercom.update, which is odd, because I don't do that but still see the current page in intercom despite not doing that in my sample apps. In the plugins code, it looks like it is listening for changes in the browser history API, so it would stand to reason that they are listening to it, but that it is not documented, not their preferred method, or that their documentation may be out of date?

wbhob commented 7 years ago

I think this is just a safe option for those who want to follow the API docs. This is definitely a feature I like having.