{"id":4939,"date":"2021-09-29T14:46:15","date_gmt":"2021-09-29T11:46:15","guid":{"rendered":"https:\/\/trackingchef.com\/?p=4939"},"modified":"2022-09-04T17:25:26","modified_gmt":"2022-09-04T14:25:26","slug":"hacking-google-analytics-universal-and-firebase-for-apps","status":"publish","type":"post","link":"https:\/\/trackingchef.com\/google-analytics\/hacking-google-analytics-universal-and-firebase-for-apps\/","title":{"rendered":"Hacking Google Analytics Universal and Firebase for Apps"},"content":{"rendered":"\n

So Google Analytics 4 is out, and quite frankly, is a mess. From missing features to confusing new reports and all the way to the mega-clusterfluff of documentation. This is also paired with a bizarre tech build up and implementation – resulting in a HUGE headache, especially when it comes to app tracking.<\/p>\n\n\n\n

Personally, I advise marketers to refrain from using GA 4 and keep using  your legacy Universal properties as long as you can (vive la resistance!), or at least until GA 4 will mature into a production ready product. <\/p>\n\n\n\n

What should we do in the meantime? <\/h2>\n\n\n\n

The short answer: Hack your way with GTM+Firebase alongside Universal Analytics. Bear with me, I\u2019ll try to explain.<\/p>\n\n\n\n

Let’s assume you have an app that you want to track. You would also like to keep your Universal account as is with all of historical data, events and custom data. But now your reporting infrastructure is set by default to Firebase analytics, which is best configured for GA 4. If you already have data in your Universal Analytics property you probably won\u2019t want to lose it, as it still holds plenty of value for you (not to mention the fact that all your setup is geared towards it).<\/p>\n\n\n\n

Now I know,  you\u2019ve implemented double tracking hoping you\u2019ll figure out a way to work with GA 4, and that someday, maybe, Google will fix all that is missing\/broken. So now you have a Universal Analytics property that\u2019s still running and holds your important data, but in parallel also a GA 4 property that, well, you’re trying to figure out how to work with. <\/p>\n\n\n\n

When it comes to web properties that\u2019s ok, I guess, for now. But what to do with your app accounts? As a GA 360 (premium) user, I have the privilege of still using the old legacy app tags (i.e. the GA SDK), but those are waaaaaaaaaay past overdue to be scrapped, and while Google hasn\u2019t announced exactly when they will sunset them, it’s expected sometime soon (probably during this year). <\/p>\n\n\n

\n
\"\"<\/figure><\/div>\n\n\n

Hacking Firebase into GTM<\/h2>\n\n\n\n

So now your app developers need (and want) to use Firebase for reporting, your GTM needs to use the Firebase tags, and you have both your universal and GA 4 accounts. How to make it all work? I\u2019ll try to explain what I have done and what works for me.<\/p>\n\n\n\n

* The following examples I give are for Android and in Kotlin, but you can see in the documentation how to adjust those to your needs\/programming language\/OS. <\/p>\n\n\n\n

Step 1: Manually set Screenviews<\/h3>\n\n\n\n

In the early days of Firebase, the metric of \u201cscreenviews\u201d was autocollected and controlled by Google. To add insult to injury, they decided to add interstitials and splash screens to the count of  screenviews – so you had way more screenviews than you should (and there was no way to filter out ads from \u201creal\u201d screens). After the community pressured them, Google decided to give developers the option to manually set screen tracking<\/a>. While this option is nice, it doesn’t help us when we want to fit Firebase reporting method to a universal account, so I used the Log Events method<\/a>, treating screenviews as just another event, with the following code:<\/p>\n\n\n\n

firebaseAnalytics.logEvent(“openScreen”) {<\/p>\n\n\n\n

    param(“screenName”, name)<\/p>\n\n\n\n

    param(“screenTitle”, text)<\/p>\n\n\n\n

}<\/p>\n\n\n\n

Now you have something you can work with in GTM. In order for this event to act as your screenview in Universal Analytics it needs to send data to the \u201cScreen Name\u201d field in GA. in order to achieve that we need to take the \u201cscreenName\u201d parameter from the code and parse it to the screen name field. <\/p>\n\n\n\n

Step 2: Set Screen View Tag in GTM<\/h3>\n\n\n\n

After dev have done their part you need to create to the following tag in GTM:<\/p>\n\n\n\n

\"image-3598344\"<\/figure>\n\n\n\n
  1. Set the \u201ctag type\u201d to \u201cGoogle Analytics: Universal Analytics\u201d<\/li>
  2. Set the \u201ctrack type\u201d to \u201cScreen View\u201d<\/li>
  3. Under \u201cGoogle Analytics Settings\u201d set your GA UA number (manually or via a \u201cgoogle analytics settings variable\u201d )<\/li>
  4. Then under \u201cfields to set\u201d enter a field name of \u201cscreenName\u201d with a value of \u201cscreenName\u201d (which you need to create as a variable of \u201cEvent Parameter\u201d type).<\/li>
  5. (optional) Add a screenTitle variable which will be reported to the appropriate custom dimension in your google analytics account. <\/li><\/ol>\n\n\n\n

    * By asking your developer to add more parameters to the openScreen event, you can add any custom data you need via this method.<\/p>\n\n\n\n

    1. Set the trigger to fire on a custom trigger where \u201cEvent Name\u201d is \u201copenScreen\u201d (pro tip – i use \u201cmatches RegEx (ignore case) to catch any errors that can occur on dev side when it comes to naming convention).<\/li><\/ol>\n\n\n\n
      \"image-8063246\"<\/figure>\n\n\n\n

      You should expect to see something like this:<\/p>\n\n\n\n

      \"image-5517799\"<\/figure>\n\n\n\n

       The \u201c11111\u201d is a test value of a screen name and \u201cthis is test\u201d is a test value of a custom dimension (screen title in this case).<\/p>\n\n\n\n

      Step 3: Tracking Events. <\/h3>\n\n\n\n

      Since screenviews are only a small part of the story, we now need to understand how to send events via Firebase and collect them with GTM in order to report them in Universal Analytics, don\u2019t worry it\u2019s simpler than it sounds. <\/p>\n\n\n\n

      We all know that universal events have a pretty rigid structure with their \u201cEvent Category\u201d, \u201cEvent Action\u201d, and \u201cEvent Label\u201d – we simply need to conform to this structure in order for events reporting to work (and you can also add \u201cEvent Value\u201d if your using it for some weird reason). <\/p>\n\n\n\n

      Using the same Log Events method we used for screenviews, all we need is to ask our developer to set the event parameters accordingly and give an event name (same is if you were sending your events to the dataLayer)\u00a0.<\/p>\n\n\n\n

      firebaseAnalytics.logEvent(\"gaEvent\") {\n    param(\"eventCategory\", text)\n    param(\"eventAction\", text)\n    param(\"eventLabel\", text)\n}<\/code><\/pre>\n\n\n\n

      This is the basic code that will help your dev to send the event as you need them for Universal Analytics, you still need to name your values in a way that makes sense to you (i.e. use your current events name set up or a new \u201ccleaner\u201d one if you want to take the opportunity to do some events cleaning).<\/p>\n\n\n\n

      Step 4: Set Events Tag in GTM<\/h3>\n\n\n\n

      Create a new tag just for events as follow:<\/p>\n\n\n\n

      \"image-3526865\"<\/figure>\n\n\n\n
      1. Set the \u201ctag type\u201d to \u201cGoogle Analytics: Universal Analytics\u201d<\/li>
      2. Set the \u201ctrack type\u201d to \u201cEvent\u201d<\/li>
      3. Check the box under the \u201cUse Firebase Events Parameters for Campaign attribution (you can read more here<\/a>)<\/li><\/ol>\n\n\n
        \n
        \"image-2557792\"<\/figure><\/div>\n\n\n
        1. Under each parameter (Category, Action, Label) set it\u2019s matching variable. Use the \u201cEvent Parameter type, then choose \u201ccustom parameter\u201d and enter to  appropriate parameter key.<\/li><\/ol>\n\n\n
          \n
          \"image-7217392\"<\/figure><\/div>\n\n\n
          1. Set a custom trigger where \u201cEvent Name\u201d is \u201cgaEvent\u201d<\/li><\/ol>\n\n\n\n

            There you have it – you now have a Firebase set up reporting to Universal analytics via GTM<\/p>\n\n\n\n

            !!! Most important – don\u2019t forget to publish your tags and test them before production. <\/p>\n\n\n\n

            Step 5: Adding Custom Data \/ Using \u201cUser Property\u201d<\/h3>\n\n\n\n

            In Firebase there are no more \u201ccustom dimension\/metrics\u201d, instead Google gave us something called \u201cuser property<\/a>\u201d which we can use as our custom data. For our case, this method should be used whenever you want to send custom data on your users that isn\u2019t linked directly to a specific event. So if you want to know if a users is logged in or not, or the certain status of page (let\u2019s say an article page is blocked or open) – then you can use the following code:<\/p>\n\n\n\n

            firebaseAnalytics.setUserProperty(“article_status”, blocked)<\/p>\n\n\n\n

            Adding this to your main PV or events tag is simple and easy, just create a variable of \u201cFirebase User Property\u201d type. After setting the user property as a variable, simply add it to your event or main PV tag, the same way you would a \u201cregular\u201d custom dimension in your tag.<\/p>\n\n\n

            \n
            \"image-8710206\"<\/figure><\/div>\n\n\n

            And there you have it – custom data for your app.<\/p>\n\n\n\n

            Final thoughts<\/h2>\n\n\n\n

            While GA4 is still being developed, and migrating all the work you\u2019ve done on your existing Universal Analytics accounts will take some time – it can be helpful to maintain your app data in UA using Firebase and GTM  while still building capacities in GA4 (especially if you’re a 360 user). The need to migrate to Firebase is given but does not mean you also HAVE to migrate to GA4 (for now). Firebase has its limits when it comes to the number of events or user properties you can use, but so does Universal (especially if you’re using a free account). You can read more about the pros and cons of each method and also about the shift from the old GA SDK+GTM to Firebase+GTM in this article by infotrust<\/a>. <\/p>\n\n\n\n

            I call for a rebellion – hack your way to keep universal alive!! At least until such time, GA4 will gain more (and much-needed) features.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"

            So Google Analytics 4 is out, and quite frankly, is a mess. From missing features to confusing new reports and all the way to the mega-clusterfluff of documentation. This is also paired with a bizarre tech build up and implementation – resulting in a HUGE headache, especially when it comes to app tracking. Personally, I […]<\/p>\n","protected":false},"author":6,"featured_media":4947,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,2,39],"tags":[],"_links":{"self":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4939"}],"collection":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/comments?post=4939"}],"version-history":[{"count":6,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4939\/revisions"}],"predecessor-version":[{"id":5376,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4939\/revisions\/5376"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media\/4947"}],"wp:attachment":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media?parent=4939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/categories?post=4939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/tags?post=4939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}