I’ve been playing around with intercom.io recently as a way to track activity in apps and have been very impressed with
Recently we wanted to track page views logged in member, and I thought I’d share how we did it to make this easy for folks in the future.
First off, I installed Code Insert Manager which is a great little tool that lets you add
Then, I went and activated a new code block sitewide, and put this in there:
That pulls the page slug and records it as an event – nice and simple. Thanks to Adrian in the comments below – we added the window.onLoad function into this to make sure this triggers at the right time.
Great post, exactly what I needed it. Just to add some information, if you are using the plugin Intercom for WordPress, the code from the plugin is inserted in the end of the page. Therefore, when you insert the Js code to track the page, it needs to be after the code from the plugin. Making simple, make sure you add the JS tracking code on footer, otherwise you can get an error “unknown variable: Intercom”
Hello, thanks for your tips. Can I also use this way tracking events in intercom?
Of course – if you look at our code, you’ll see all we are really doing is getting the page name and passing it as an event into Intercom. You can pass any value you want – if you need it to be dynamic, you’d just have to switch out the first block of code to get the value you needed. Also, just as a note, these days I’m using Google Tag Manager as a better solution for including the code.
Are you still having success with this in 2018? It doesn’t seem to be tracking events like I expected. Thanks in advance!
Hey Adrian – to be honest I haven’t used this in a couple of years – but.. if you want me to troubleshoot let me know – are you seeing any events tracked? What were you expecting vs what you are seeing?
It’s probably user error. I’m using a header/footer plug-in to place the code snippet just before the body close, but console shows this error now:
Uncaught ReferenceError: Intercom is not defined
at (index):106
Did you install and configure Intercom for WordPress, or do you in some way have Intercom already integrated? It looks like the code you pasted in from my example is calling before you have loaded intercom.
Yeah, I have the official Intercom plug-in installed and working properly. https://wordpress.org/plugins/intercom/
Your script is set just before the body close, but perhaps I need to use a differing plug-in or method here.
I contacted Intercom support and we were able to get it working with a slight tweak to the code. Apparently WordPress loads scripts differently, so this was needed. Thanks for your help!
post_name;
?>
window.onload = function(){Intercom(‘trackEvent’, ‘Page Visit: ‘);}
Hey – I just took a look at your page. If you view source, you’ll see that the page tracking code is loading before the intercom code – so this has something to do with the page load order. the intercom code is probably loaded in wp_footer() – can you place your code after that in the theme template? Or, there may be some way to control plugin load order that doesn’t involve code, but I’m not sure. If you want us to fix this I could get someone to take a look over at https://managedwp.rocks – it would probably cost about $50 US to get it set and running.
Thanks again for your help. Got it working with this slight modification from Intercom support. 🙂
post_name;
?>
window.onload = function(){Intercom(‘trackEvent’, ‘Page Visit: ‘);}