Skip to content

Commit 675e79e

Browse files
AGulevSippul
andauthored
New native (#31)
* Remove FIR cpp SDK (#30) * initial fix * implements ios * add constants * rename constants * fix constants * update docs * update documentation * fix manual * fix log() function on ios * rewrite table for android * android cleanup * implement iOS and add validity check * fix platform name for actions --------- Co-authored-by: Sippul <alex.zelenshikov@gmail.com>
1 parent 844b78d commit 675e79e

31 files changed

+2852
-690
lines changed

.github/workflows/bob.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
build_with_bob_macos:
4444
strategy:
4545
matrix:
46-
platform: [arm64-darwin, x86_64-darwin]
46+
platform: [arm64-ios, x86_64-darwin]
4747
runs-on: macOS-latest
4848

4949
name: Build

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ google-services.xml
1414
dependencies.json
1515
GoogleService-Info.plist
1616
Info.plist
17+
/debug.keystore
18+
/debug.keystore.pass.txt
19+
/manifest.private.der
20+
/manifest.public.der

DEVELOPMENT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
Follow guide in https://github.com/defold/extension-firebase
2+
3+
Download Firebase C++ SDK download link: https://firebase.google.com/download/cpp
4+
Copy `firebase_cpp_sdk/include/firebase/analytics/*.*` to `include/firebase/analytics/` in extension. Make sure new constant registered in Lua.

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
[![Actions Status Alpha](https://github.com/defold/extension-firebase-analytics/actions/workflows/bob.yml/badge.svg)](https://github.com/defold/extension-firebase-analytics/actions)
22

3-
![](https://img.shields.io/badge/Firebase%20CPP%20SDK-8.10.0-green)
4-
![](https://img.shields.io/badge/Firebase%20iOS%20SDK-8.13.0-green)
5-
63
# Firebase Analytics for Defold
74

85
Defold [native extension](https://www.defold.com/manuals/extensions/) that integrates [Firebase Analytics](https://firebase.google.com/docs/analytics) functionality on Android and iOS.

docs/add-dependency.png

107 KB
Loading

docs/index.md

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,64 @@ This extension allows you to interact with Firebase Analytics in a uniform way f
99

1010

1111
## Installation
12-
To use this library in your Defold project, add the following URLs to your `game.project` dependencies:
12+
To use Firabase in your Defold project, add a version of the Firebase extension to your `game.project` dependencies from the list of available [Firebase Releases](https://github.com/defold/extension-firebase/releases) and corresponding [Firebase Config Release](https://github.com/defold/extension-firebase-remoteconfig/releases).
13+
Find the version you want for both extensions, copy the URLs to ZIP archive of the release and add it to the project dependencies.
1314

14-
15-
| Firebase C++ SDK | Firebase iOS SDK | Dependencies |
16-
|-------------------------|-------------------------|--------------|
17-
| Firebase C++ SDK 8.10.0 | Firebase iOS SDK 8.13.0 |[https://github.com/defold/extension-firebase/archive/refs/tags/1.4.2.zip](https://github.com/defold/extension-firebase/archive/refs/tags/1.4.2.zip)<br>[https://github.com/defold/extension-firebase-analytics/archive/refs/tags/2.2.0.zip](https://github.com/defold/extension-firebase-analytics/archive/refs/tags/2.2.2.zip) |
15+
![](add-dependency.png)
1816

1917

2018
## Setup
2119
Follow the [main setup guide for integration of Firebase in Defold](https://www.defold.com/extension-firebase).
2220

2321

24-
2522
## Usage
2623

2724
```lua
28-
function init(self)
29-
-- use firebase only if it is supported on the current platform
30-
if not firebase then
25+
local function firebase_analytics_callback(self, message_id, message)
26+
if message_id == remoteconfig.MSG_ERROR then
27+
-- an error was detected when performing an analytics config operation
28+
print("Firebase Analytics Config error: ", message.error)
3129
return
3230
end
3331

34-
-- initialise firebase and check that it was successful
35-
local ok, err = firebase.init()
36-
if not ok then
37-
print(err)
32+
if message_id == remoteconfig.MSG_INSTANCE_ID then
33+
-- result of the firebase.analytics.get_id() call
34+
print("Firebase Analytics Config instance_id: ", message.instance_id)
3835
return
3936
end
37+
end
4038

41-
-- initialise analytics
42-
firebase.analytics.init()
43-
44-
-- log data
45-
firebase.analytics.set_screen("myscreen", "collection")
46-
firebase.analytics.log_string("character", "storm trooper")
47-
firebase.analytics.log_int("kills", 152)
48-
firebase.analytics.log_number("speed", 1.15)
49-
local t = {
50-
number = math.random(1,100),
51-
boolean = true,
52-
string = "some_string"
53-
}
54-
firebase.analytics.log_table("stats", t)
39+
function init(self)
40+
-- use firebase only if it is supported on the current platform
41+
if not firebase then
42+
return
43+
end
44+
45+
-- initialise firebase and check that it was successful
46+
firebase.set_callback(function(self, message_id, message)
47+
if message_id == firebase.MSG_INITIALIZED then
48+
firebase.remoteconfig.set_callback(firebase_analytics_callback)
49+
firebase.analytics.initialize()
50+
51+
-- log data
52+
firebase.analytics.log_string("character", "storm trooper")
53+
firebase.analytics.log_int("kills", 152)
54+
firebase.analytics.log("tutorial_done")
55+
firebase.analytics.log_number("speed", 1.15)
56+
local t = {
57+
number = math.random(1,100),
58+
boolean = true,
59+
string = "some_string"
60+
}
61+
firebase.analytics.log_table("stats", t)
62+
firebase.analytics.get_id()
63+
end
64+
end)
5565
end
5666
```
5767

68+
Read about [events](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Event) and [parameters](https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/FirebaseAnalytics.Param) naming limitations in the official documentation.
69+
5870
## Source code
5971

6072
The source code is available on [GitHub](https://github.com/defold/extension-firebase-analytics)

0 commit comments

Comments
 (0)