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

Commit 22a543d

Browse files
Support Firebase Performance Monitoring #370
1 parent 7edfc62 commit 22a543d

File tree

19 files changed

+321
-40
lines changed

19 files changed

+321
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ src/platforms/android/include.gradle
1717
!src/references.d.ts
1818
!src/analytics/analytics.d.ts
1919
!src/crashlytics/crashlytics.d.ts
20+
!src/performance/performance.d.ts
2021
!src/storage/storage.d.ts
2122
!src/admob/admob.d.ts
2223
!src/messaging/messaging.d.ts

demo-ng/app/tabs/mlkit/barcodescanning/barcodescanning.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<MLKitBarcodeScanner
77
width="100%"
88
height="100%"
9-
formats="QR_CODE, EAN_8, EAN_13"
9+
formats="QR_CODE, EAN_8, EAN_13, ISBN"
1010
android:processEveryNthFrame="5"
1111
ios:processEveryNthFrame="10"
1212
[torchOn]="torchOn"

demo-ng/firebase.nativescript.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"realtimedb": false,
55
"firestore": true,
66
"remote_config": false,
7+
"performance_monitoring": true,
78
"messaging": false,
89
"crash_reporting": false,
910
"crashlytics": true,

demo-ng/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"nativescript-angular": "^6.1.0",
2626
"nativescript-camera": "^4.0.2",
2727
"nativescript-imagepicker": "~6.0.4",
28-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.2.0.tgz",
28+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.3.0.tgz",
2929
"nativescript-theme-core": "~1.0.4",
3030
"reflect-metadata": "~0.1.10",
3131
"rxjs": "~6.0.0 || >=6.1.0",

demo/app/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ button {
7777
background-color: #1832d5;
7878
}
7979

80+
.button-performance {
81+
background-color: #d57c13;
82+
}
83+
8084
.barcodescanner {
8185
height: 420;
8286
margin-top: 16;

demo/app/main-page.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<TabViewItem.view>
8686
<ScrollView>
8787
<GridLayout columns="*, *"
88-
rows="auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto"
88+
rows="auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto, auto"
8989
horizontalAlignment="stretch"
9090
class="tab-content">
9191

@@ -225,6 +225,15 @@
225225
<Label row="49" colSpan="2" text="Firebase Invites" class="subtitle"/>
226226
<Button row="50" col="0" text="send invitation" tap="{{ sendInvitation }}" class="button button-invites"/>
227227
<Button row="50" col="1" text="get invitation" tap="{{ getInvitation }}" class="button button-invites"/>
228+
229+
<Label row="51" colSpan="2" text="Performance Monitoring" class="subtitle"/>
230+
<Button row="52" col="0" text="start trace" tap="{{ startPerformanceMonitoringTrace }}" class="button button-performance"/>
231+
<Button row="52" col="1" text="stop trace" tap="{{ stopPerformanceMonitoringTrace }}" class="button button-performance"/>
232+
<Button row="53" col="0" text="set value trace" tap="{{ setValuePerformanceMonitoring }}" class="button button-performance"/>
233+
<Button row="53" col="1" text="get value" tap="{{ getValuePerformanceMonitoring }}" class="button button-performance"/>
234+
<Button row="54" col="0" text="get attributes" tap="{{ getAttributesPerformanceMonitoring }}" class="button button-performance"/>
235+
<Button row="54" col="1" text="removeAttribute" tap="{{ removeAttributePerformanceMonitoring }}" class="button button-performance"/>
236+
<Button row="55" colSpan="2" text="increment metric" tap="{{ incrementMetricPerformanceMonitoring }}" class="button button-performance"/>
228237
</GridLayout>
229238

230239
</ScrollView>

demo/app/main-view-model.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
AddEventListenerResult,
77
admob as firebaseAdMob,
88
crashlytics as firebaseCrashlytics,
9+
performance as firebasePerformance,
910
storage as firebaseStorage,
1011
User
1112
} from "nativescript-plugin-firebase";
1213
import * as fs from "tns-core-modules/file-system";
1314
import { MessagingViewModel } from './messaging-view-model';
15+
import { FirebaseTrace } from "nativescript-plugin-firebase/performance/performance";
1416

1517
const firebaseWebApi = require("nativescript-plugin-firebase/app");
1618

@@ -24,6 +26,7 @@ export class HelloWorldModel extends Observable {
2426
private userListenerWrapper: AddEventListenerResult;
2527
private companiesListenerWrapper: AddEventListenerResult;
2628
private onAuthStateChangedHandlerSet = false;
29+
private firebaseTrace: FirebaseTrace;
2730

2831
/***********************************************
2932
* Web API usage examples
@@ -1599,6 +1602,52 @@ export class HelloWorldModel extends Observable {
15991602
);
16001603
}
16011604

1605+
public startPerformanceMonitoringTrace(): void {
1606+
this.firebaseTrace = firebasePerformance.startTrace("myTrace");
1607+
console.log(">> trace started");
1608+
}
1609+
1610+
public stopPerformanceMonitoringTrace(): void {
1611+
if (this.firebaseTrace) {
1612+
this.firebaseTrace.stop();
1613+
this.firebaseTrace = undefined;
1614+
console.log(">> trace stopped");
1615+
}
1616+
}
1617+
1618+
public setValuePerformanceMonitoring(): void {
1619+
if (this.firebaseTrace) {
1620+
this.firebaseTrace.setValue("foo", "bar");
1621+
console.log(">> value set");
1622+
}
1623+
}
1624+
1625+
public getValuePerformanceMonitoring(): void {
1626+
if (this.firebaseTrace) {
1627+
console.log(">> value: " + this.firebaseTrace.getValue("foo"));
1628+
}
1629+
}
1630+
1631+
public getAttributesPerformanceMonitoring(): void {
1632+
if (this.firebaseTrace) {
1633+
console.log(">> attributes: " + JSON.stringify(this.firebaseTrace.getAttributes()));
1634+
}
1635+
}
1636+
1637+
public removeAttributePerformanceMonitoring(): void {
1638+
if (this.firebaseTrace) {
1639+
this.firebaseTrace.removeAttribute("foo");
1640+
console.log(">> attribute removed");
1641+
}
1642+
}
1643+
1644+
public incrementMetricPerformanceMonitoring(): void {
1645+
if (this.firebaseTrace) {
1646+
this.firebaseTrace.incrementMetric("foo_metric", 1);
1647+
console.log(">> metric incremented");
1648+
}
1649+
}
1650+
16021651
public doLogMessage(): void {
16031652
firebase.sendCrashLog({
16041653
message: "Hey, I was logged!",

demo/firebase.nativescript.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"realtimedb": true,
77
"authentication": true,
88
"remote_config": true,
9+
"performance_monitoring": true,
910
"messaging": true,
1011
"crashlytics": true,
1112
"crash_reporting": true,

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"firebase-functions": "^2.0.5",
13-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.2.0.tgz",
13+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.3.0.tgz",
1414
"nativescript-theme-core": "^1.0.4",
1515
"nativescript-unit-test-runner": "^0.3.4",
1616
"tns-core-modules": "^4.2.1"

publish/scripts/installer.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ function promptQuestions() {
157157
name: 'remote_config',
158158
description: 'Are you using Firebase RemoteConfig? (y/n)',
159159
default: 'n'
160+
}, {
161+
name: 'performance_monitoring',
162+
description: 'Are you using Performance Monitoring? (y/n)',
163+
default: 'n'
160164
}, {
161165
name: 'messaging',
162166
description: 'Are you using Firebase Messaging? (y/n)',
@@ -340,6 +344,9 @@ pod 'GoogleUtilities', '5.2.3'
340344
# Remote Config
341345
` + (isSelected(result.remote_config) ? `` : `#`) + `pod 'Firebase/RemoteConfig'
342346
347+
# Performance Monitoring
348+
` + (isSelected(result.performance_monitoring) ? `` : `#`) + `pod 'Firebase/Performance'
349+
343350
# Crash Reporting
344351
` + (isSelected(result.crash_reporting) && !isSelected(result.crashlytics) ? `` : `#`) + `pod 'Firebase/Crash'
345352
@@ -576,7 +583,7 @@ repositories {
576583
}
577584
578585
def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "26.0.0"
579-
def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : "15.0.1"
586+
def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : "16.0.1"
580587
581588
if (VersionNumber.parse(googlePlayServicesVersion) < VersionNumber.parse('15.0.+')) {
582589
throw new GradleException(" googlePlayServicesVersion set too low, please update to at least 15.0.0 / 15.0.+ (currently set to $googlePlayServicesVersion)");
@@ -590,44 +597,47 @@ dependencies {
590597
compile "com.android.support:support-compat:$supportVersion"
591598
592599
// make sure you have these versions by updating your local Android SDK's (Android Support repo and Google repo)
593-
compile "com.google.firebase:firebase-core:16.0.3"
600+
compile "com.google.firebase:firebase-core:16.0.4"
594601
595602
// for reading google-services.json and configuration
596603
compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
597604
598605
// Authentication
599-
` + (!externalPushClientOnly && (!isPresent(result.authentication) || isSelected(result.authentication)) ? `` : `//`) + ` compile "com.google.firebase:firebase-auth:16.0.3"
606+
` + (!externalPushClientOnly && (!isPresent(result.authentication) || isSelected(result.authentication)) ? `` : `//`) + ` compile "com.google.firebase:firebase-auth:16.0.4"
600607
601608
// Realtime DB
602-
` + (!externalPushClientOnly && (!isPresent(result.realtimedb) || isSelected(result.realtimedb)) ? `` : `//`) + ` compile "com.google.firebase:firebase-database:16.0.1"
609+
` + (!externalPushClientOnly && (!isPresent(result.realtimedb) || isSelected(result.realtimedb)) ? `` : `//`) + ` compile "com.google.firebase:firebase-database:16.0.3"
603610
604611
// Cloud Firestore
605-
` + (isSelected(result.firestore) ? `` : `//`) + ` compile "com.google.firebase:firebase-firestore:17.1.0"
612+
` + (isSelected(result.firestore) ? `` : `//`) + ` compile "com.google.firebase:firebase-firestore:17.1.1"
606613
607614
// Remote Config
608-
` + (isSelected(result.remote_config) ? `` : `//`) + ` compile "com.google.firebase:firebase-config:16.0.0"
615+
` + (isSelected(result.remote_config) ? `` : `//`) + ` compile "com.google.firebase:firebase-config:16.1.0"
616+
617+
// Performance Monitoring
618+
` + (isSelected(result.performance_monitoring) ? `` : `//`) + ` compile "com.google.firebase:firebase-perf:16.1.2"
609619
610620
// Crash Reporting
611-
` + (isSelected(result.crash_reporting) && !isSelected(result.crashlytics) ? `` : `//`) + ` compile "com.google.firebase:firebase-crash:16.2.0"
621+
` + (isSelected(result.crash_reporting) && !isSelected(result.crashlytics) ? `` : `//`) + ` compile "com.google.firebase:firebase-crash:16.2.1"
612622
613623
// Crashlytics
614-
` + (isSelected(result.crashlytics) ? `` : `//`) + ` compile "com.crashlytics.sdk.android:crashlytics:2.9.3"
624+
` + (isSelected(result.crashlytics) ? `` : `//`) + ` compile "com.crashlytics.sdk.android:crashlytics:2.9.5"
615625
616626
// Firebase Cloud Messaging (FCM)
617-
` + (isSelected(result.messaging) || externalPushClientOnly ? `` : `//`) + ` compile "com.google.firebase:firebase-messaging:17.3.0"
627+
` + (isSelected(result.messaging) || externalPushClientOnly ? `` : `//`) + ` compile "com.google.firebase:firebase-messaging:17.3.4"
618628
619629
// Cloud Storage
620-
` + (isSelected(result.storage) ? `` : `//`) + ` compile "com.google.firebase:firebase-storage:16.0.1"
630+
` + (isSelected(result.storage) ? `` : `//`) + ` compile "com.google.firebase:firebase-storage:16.0.3"
621631
622632
// Cloud Functions
623-
` + (isSelected(result.functions) ? `` : `//`) + ` compile "com.google.firebase:firebase-functions:16.1.0"
633+
` + (isSelected(result.functions) ? `` : `//`) + ` compile "com.google.firebase:firebase-functions:16.1.1"
624634
625635
// AdMob / Ads
626636
` + (isSelected(result.admob) ? `` : `//`) + ` compile "com.google.firebase:firebase-ads:15.0.1"
627637
628638
// ML Kit
629-
` + (isSelected(result.ml_kit) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision:17.0.0"
630-
` + (isSelected(result.ml_kit_image_labeling) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision-image-label-model:15.0.0"
639+
` + (isSelected(result.ml_kit) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision:18.0.1"
640+
` + (isSelected(result.ml_kit_image_labeling) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision-image-label-model:17.0.2"
631641
632642
// Facebook Authentication
633643
` + (isSelected(result.facebook_auth) ? `` : `//`) + ` compile ("com.facebook.android:facebook-android-sdk:4.35.0"){ exclude group: 'com.google.zxing' }
@@ -636,10 +646,10 @@ dependencies {
636646
` + (isSelected(result.google_auth) ? `` : `//`) + ` compile "com.google.android.gms:play-services-auth:16.0.0"
637647
638648
// Firebase Invites
639-
` + (isSelected(result.invites) ? `` : `//`) + ` compile "com.google.firebase:firebase-invites:16.0.3"
649+
` + (isSelected(result.invites) ? `` : `//`) + ` compile "com.google.firebase:firebase-invites:16.0.4"
640650
641651
// Firebase Dynamic Links
642-
` + (isSelected(result.dynamic_links) ? `` : `//`) + ` compile "com.google.firebase:firebase-dynamic-links:16.1.1"
652+
` + (isSelected(result.dynamic_links) ? `` : `//`) + ` compile "com.google.firebase:firebase-dynamic-links:16.1.2"
643653
}
644654
645655
apply plugin: "com.google.gms.google-services"

0 commit comments

Comments
 (0)