Beyond mobile tracking with Firebase Cloud Functions!

Anaïs Ghelfi
Google Cloud - Community
3 min readSep 17, 2017

At my company, analytics data is used by a lot of teams across the company to:

  • Optimise paid marketing campaigns
  • Provide a unique user experience

On the web, we are adapting the tracking and pixels ‘small snippets to collect and send information about the visitor and his browsing’ according to the team expectations across the board. We are using Google Tag Manager which gives us a lot of flexibility to modify/enrich and send the data to our dozens of marketing partners.

How we pulled out our hair with the mobile tracking …

When we have launched our mobile application early this year, we were using the Firebase SDK + Google Tag Manager for internal analytics purposes and we quickly realised the pixel integrations needed to be done from the app-side using tons of different SDKs ‘Software Development Kit’.

Then, Google released Firebase Cloud Functions

Firebase allows you to deploy NodeJS functions on their servers and those functions can be triggered based on different events such as Firebase Analytics functions.

Amazing! We are already using Firebase to send data to Google Analytics.

Then, we decided to build an in-house solution with Cloud Functions to centralise everything: Octopus.

About Octopus

To briefly explain what Octopus does.

Based on analytics events: add to cart, sign in … Octopus can enrich/modify and send the data wherever we want without relying on app release or SDK integration.

Build to be simple with Cloud Functions

Our index.js contains all the functions Firebase will trigger based on analytics events. You can enrich your data with all the sources you want, for us it’s our CRM API.

To breakdown what’s happening, the functions are:
1. Getting the event payload from the apps in real-time
2. Enriching the data
3. Passing the data to the relevant tags (sub-functions)

Each “tag” maps the input data with the output format required.

Let’s take a look at the sign_in Google Analytics tag.
Below, we are filling the event information for the Sign In event the team will find in Google Analytics.

To finish, we have a generic function to send the data to Google Analytics using the Measurement Protocol.

Conclusion

Moving the tracking from the app-side to Firebase side reduced drastically the time spent on the pixel tracking integration and helped us leverage the mobile tracking.

Speed up the integration time by 3!

From 7 to 3 steps in the integration process.

Live deployment: Any changes can go live without involving our mobile developers and waiting for app releases

Firebase Playground

Data consolidation: Before, we had two Google Tag Manager containers to maintain (1 for Android and 1 for iOS). Now, we have the same code running on Cloud Functions for the two mobile applications.

Data enrichment: We can shape the data before dispatching it.

Serverless, serverless and serverless …

The Cloud Functions environment is fully managed by Google.

--

--