I figured out a way to make this work - it took a little tinkering, but it seems to work great. So, in your app's javascript code block you will want to use the wrapper that gets called anytime a scene is rendered, and then call the google analytics code:
$(document).on('knack-scene-render.any', function(event, scene) {// GOOGLE ANALYTICS
// set variables to be used as the page URL and Title -
// you can customize these using jquery if you want to pull something different than I did.
var pagetitle = $(’.kn-crumbtrail a:first-child’).text()+’ - ‘+$(’.kn-scene h1’).text();
var pageurl = window.location;// this part needs to all be on one line - be sure to replace your ga ID/code
$("#knack-body").append("<script>\n\n(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){\n(i[r].q=i[r].q||).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n})(window,document,‘script’,’//www.google-analytics.com/analytics.js’,‘ga’);\n\nga('create’, ‘UA-XXXXXXXX-X’, ‘auto’);\nga(‘send’, ‘pageview’, {\n ‘page’:’"+pageurl+"’,\n’title’:’"+pagetitle+"’\n});\n\n</script>");});
Please note - you will need to replace the google analytics ID with your own - I changed it to “UA-XXXXXXXX-X” in my sample above.
This code will take the proper URL (with all the query parameters) and send it along, and it makes a title out of the first section on the breadcrumb to give you context for the page name, which it pulls from the H1. On the top level it will include an errant " - " after the section name, but that won’t really affect the usefulness of using Google Analytics. I set the url and title before calling the big ugly string in case you want to customize what gets sent to gA.
I hope someone else finds this helpful.
Benjamin