Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 9b0bc2d

Browse files
author
Pierre BOULC'H
committed
Complex log event analytics
1 parent fc10aa1 commit 9b0bc2d

File tree

7 files changed

+338
-29
lines changed

7 files changed

+338
-29
lines changed

demo/app/main-view-model.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,56 @@ export class HelloWorldModel extends Observable {
500500
});
501501
}
502502
);
503+
504+
firebase.analytics.logComplexEvent({
505+
key: "view_item_list",
506+
parameters: [{
507+
key: "item1",
508+
type: "array",
509+
value: [
510+
{
511+
parameters: [
512+
{ key: "item_id", value: "id de l’offre", type: "string"},
513+
{key: "item_name", value: "uri métier", type: "string"},
514+
{key: "item_category", value: "category", type: "string"},
515+
{key: "item_variant", value: "variant", type: "string"},
516+
{key: "item_brand", value: "nom de l’entreprise", type: "string"},
517+
{key: " price", value: 1 , type: "long"},
518+
{key: "item_list", value: "LO-Moteur" , type: "string" },
519+
{key: "index", value: 1 , type: "0"}
520+
521+
]
522+
},
523+
{
524+
parameters: [
525+
{ key: "item_id", value: "id de l’offre 1", type: "string"},
526+
{key: "item_name", value: "uri métier", type: "string"},
527+
{key: "item_category", value: "category", type: "string"},
528+
{key: "item_variant", value: "variant", type: "string"},
529+
{key: "item_brand", value: "nom de l’entreprise", type: "string"},
530+
{key: " price", value: 1 , type: "long"},
531+
{key: "item_list", value: "LO-Moteur" , type: "string" },
532+
{key: "index", value: 2 , type: "int"}
533+
534+
]
535+
},
536+
{
537+
parameters: [
538+
{ key: "item_id", value: "id de l’offre 2", type: "string"},
539+
{key: "item_name", value: "uri métier", type: "string"},
540+
{key: "item_category", value: "category", type: "string"},
541+
{key: "item_variant", value: "variant", type: "string"},
542+
{key: "item_brand", value: "nom de l’entreprise", type: "string"},
543+
{key: " price", value: 1 , type: "long"},
544+
{key: "item_list", value: "LO-Moteur" , type: "string" },
545+
{key: "index", value: 3 , type: "int"}
546+
547+
]
548+
}
549+
]
550+
}]
551+
});
552+
503553
}
504554

505555
public doSetAnalyticsUserProperty(): void {
@@ -1708,4 +1758,4 @@ export class HelloWorldModel extends Observable {
17081758
okButtonText: "Okay"
17091759
});
17101760
}
1711-
}
1761+
}

demo/app_resources/Android/google-services.json

Lines changed: 157 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,182 @@
11
{
22
"project_info": {
3-
"project_number": "1052836194035",
4-
"firebase_url": "https://n-plugin-test.firebaseio.com",
5-
"project_id": "n-plugin-test",
6-
"storage_bucket": "n-plugin-test.appspot.com"
3+
"project_number": "600049590124",
4+
"firebase_url": "https://regionsjob-9edb9.firebaseio.com",
5+
"project_id": "regionsjob-9edb9",
6+
"storage_bucket": "regionsjob-9edb9.appspot.com"
77
},
88
"client": [
99
{
1010
"client_info": {
11-
"mobilesdk_app_id": "1:1052836194035:android:443e3741d53b6bc3",
11+
"mobilesdk_app_id": "1:600049590124:android:c31930961dc71d71",
1212
"android_client_info": {
13-
"package_name": "org.nativescript.firebasedemo"
13+
"package_name": "com.bdmjob.android"
14+
}
15+
},
16+
"oauth_client": [
17+
{
18+
"client_id": "600049590124-517eensjofvpm1c0cs91t2upv5u7st6t.apps.googleusercontent.com",
19+
"client_type": 3
20+
}
21+
],
22+
"api_key": [
23+
{
24+
"current_key": "AIzaSyBd595lIGHhdcy27S1b3Rdy3oUM0SMlZ78"
25+
}
26+
],
27+
"services": {
28+
"analytics_service": {
29+
"status": 1
30+
},
31+
"appinvite_service": {
32+
"status": 1,
33+
"other_platform_oauth_client": []
34+
},
35+
"ads_service": {
36+
"status": 2
37+
}
38+
}
39+
},
40+
{
41+
"client_info": {
42+
"mobilesdk_app_id": "1:600049590124:android:efb9450024562531",
43+
"android_client_info": {
44+
"package_name": "com.bdmjob.android.dev"
1445
}
1546
},
1647
"oauth_client": [
1748
{
18-
"client_id": "1052836194035-jtaui0ukukm0o8peubst87stchckm6cu.apps.googleusercontent.com",
19-
"client_type": 1,
20-
"android_info": {
21-
"package_name": "org.nativescript.firebasedemo",
22-
"certificate_hash": "c50c24d7261f8a41c00c641cf19b5116326b333b"
23-
}
49+
"client_id": "600049590124-517eensjofvpm1c0cs91t2upv5u7st6t.apps.googleusercontent.com",
50+
"client_type": 3
51+
}
52+
],
53+
"api_key": [
54+
{
55+
"current_key": "AIzaSyBd595lIGHhdcy27S1b3Rdy3oUM0SMlZ78"
56+
}
57+
],
58+
"services": {
59+
"analytics_service": {
60+
"status": 1
61+
},
62+
"appinvite_service": {
63+
"status": 1,
64+
"other_platform_oauth_client": []
65+
},
66+
"ads_service": {
67+
"status": 2
68+
}
69+
}
70+
},
71+
{
72+
"client_info": {
73+
"mobilesdk_app_id": "1:600049590124:android:6393a01a1fc7c3b6",
74+
"android_client_info": {
75+
"package_name": "com.cadreo.android.dev"
76+
}
77+
},
78+
"oauth_client": [
79+
{
80+
"client_id": "600049590124-517eensjofvpm1c0cs91t2upv5u7st6t.apps.googleusercontent.com",
81+
"client_type": 3
82+
}
83+
],
84+
"api_key": [
85+
{
86+
"current_key": "AIzaSyBd595lIGHhdcy27S1b3Rdy3oUM0SMlZ78"
87+
}
88+
],
89+
"services": {
90+
"analytics_service": {
91+
"status": 1
2492
},
93+
"appinvite_service": {
94+
"status": 1,
95+
"other_platform_oauth_client": []
96+
},
97+
"ads_service": {
98+
"status": 2
99+
}
100+
}
101+
},
102+
{
103+
"client_info": {
104+
"mobilesdk_app_id": "1:600049590124:android:2e01f2ce3bf3617b",
105+
"android_client_info": {
106+
"package_name": "com.hellowork.test"
107+
}
108+
},
109+
"oauth_client": [
110+
{
111+
"client_id": "600049590124-517eensjofvpm1c0cs91t2upv5u7st6t.apps.googleusercontent.com",
112+
"client_type": 3
113+
}
114+
],
115+
"api_key": [
25116
{
26-
"client_id": "1052836194035-p5uj5vhmbnsc65sgkqeon8a5ja6bjhvi.apps.googleusercontent.com",
27-
"client_type": 1,
28-
"android_info": {
29-
"package_name": "org.nativescript.firebasedemo",
30-
"certificate_hash": "86bfaa9359cd32b94a0db4e71381d7f553e29efe"
31-
}
117+
"current_key": "AIzaSyBd595lIGHhdcy27S1b3Rdy3oUM0SMlZ78"
118+
}
119+
],
120+
"services": {
121+
"analytics_service": {
122+
"status": 1
32123
},
124+
"appinvite_service": {
125+
"status": 1,
126+
"other_platform_oauth_client": []
127+
},
128+
"ads_service": {
129+
"status": 2
130+
}
131+
}
132+
},
133+
{
134+
"client_info": {
135+
"mobilesdk_app_id": "1:600049590124:android:bad650d180d153d2",
136+
"android_client_info": {
137+
"package_name": "com.hellowork.whiteapp.android"
138+
}
139+
},
140+
"oauth_client": [
141+
{
142+
"client_id": "600049590124-517eensjofvpm1c0cs91t2upv5u7st6t.apps.googleusercontent.com",
143+
"client_type": 3
144+
}
145+
],
146+
"api_key": [
33147
{
34-
"client_id": "1052836194035-om4t43ap2n4rt9q6jjr407tm3vad1qim.apps.googleusercontent.com",
35-
"client_type": 1,
36-
"android_info": {
37-
"package_name": "org.nativescript.firebasedemo",
38-
"certificate_hash": "f7e078e5bfcaa18db892f8ccc50a82e1775fb272"
39-
}
148+
"current_key": "AIzaSyBd595lIGHhdcy27S1b3Rdy3oUM0SMlZ78"
149+
}
150+
],
151+
"services": {
152+
"analytics_service": {
153+
"status": 1
40154
},
155+
"appinvite_service": {
156+
"status": 1,
157+
"other_platform_oauth_client": []
158+
},
159+
"ads_service": {
160+
"status": 2
161+
}
162+
}
163+
},
164+
{
165+
"client_info": {
166+
"mobilesdk_app_id": "1:600049590124:android:443e3741d53b6bc3",
167+
"android_client_info": {
168+
"package_name": "org.nativescript.firebasedemo"
169+
}
170+
},
171+
"oauth_client": [
41172
{
42-
"client_id": "1052836194035-mvghp8j5h3eh17c0n1dl0pkaeum8hjii.apps.googleusercontent.com",
173+
"client_id": "600049590124-517eensjofvpm1c0cs91t2upv5u7st6t.apps.googleusercontent.com",
43174
"client_type": 3
44175
}
45176
],
46177
"api_key": [
47178
{
48-
"current_key": "AIzaSyDSMjaKslCCA-U4MZm_ZFQjkGP_mS0RQKM"
179+
"current_key": "AIzaSyBd595lIGHhdcy27S1b3Rdy3oUM0SMlZ78"
49180
}
50181
],
51182
"services": {

src/analytics/analytics.android.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as appModule from "tns-core-modules/application";
2-
import { LogEventOptions, SetScreenNameOptions, SetUserPropertyOptions } from "./analytics";
2+
import { LogEventOptions, SetScreenNameOptions, SetUserPropertyOptions, LogComplexEventOptions, LogComplexEventParameter } from "./analytics";
3+
import { LogComplexEventTypeParameter } from "../firebase";
34

45
declare const com: any;
56

@@ -33,6 +34,80 @@ export function logEvent(options: LogEventOptions): Promise<void> {
3334
});
3435
}
3536

37+
function getArrayList(array: Array<LogComplexEventOptions>): java.util.ArrayList<android.os.Bundle> {
38+
let returnArray = new java.util.ArrayList<android.os.Bundle>();
39+
console.log("HERE 24");
40+
for (const p in array) {
41+
const param = array[p];
42+
if (param.parameters !== undefined) {
43+
let bundle: android.os.Bundle = buildBundle(param.parameters);
44+
returnArray.add(bundle);
45+
} else {
46+
console.log("BE CARREFUL, no parameters into your complex event");
47+
}
48+
}
49+
return returnArray;
50+
}
51+
52+
function buildBundle(params: Array<LogComplexEventParameter>): android.os.Bundle {
53+
const bundle = new android.os.Bundle();
54+
for (const p in params) {
55+
const param = params[p];
56+
if (param.value !== undefined) {
57+
console.log("HERE 23");
58+
console.log(param.type);
59+
console.dir(param);
60+
if (param.type === "string") {
61+
bundle.putString(param.key, param.value);
62+
} else if (param.type === "double") {
63+
bundle.putDouble(param.key, param.value);
64+
}
65+
else if (param.type === "float") {
66+
bundle.putFloat(param.key, param.value);
67+
}
68+
else if (param.type === "int") {
69+
bundle.putInt(param.key, param.value);
70+
}
71+
else if (param.type === "long") {
72+
bundle.putLong(param.key, param.value);
73+
}
74+
else if (param.type === "boolean") {
75+
bundle.putBoolean(param.key, param.value);
76+
}
77+
else if (param.type === "array") {
78+
bundle.putParcelableArrayList(param.key, getArrayList(param.value));
79+
}
80+
// bundle.putString(param.key, param.value);
81+
}
82+
}
83+
return bundle;
84+
}
85+
86+
export function logComplexEvent(options: LogComplexEventOptions): Promise<void> {
87+
return new Promise<void>((resolve, reject) => {
88+
try {
89+
if (options.key === undefined) {
90+
reject("Argument 'key' is missing");
91+
return;
92+
}
93+
94+
let bundle = new android.os.Bundle();
95+
if (options.parameters !== undefined) {
96+
bundle = buildBundle(options.parameters);
97+
}
98+
99+
com.google.firebase.analytics.FirebaseAnalytics.getInstance(
100+
appModule.android.currentContext || com.tns.NativeScriptApplication.getInstance()
101+
).logEvent(options.key, bundle);
102+
103+
resolve();
104+
} catch (ex) {
105+
console.log("Error in firebase.analytics.logEvent: " + ex);
106+
reject(ex);
107+
}
108+
});
109+
}
110+
36111
export function setUserId(arg): Promise<void> {
37112
return new Promise<void>((resolve, reject) => {
38113
try {

0 commit comments

Comments
 (0)