3

I am using telescope for may blog application and i able to configure google analytics by telescope admin setting. now we wanted to configure Google Tag Manager but we not able to figure out how to configure GTM with telescope. we found one addon "https://github.com/GorillaStack/meteor-iron-router-gtm" it allowed to configure GTM in meteor but its based on iron router but telescope using flow-router..

can some one please help us to configure GTM with telescope ..

jayesh
  • 2,422
  • 7
  • 44
  • 78

1 Answers1

5

this is work for me adding code to client.js in project

if(Meteor.isClient){
FlowRouter.triggers.enter( [ enterFunction ] );
FlowRouter.triggers.exit( [ exitFunction ] );
  function enterFunction() {
    $('body').append("<noscript id='gtmnoscript'><iframe src=\"//www.googletagmanager.com/ns.html?id=GTM-XXXXXX\" height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript><script id='gtmscript'>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>")
  }

  function exitFunction() {
    $('#gtmnoscript').remove();
    $('#gtmscript').remove();
  }
}
jayesh
  • 2,422
  • 7
  • 44
  • 78
  • I know I should avoid comments like "thanks", but this little snippet just saved my ass. Many thanks. To to contribute a little, I am using Meteor 1.3 and pasted it inside lib/routes.js out of the Meteor.isClient condition and it worked ok. – Brunno Vodola Martins Apr 19 '16 at 21:21
  • Hello, I was wondering if we could avoid doing this everytime the route changes (with triggers) ? Is it able to append it only for the layout, which charge the code once. Well as it happes only on client, I think it is not a big deal but still... – roro_57 Nov 13 '17 at 09:22