Android Quickstart With Google Analytics For Firebase And Google Tag Manager

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello my friends I am back with another video lounging on the couch and just talking to you about Google Analytics and firebase analytics and Android applications so this video will be a walkthrough of how to set up your own Android application using either a virtual device or your plugged in USB Android phone and the purpose of this video is to show you how to install firebase in your application how to get firebase analytics up and running how to integrate firebase as base analytics into the Google Analytics UI and finally how to install GTM as well if you want to collect two other tags as well using Google tag manager as the dependency so we'll be walking through all those steps and hopefully after watching this video and reading the accompanying article you'll be able to add firebase to your projects yourself and thus be able to make use of the new app plus web measurement paradigm introduced by Google a while ago so enjoy the video and I'll see you soon in the walkthrough we will be using Android studio and I'll show you how to set it up to build an extremely simple demo application which basically has nothing else than just a hello world text so we'll actually be using the default application that Android studio ships with when you create a new project you will be adding things like firebase dependencies Google services and we'll also add Google tag manager for good measure and then you'll be able to once you've finished you'll be able to see your hits in the debug view they will also be collected into the analytics dashboard at some point once they finally come through to the reports and then you will also be able to see how those hits are being sent to Google Analytics so you can see that there are there will be Google Analytics hits will configure at Google Analytics tag in the container to send hits to GA when any events happen in the Android application so this is what we'll be working on it will start from scratch so I'll just reset my environment and that will get started to get started you'll need Android studio so head over to developer.android.com - studio and download android studio for your computer I'm going to be using the OS X version the Mac version so these examples will be done on a Mac Mac computer macbook they should be the equivalent if you're running this on a Windows computer or Linux computer or whatever so once you've downloaded Android studio you can open it up and it will ask you will show you a screen like this so choose to create a new Android studio project we'll be creating an empty activity because the whole purpose of this application is just to show you how to install firebase you can of course use something else so you can integrate this into your existing app that doesn't matter but we'll be using empty activity just to get things started to go fast give the application a name and it will also get a package name you can you can change that if you want but it should be something that's easy to type because you'll you'll need to add this add this to a couple of places once you have firebase and Google tag manager implemented make sure the location you're trying to add it to exists so I'm adding it to a folder called Android test and this has to exist in your filesystem for for the studio to be able to create the application folder keep Kotlin as the language check the use Android X artifacts because the current version at the time of creating this video the current version of Google services doesn't seem to work without these enabled once you're done you can click finish and you'll see your application being built and synchronized so you have your Gradle files synchronized and so on I'll get but I'll tell you soon what all these things are this is your main view you can switch it to the project view which might make it easier to understand the whole thing and now you can click the play button in the in the top in the header and if you have a USB device you could Android a phone and a USB cable you can add the Android phone with the USB cable to your computer and you should see it under the connected devices so you can essentially debug your applications on an actual Android phone well I don't have an Android phone at hand right now so I'm just gonna use a virtual device so create a new virtual device choose the model let's do let's do a Nexus 5 for good measure then you'll need to choose the operating system so just choose any one with a pretty recent API level it doesn't really matter because the application works on on an API level of 19 plus I'm using Pi you'll need to download the OS if you want to create a virtual device with it so it's a pretty hefty download but I'm using Pi and I've already downloaded so just click Next you gonna give the AVD some name like um Simo 2 and then click finish and it's gonna create the device and then you'll find it in the available virtual devices list so choose the device you created and click OK and down here in the footer of Android studio you'll see what it's trying to do at the moment so currently it's it's loading the operating system and it's waiting for the operating system to load waiting for the target device to come online and as soon as it does it will next create and install the apk or the application package and once the apk has been installed it will run the application and you should see your hello world text pop up in the in the phone window if you're using a USB device you'll see it in your phone window right now so if you see hello world world here congratulations you've built your first Android application or maybe it's not your first one but congratulations anyway alright so we can now stop the emulator and now the next thing to do is to add firebase so go to consult firebase google.com so click to create a project choose a name for the project let's go with test project you'll see the the project ID here and this is what the cloud project will be created with so that's okay setup Google Analytics for my project let's choose an existing Google Analytics account so this is the account that will be created if you don't yet have a Google Analytics account so by creating this you're not actually creating a Google Analytics like the regular GA for web and apps that you're used to you're actually creating a firebase Analytics account in your GA user interface so you're surfacing your firebase analytics data over there and this is kind of part of the new app and web paradigm that Google Analytics has recently published so anyway let's create our project now you'll see the loader so this will take a while so grab my grab a coffee or something while you're waiting right and now it tells me my new project is ready so click continue when you're happy with that next thing you need to do is add firebase to your apps so choose the little Android dude over here give the package name so the package name you'll find in your in your application in the Java directory you'll see what the package name is so it's comm dot example don't - that test application this is what you'd configure when you created the created the project in the first place so then let's add the my test application ethnic named semo's test application this is just what the application will show up in the firebase console last so if you want to give it some nice nickname you can do that register the application then it will tell me to download the config config file which is a Google services JSON file so download that and then in your application Android studio you'll need to add the file into the app directory so I'll just drag and drop it from my browser to the app directory like this so now you've had it the Google services JSON this is just a configuration file that basically establishes the firebase credentials for this project so everything all this kind of authentication stuff is done for you which is really nice and handy once you've done that click Next now we will tell you to add the firebase SDK so first of all you'll need to find the project level build.gradle file so this is where you will add your project level dependencies so you'll find it underneath your project you open the main folder and there's a Gradle build of Gradle Dahl file it looks like this there are two important Gradle files in your project the first one is to build Gradle in the project group and the second one is to build Gradle in the application roof so in the app folder now you'll need to edit the project level build.gradle there's a dependencies object here so at the end of dependencies you will need to copy the class path for Google services and you just keep it in its point to put zero version or whatever firebase suggests for you you don't have to upgrade it for the purposes of this but at some point you'll want to upgrade it don't click the sync now yet it doesn't it doesn't make sense for now because now you'll need to edit the application level build up Gradle file which you'll find in the app folder and here's another dependencies block so then you will copy the implementation dependency and you'll add it here again it's gonna tell you there's a newer version well you don't have to worry about that for now and then to the bottom of the file you need to add the plug-in plug-in the link like this so now you've added your updated your dependencies to include firebase so now you'll need to synchronize the Gradle so click sync now and it should run pretty smoothly without any any errors so green checkmarks throughout if you see errors well my suggestions just googled those errors and see what you find because there might be some problems if for example if you try to use a the latest version of firebase it might have conflicts with your other dependencies so you'll need to make sure that you find a good match of versions that won't break your setups once you've added these it's gonna tell you you need to run your application to verify installation so you'll need to basically run the app so that it communicates with the firebase servers and tells firebase that everything is running so click the play button up here choose your virtual device and it's gonna install the latest application load the dependencies and run the application and then you see in firebase that the application has communicated with the firebase server so let's see what happens we run the application then we go to firebase and now we'll just wait for this to turn into a green checkmark and here we go congratulations you've successfully added firebase to your app so that we can go to the console and once you start using firebase you'll see these analytics events running under the analytics menu but we haven't added any analytics events yet so that's the next thing we're gonna do so now we'll need to add some code that will start collecting firebase analytics events so the first thing you'll need to do is find your main activity you'll find it in your application deep in the root or deep inside the folder structure but it's basically under the application SRC main Java and then your application you can quickly find it if you choose Android over here it's it's a bit faster to find it like that so this is your main activity and this represents the in an Android here you're using activities so activities basically represent different types of views and different types of things that can be done on the application so the main activity is what's run when the application is first executed and this is where you'll need to initialize your your firebase installation as well so we'll start by creating a variable for the firebase instance like this far base analytics and then you want to load the firebase analytics dependency so you'll once you start typing it will give you a list of all the firebase analytics items so click tab click the tab key once you have firebase analytics selected from this list because that will automatically add the dependency as an import statement it's a really nice feature of Android studio so once you've initialized as you're using the late in it because you need this is basically a constructor patterning in Cortland but you don't yet have firebase analytics dependency loaded that you could initialize this with so you're using the late in it to tell Cortland that hey I'm gonna give initialized this variable a bit later but I want to use it on the activity level so then inside your your oncreate method you'll just add a little room here so here we'll it will actually initialize it so we'll take the firebase analytics and tell that let's initialize it as an instance of the firebase Analytics let's go since it's singleton with the get instance and the context is basically this so that you're you're passing the the context of the main activity of the application to the firebase analytics this is how you initialize firebase you don't have to worry about it too much and then what we can do is we can actually just send a custom event so let's send a custom kind of screen view event so let's let's when you want to send an event you'll basically do a firebase analytics dot log event it will take the event name as the first parameter and you can actually use an you know enumerated item for this so under firebase analytics you'll have the param property and under param you'll have all these built-in event names so let's choose select content sorry I'm sorry I'm in the wrong place so you'll need actually you'll need to use another enum which is the event not the param so we'll use event which is a list of all the event names that you have access to that kind of standard event names so let's choose select content as the event name and then it takes parameter list as the second parameter so let's create a parameter we'll use android zone bundle which is basically just a list of items key value pairs like a plain object in JavaScript we'll put some items into it so put string is what we'll use and now it takes the key name as the first item so this would be this could be something like my parameter but we can again use the default parameters so now we'll look for firebase analytics dot param and let's do item ID and we can set this to some tests for example and then we'll pass that as the second parameter off the log event calls so now we're logging an event with the name select content and with bundle of key value pairs where there's just a single key item ID and value sum test now to see what happens in firebase you'll need to add some logging so we'll need to load some logging capabilities in firebase and I'll show you how to do that so go to firebase google.com - knocks - analytics - Android - start so just look for like firebase getting started guide quote Android and then copy these three commands that you see over here then in Android open the terminal so click the terminal down here in Android studio and just paste the commands here oh yeah you'll need to actually run your emulator first so let's let's run this application in an emulator so click the play button again and choose your emulator once you've had it firebase to the application and now you can add those commands and press ENTER and now you'll see this is basically a log of the firebase tasks that are being sent to firebase so now you can see that there's an event recorded with the name select content so that's our event with some parameters which is a bundle with item ID equals some tests so this is how firebase basically works there's some automatic screen view tracking going on as well so firebase actually automatically tracks the screen view and you'll find these in the stream you in the stream view of your firebase so you'll usually be able to see your your item here item over here in the street view so this is how you'll you'll be able to check how these so you'll be able to you know verify that everything is working by checking the stream you for your project but then we might want to see it in the debug view as well so you need to actually configure your device your virtual device as a debug device you need to tell Android that hey this devices allowed us in debug hits so for that we'll need to find a way to do debugging so you can actually find it in these same instructions enabling debug mode so just copy this line and then in the Android shell so you can actually stop with sup this with control C that will halt - halt beyond debugging you could do adb shell you can paste the command here and instead of package name you your package name SOCOM example my test application so now you've registered your virtual device which is running here in the background you've registered this as a debug device so now when you run the application I'll just reset it and you can run this logcat line again so look at - we time - as fa fa SVC your application is now running over here there's gonna be some debug debug data as well but now you'll be able to find your application data in the debug view as well so here's the here's your virtual device sending these hits and you can see your select content with the item ID of some tests so this is how you run firebase analytics through your app and from this it just gets more you could get us complicated as you want you can start creating your own modules create your own complicated firebase analytic stuff it's a good idea to just keep tabs on the on the firebase analytics documentation which is pretty solid obviously a lot of stuff stuff missing as usual but you can always find your firebase analytics itself is pretty rudimentary at the moment so there's not that much to even document but you can find how to set things like user properties and so on but the way in Android that things work is you have you create this instance or you get an instance of the firebase analytics singleton and you start using it to sending events so you can load up load the firebase in other activities as well by remembering to initialize it with the current instance with the current context of the application and then you just run these log event commands sending a bundle as parameters so what if we want to add Google tag manager to our Android Android firebase application next so we might want to use GTM to send some data to Google Analytics as well or maybe use some other tags in GTM for firebase so next thing you'll need to do is head on over to Google tag manager and create a new create a new container let's do my tests application again choose Android ask the container type and then create a new container let's create a new tag here as well so choose a tag create Google Analytics Universal analytics keep screaming you as it no actually let's send an event test event sorry test category now we can add as the action let's add our item ID so I want to fire this tag when the select content event fires so let's put our item ID over here so parameter item ID event parameter and then you'll just look for the event parameter in the suggested events list there's an item ID over here so we'll use that one and that should be now sent as the action of the hit and then just choose a tracking ID I'll choose my all-time favorite one and then we can create an event for firebase which would be a custom event because there's no event for select content over here and I can actually just have this fire in all events just for good measure which doesn't make sense because there actually is an all events trigger here so let's just use that one instead so we're just have this fire in all events just so that I can show you how the GTF stuff works so once you're done save the tag publish the workspace or the container and then it's going to give you a download link here so click download to download this container it's going to be a JSON file like this so the next thing is really important you need to add this container to the correct so you will need to add a new directory under your main folder so right click and click new if it doesn't already exist that means so the director name is assets under assets you'll create one more directory called containers and then you'll drag the container JSON to that containers folder and now you can test the application again so let's see if it manages download a one thing of course one thing that we forgot to do is we need to actually load Google tag manager as a dependency so we need to edit our Gradle file again so go to your app builder cradle and down here at implementation calm Google Android GMs Play services tag manager and then 17 point 0.01 to make sure that it matches the firebase core just so that they don't go out of sync then you can just sync the Gradle file so that's done now and now once you've added the GTM dependency to Android studio now you can click to play thee and now you can open the terminal or actually you can open the logcat file so logcat is basically a log of all your events running in GT running in firebase so you can look for a Google tag manager here and you should see the following lines it's loading the container it's installing event handlers and so on so then it says that's something is something is happening so we'll need to see if it actually sends anything to analytics so you'll see that Google Analytics is starting up then he tells you that hey the set logger is deprecated to enable debug logging police run this adb commands so copy this command over here go to terminal and paste it here so now we've enabled Google Analytics logging for our app so now we can just actually rerun the application you'll see that some hits but have been sent to the analytic service for delivery so let's see if we can looking for your UA ID you'll see that a hit delivery has been requested with the application name my ad load test application there's the there's the events so test category some test which is your value of your item ID parameter if you remember non interaction falls UA 1 2 3 4 5 - 1 and so on and actually just to clarify so the two times that it runs is that because I had every event I had GA tag firing for all events there's actually three firebase events that take place there's the screen view event and there so I think the first open or or user engagement or something like this so the tag has actually fired three times but it's only fired once for the log event command because that's the only place where we have the item ID included so these values don't persist from one event to the other if you want to have item ID in your events you have to have it in every single one of your log event calls if you want things to persist you'll actually have to use user properties so anyway now you can see that the Google Analytics is working as well I don't have access to this you a one two three four five - one so I can't show you but you can just trust that it is actually working as it should so we're about done here we've created our Android application it's running in our virtual device it's sending data to firebase analytics and it's sending data to Google Analytics using Google tag manager we've installed all the dependencies and now it's just up to you how to keep on building this application upgrading it to an app plus web property and just you know combining all this stuff I'm just doing good analytics for your mobile applications thank you very much for your attention
Info
Channel: Simmer – Online Courses In Technical Marketing
Views: 28,186
Rating: undefined out of 5
Keywords: google analytics, firebase, google tag manager, guide
Id: brPF0qRvcLU
Channel Id: undefined
Length: 26min 59sec (1619 seconds)
Published: Mon Aug 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.