Tracking Scene Loads in Google Analytics


#1

@MarkHunte, sure!

Keep in mind, I’m not much of a code guy and I didn’t made this one (someone else on my team did it), but as far as concerns, I’ll try to explain as best as I can.

First, copy and paste the Google code in your HTML Head. (Document Inspector, Edit HTML head button, and paste)
Replace the “YOURGOOGLECODE” and “YOURWEBSITE-DOT-COM” with your data (your google code, and the target website)

These are the two scripts we used .Google provides it right this way for you to copy-paste. Anyway may be safer to use the one that Google gives you, I am not sure if might be details that change depending on country or… Just play safe.

<script type="text/javascript">

	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

	ga('create', 'YOURGOOGLECODE', 'YOURWEBSITE.COM');
ga('send', 'pageview');

</script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'YOURGOOGLECODE']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

Then, write the tracking javascript and name it at your taste. Mine is named “metricas” -you can identify it in the following image. It must be loaded on each scene.

This is the scene tracking script.

_gaq.push(['_trackEvent', 'Scenes', 'Load', hypeDocument.currentSceneName()]);

As said, you must load it on each scene you want to track. In our case, each and every single scene in our hype document. To do so, simply select the scene, go to the Scene Inspector, and load the script on Scene Load. That’s all.

I think that I am not missing any other detail. Let me know if it works for you.

Hope that helps guys!


Google Analytics for Scenes
Left and Right Fixed Navigation
#2

Thanks for sharing this, @DavidA! I’ve moved this into its own thread. There are a a few other Google Analytics tips, in this thread.


#3

Google?! There is no emoji to accurately portray my disgust.

For those that feel the same way, there’s Piwik… http://piwik.org/blog/2012/04/how-to-use-piwik-to-track-mobile-apps-activity-clicks-phones-errors-etc/


#4

So you’re down on Google & jQuery?

Hope we can stay in your good graces a bit longer! :slight_smile:

(Also a fan of Piwik)


#5

I don’t know, is Tumult buying Boston Dynamics… https://www.youtube.com/watch?v=rVlhMGQgDkY …and building scary looking robots? :smile:

To be fair, it seems Google is selling Boston Dynamics and appears to be getting out of the scary robot business. So, that’s a plus. But in general, I’ve had lots of problems with them in the past. It’s hard for me to trust them again.

Lately, I’ve been wondering if it’s worth the extra effort to run Piwik instead of just using Google Analytics. After much thought, I decided to stick with Piwik.

As for jQuery, I think people rely on it too much – instead of just writing some simple JavaScript code.

Website obesity is a problem… http://idlewords.com/talks/website_obesity.htm …and I can’t just keep chasing after the latest framework… https://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks …I still like jQuery, but mainly because it’s a big part of WordPress and Drupal. After what I’ve learned from using Hype, I tend to avoid using jQuery because I don’t need it as much.

If I have a problem with Hype, there it is. By using the software, I became a much better JavaScript developer. So, I don’t necessarily need to use Hype.

Fortunately, I prefer using a graphical user interface. I haven’t seen anything that’s close to competing with Hype. But even if better software does come along, I’d probably still think nice thoughts about Tumult. You care about your customers and have a friendly community. It’s like Stencyl. Even though I don’t really use that software anymore, I’d probably still recommend the software when it makes sense. They have a great community too and the software is a great way to get started with game development.

Also, if you’re worried about this… Free Hype Templates [New “Eclipse” Template] 🌞 …my experiment with Matter.js didn’t go so well. I started learning the API, only to realize how much effort is involved. Even just to specify a background color was too tedious for me. I’m waiting to see if you improve your Physics API. So meanwhile, I’m just taking it easy. I’m a bit burned out on web development right now.


JavaScript and jQuery
(Casey) #6

I’ve successfully integrated this into my project and it works great for tracking Google events. Thanks so much!


(Shannon Rednour) #7

I have my google analytics script in my head, but I’m not understanding how to add the specific event trigger to the scene. I see where I can create a respons “On Scene Load” but do I just paste my code into “Trigger custom behaviors” in the pull down? Or where do I add that?

Thank you


#8

You would add this code as an ‘On Scene Load’ JavaScript function:


(Shannon Rednour) #9

Super helpful. Thank you!


(laggarto) #10

Thanks, just saved my data and analytics!