@capacitor-firebase/performance 8.2.0 → 8.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'FirebasePerformance', '~> 12.7.0'
16
+ s.dependency 'FirebasePerformance', '~> 12.7'
17
17
  s.swift_version = '5.1'
18
18
  s.static_framework = true
19
19
  end
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @capacitor-firebase/performance
1
+ # Capacitor Firebase Performance Monitoring Plugin
2
2
 
3
3
  Unofficial Capacitor plugin for [Firebase Performance Monitoring](https://firebase.google.com/docs/perf-mon).[^1]
4
4
 
@@ -8,9 +8,14 @@ Unofficial Capacitor plugin for [Firebase Performance Monitoring](https://fireba
8
8
  </a>
9
9
  </div>
10
10
 
11
- ## Newsletter
11
+ ## Use Cases
12
12
 
13
- Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
13
+ The Firebase Performance Monitoring plugin is typically used to gain insight into the performance characteristics of your app, for example:
14
+
15
+ - **Custom code traces**: Measure how long specific tasks in your app take, such as loading data or processing an image.
16
+ - **Custom metrics**: Count performance-related events within a trace, such as cache hits or retries.
17
+ - **Performance segmentation**: Add custom attributes to your traces, such as a user id, to segment your performance data.
18
+ - **Privacy compliance**: Enable or disable performance monitoring at runtime, for example based on the user's consent.
14
19
 
15
20
  ## Compatibility
16
21
 
@@ -28,7 +33,7 @@ You can use our **AI-Assisted Setup** to install the plugin.
28
33
  Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
29
34
 
30
35
  ```bash
31
- npx skills add capawesome-team/skills
36
+ npx skills add capawesome-team/skills --skill capacitor-plugins
32
37
  ```
33
38
 
34
39
  Then use the following prompt:
@@ -58,6 +63,30 @@ If needed, you can define the following project variable in your app’s `variab
58
63
 
59
64
  This can be useful if you encounter dependency conflicts with other plugins in your project.
60
65
 
66
+ ### iOS
67
+
68
+ #### Swift Package Manager
69
+
70
+ Add the following to your `capacitor.config.json` (or `capacitor.config.ts`) to avoid a [SwiftPM package identity collision](https://github.com/capawesome-team/capacitor-firebase/issues/959):
71
+
72
+ ```json
73
+ {
74
+ "experimental": {
75
+ "ios": {
76
+ "spm": {
77
+ "packageOptions": {
78
+ "@capacitor-firebase/performance": {
79
+ "symlink": true
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ **Attention**: SPM `packageOptions` support requires Capacitor CLI **8.4.0+**.
89
+
61
90
  ## Configuration
62
91
 
63
92
  No configuration required for this plugin.
@@ -68,6 +97,12 @@ A working example can be found here: [robingenz/capacitor-firebase-plugin-demo](
68
97
 
69
98
  ## Usage
70
99
 
100
+ The following examples show how to start and stop traces, record custom metrics, add custom attributes, toggle performance monitoring, and record a trace manually.
101
+
102
+ ### Start and stop a trace
103
+
104
+ Start a custom code trace to measure how long a specific task in your app takes and stop it as soon as the task is completed:
105
+
71
106
  ```typescript
72
107
  import { FirebasePerformance } from '@capacitor-firebase/performance';
73
108
 
@@ -78,6 +113,22 @@ const startTrace = async () => {
78
113
  const stopTrace = async () => {
79
114
  await FirebasePerformance.stopTrace({ traceName: 'test_trace' });
80
115
  };
116
+ ```
117
+
118
+ ### Record custom metrics
119
+
120
+ Set the value of a custom metric for a trace, increment it atomically, or read its current value. Note that metric values are floored down to the nearest integer:
121
+
122
+ ```typescript
123
+ import { FirebasePerformance } from '@capacitor-firebase/performance';
124
+
125
+ const putMetric = async () => {
126
+ await FirebasePerformance.putMetric({
127
+ traceName: 'test_trace',
128
+ metricName: 'item_cache_hit',
129
+ num: 1,
130
+ });
131
+ };
81
132
 
82
133
  const incrementMetric = async () => {
83
134
  await FirebasePerformance.incrementMetric({
@@ -87,14 +138,21 @@ const incrementMetric = async () => {
87
138
  });
88
139
  };
89
140
 
90
- const setEnabled = async () => {
91
- await FirebasePerformance.setEnabled({ enabled: true });
141
+ const getMetric = async () => {
142
+ const result = await FirebasePerformance.getMetric({
143
+ traceName: 'test_trace',
144
+ metricName: 'item_cache_hit',
145
+ });
146
+ return result.value;
92
147
  };
148
+ ```
93
149
 
94
- const isEnabled = async () => {
95
- const result = await FirebasePerformance.isEnabled();
96
- return result.enabled;
97
- };
150
+ ### Add custom attributes to a trace
151
+
152
+ Set custom attributes on a trace, for example a user id, to segment your performance data. You can also read or remove them again:
153
+
154
+ ```typescript
155
+ import { FirebasePerformance } from '@capacitor-firebase/performance';
98
156
 
99
157
  const putAttribute = async () => {
100
158
  await FirebasePerformance.putAttribute({
@@ -123,22 +181,31 @@ const removeAttribute = async () => {
123
181
  attribute: 'user_id',
124
182
  });
125
183
  };
184
+ ```
126
185
 
127
- const putMetric = async () => {
128
- await FirebasePerformance.putMetric({
129
- traceName: 'test_trace',
130
- metricName: 'item_cache_hit',
131
- num: 1,
132
- });
186
+ ### Enable or disable performance monitoring
187
+
188
+ Enable or disable performance monitoring at runtime, for example based on the user's consent. The setting is applied with the next start of the app:
189
+
190
+ ```typescript
191
+ import { FirebasePerformance } from '@capacitor-firebase/performance';
192
+
193
+ const setEnabled = async () => {
194
+ await FirebasePerformance.setEnabled({ enabled: true });
133
195
  };
134
196
 
135
- const getMetric = async () => {
136
- const result = await FirebasePerformance.getMetric({
137
- traceName: 'test_trace',
138
- metricName: 'item_cache_hit',
139
- });
140
- return result.value;
197
+ const isEnabled = async () => {
198
+ const result = await FirebasePerformance.isEnabled();
199
+ return result.enabled;
141
200
  };
201
+ ```
202
+
203
+ ### Record a trace manually
204
+
205
+ Record a trace for a task that has already been completed by providing its start time and duration. Only available on Web:
206
+
207
+ ```typescript
208
+ import { FirebasePerformance } from '@capacitor-firebase/performance';
142
209
 
143
210
  const record = async () => {
144
211
  await FirebasePerformance.record({
@@ -513,6 +580,37 @@ Only available on web.
513
580
 
514
581
  </docgen-api>
515
582
 
583
+ ## FAQ
584
+
585
+ ### How do I measure the duration of a specific task in my app?
586
+
587
+ Start a custom code trace with `startTrace(...)` before the task begins and stop it with `stopTrace(...)` as soon as the task is completed, as shown in the [usage example](#start-and-stop-a-trace) above. You can enrich the trace with custom metrics and attributes before stopping it.
588
+
589
+ ### What are the requirements for custom trace names?
590
+
591
+ Names for custom code traces must not contain leading or trailing whitespace, must not start with an underscore (`_`), and may have a maximum length of 100 characters.
592
+
593
+ ### What is the difference between a metric and an attribute?
594
+
595
+ A metric is a numeric value of a trace, for example a counter for cache hits, which is set with `putMetric(...)` or incremented with `incrementMetric(...)`. Note that metric values are floored down to the nearest integer. An attribute is a string value of a trace, for example a user id, which is set with `putAttribute(...)` and can be used to segment your performance data.
596
+
597
+ ### Can users disable performance monitoring at runtime?
598
+
599
+ Yes, call `setEnabled(...)` to enable or disable performance monitoring, for example based on the user's consent. The setting is applied with the next start of the app. Use `isEnabled()` to determine whether performance monitoring is currently enabled or disabled.
600
+
601
+ ### Why does the `record` method not work on Android and iOS?
602
+
603
+ The `record(...)` method is only available on Web. On Android and iOS, use `startTrace(...)` and `stopTrace(...)` to measure the duration of a task instead.
604
+
605
+ ## Related Plugins
606
+
607
+ - [Firebase Analytics](https://capawesome.io/docs/sdks/capacitor/firebase/analytics/): Log events and user properties with Firebase Analytics.
608
+ - [Firebase Crashlytics](https://capawesome.io/docs/sdks/capacitor/firebase/crashlytics/): Track and analyze app crashes with Firebase Crashlytics.
609
+
610
+ ## Newsletter
611
+
612
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
613
+
516
614
  ## Changelog
517
615
 
518
616
  See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-firebase/blob/main/packages/performance/CHANGELOG.md).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capacitor-firebase/performance",
3
- "version": "8.2.0",
4
- "description": "Capacitor plugin for Firebase Performance Monitoring.",
3
+ "version": "8.4.0",
4
+ "description": "Capacitor plugin for Firebase Performance Monitoring on Android, iOS, and Web.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
@@ -37,7 +37,15 @@
37
37
  "keywords": [
38
38
  "capacitor",
39
39
  "plugin",
40
- "native"
40
+ "native",
41
+ "capacitor-plugin",
42
+ "firebase",
43
+ "firebase performance",
44
+ "performance monitoring",
45
+ "app performance",
46
+ "tracing",
47
+ "custom traces",
48
+ "metrics"
41
49
  ],
42
50
  "scripts": {
43
51
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
@@ -59,17 +67,16 @@
59
67
  },
60
68
  "devDependencies": {
61
69
  "@capacitor/android": "8.0.0",
62
- "@capacitor/cli": "8.0.0",
70
+ "@capacitor/cli": "8.4.2",
63
71
  "@capacitor/core": "8.0.0",
64
72
  "@capacitor/docgen": "0.3.1",
65
73
  "@capacitor/ios": "8.0.0",
66
74
  "@ionic/eslint-config": "0.4.0",
67
75
  "eslint": "8.57.0",
68
76
  "firebase": "11.2.0",
69
- "prettier": "3.4.2",
70
- "prettier-plugin-java": "2.6.7",
77
+ "prettier-plugin-java": "2.9.7",
71
78
  "rimraf": "6.1.2",
72
- "rollup": "4.53.3",
79
+ "rollup": "4.62.3",
73
80
  "swiftlint": "2.0.0",
74
81
  "typescript": "5.9.3"
75
82
  },