ErickTamayo / fuse-google-analytics

Native Google Analytics integration in Fuse.
MIT License
8 stars 3 forks source link

fuse-google-analytics - Beta

Software License

This is the integration of the native iOS and Android bindings for Fuse of Google Analytics.

The current Firebase Analytics doesn't have real time analytics. This package is intended to be able to satisfy the need to register pageviews and events of your Fuse Application in the easiest possible way.

Contents

Usage

Using the Javascript API

var GoogleAnalytics = require("Google/Analytics");

module.exports.ScreenView = function() {
    GoogleAnalytics.ScreenView("App-JS");
};

module.exports.TrackEvent = function() {
    GoogleAnalytics.TrackEvent("js_action", "button_press", "play", "0");
};

Using as TriggerActions in the UI

<GAPageView Page="App-UI"/>
<GATrackEvent Category="ui_action" Action="button_press" Label="play" Value="0"/>

As in

<Button Height="50" Width="300" Background="Black">
    <Clicked>
        <GAPageView Page="App-UI"/>
    </Clicked>
    <Text TextAlignment="Center" Alignment="Center" Color="White">Generate Screenview From UI</Text>
</Button>
<Button Height="50" Width="300" Background="Black">
    <Clicked>
        <GATrackEvent Category="ui_action" Action="button_press" Label="play" Value="0"/>
    </Clicked>
    <Text TextAlignment="Center" Alignment="Center" Color="White">Track Event From UI</Text>
</Button>

Prerequisites

iOS

You need to have CocoaPods installed for iOS

Android

You need to have Google Play Services library installed in your Fuse installation here is a guide to do so.

AnalyticsExample Project

This project contains the basic implementation to make the Google Analytics integration work. Some of these files should be in the same directory as the project that you want integrate Google Analytics. The functions of the files are the following:

AnalyticsExample.unoproj

This file contains the configuration of the project. To make analytics work, you must add the bundle identifier and the package. This needs to be the same as your Google configuration file (google-services.xml for Android and GoogleService-Info.plist for iOS). How to get the Google configurations files will be explained later.

Included Google Analytics Project

  "Projects": [
    "../Google.Analytics/Google.Analytics.unoproj"
  ],

Configured BundleIdentifier and Package

"iOS": {
    "BundleIdentifier": "com.ericktamayo.example"
},
"Android" : {
    "Package" : "com.ericktamayo.example"
}

Also, you must include the GoogleService-Info.plist in the file.

"Includes": [
    "*",
    "GoogleService-Info.plist:ObjCSource:iOS"
],

google-services-xml-gen.php

This php file converts the google-services.json in google_services.xml. The reason of this is because in normal circumstances this file should just be copied instead of converting, but theres a known issue that with the current Gradle version that Fuse uses to build the project is not being able to run the task to make it the app to be able to read it, so we do that for Gradle :).

The bug: https://code.google.com/p/analytics-issues/issues/detail?id=939

AndroidImpl.uxl

Basically this file is in charge of copying the google-services.xml file to your Android build directory.

MainView.ux

This file contains how the integration should be used.

Making the AnalyticsExample Work

Note: You must to be able to install the project in an Android or iOS device. The preview won't work on Mac or Windows. The app will still be able to be previewed however, just you won't see anything happening on your Google Analytics Site

Note: for the iOS we asume that you have installed cocoapods, if not refer to https://cocoapods.org/ to install

Setting up the Project on Google Console

iOS

Enabling Google Services for iOS on Google
Setting the .unoproj file
Build your project

Note: CocoaPods the first time will take long downloading the Google Analytics dependencies

When Xcode opens, sign your code and run on your iPhone. You should see 4 buttons for generating the events. Click on them and your Google Analytics account should have activity.

Android

Build and run your project

When the app runs, you should see 4 buttons for generating the events. Click on them and your Google Analytics account should have activity.

License

MIT