Native Google Analytics integration in Fuse.
Uno PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
AnalyticsExample
Google.Analytics
LICENSE.md
README.md

README.md

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
  • Visit https://developers.google.com/mobile/add?platform=ios.
  • In the App Name Dropdown you should see listed your Google Project, select it.
  • Write your iOS Bundle, remember, it must be the same that you will put in the .unoproj file. For example com.your.bundlename.
  • Click on Continue to Choose and configure services.
  • Now choose Analytics
  • In the dropdown, choose or create your Analytics account and fill fields with the needed information.
  • After filling out the info and enabling the Service, click on Continue to Generate configuration files
  • Click on Download GoogleService-Info.plist and save the file in the AnalyticsExample directory
Setting the .unoproj file
  • Change the BundleIdentifier to the one you selected configuring the service on Google
Build your project
  • Run fuse build -t=iOS -DCOCOAPODS -adebug

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

  • Visit https://developers.google.com/mobile/add?platform=android.
  • In the App Name Dropdown you should see listed your Google Project, select it.
  • Write your Package Name, remember, it must be the same that you will put in the .unoproj file. For example com.your.packagename.
  • Click on Continue to Choose and configure services.
  • Now choose Analytics
  • In the dropdown, choose or create your Analytics account and fill fields with the needed information.
  • After filling out the info and enabling the Service, click on Continue to Generate configuration files
  • Click on Download google-services.json and save the file in the AnalyticsExample directory
  • In your terminal, in the directory run php google-services-xml-gen.php, a new file should be generated named google_services.xml
Build and run your project
  • Run fuse build -t=android -DGRADLE -run

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