Add Google Analytics to your apps

  • 28 favourites


2,088 visits, 3,086 views


This tutorial hasn't been translated.



This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

While all of this information is available through the other tutorials and forum comments I wasn't able to find a single document putting it all together the way I needed it.

I used the "Editing your Export.html templates" to figure out how to do this. This method works great if you have only 1 app but I have multiple apps and don't want to change the export files each time I want to export a different app. I'm able to change back and forth between apps and export each of them without leaving the Construct 2 environment provided you setup a unique account or property for each app inside of GA.


copy your tracking code from your Google Analytics account which is generated by GA for your app/site. It should look like this:


(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),



ga('create', 'UA-XXXXXXXX-X', '');

ga('send', 'pageview');


Copy and past the top part of this script into all of your export-XXX.html files located in your Construct 2 program directory and encapsulate it inside your <script> </script> tags.

Should look like this in each of your export files:



(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),




This is the generic GA function that works for all of your apps.


Inside of your event sheet for your Title Page (or any page) add an event: System->On Load Complete or System->On Start of Layout. If you "need" tracking for every single pageview you could put this on specific layouts or specific levels, just keep in mind you are adding additional traffic and processing to your app.


Add an Action to your new event: Browser->Execute javascript. Now paste the second part of your GA javascript into the window. It should look like this:

"ga('create', 'UA-XXXXXXXX-X', 'auto');

ga('send', 'pageview');"

with the quotes. This is where you should have your unique UA-X number for each one of your distinct apps.

That's it. I've tested this on HTML5 exports and phonegap and it works. I have not tested on iOS yet because I'm brand new to this and don't have an iphone to test with yet. If I find any problems I'll update this tutorial.

If anybody has anything to contribute please let me know and I'm happy to update this or take it down if somebody has a better method.

Update: CocoonJS is not working, hopefully I'll have a fix for that soon.


  • Order by
Want to leave a comment? Login or Register an account!