Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [setEnabled](#setenabled)
- [setUserId](#setuserid)
- [setUserProperty](#setuserproperty)
- [getAppInstanceId](#getappinstanceid)

<!-- /MarkdownTOC -->

Expand Down Expand Up @@ -276,3 +277,21 @@ cordova.plugins.firebase.analytics.setUserProperty("name1", "value1");
`Promise`<`void`\>

Callback when operation is completed

### getAppInstanceId

**getAppInstanceId**(): `Promise`<`string`\>

Returns app instance identifier from Firebase.

**`Example`**

```ts
cordova.plugins.firebase.analytics.getAppInstanceId();
```

#### Returns

`Promise`<`string`\>

Callback when operation is completed
12 changes: 12 additions & 0 deletions src/android/FirebaseAnalyticsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ protected void setDefaultEventParameters(CordovaArgs args, CallbackContext callb
callbackContext.success();
}

@CordovaMethod
protected void getAppInstanceId(CordovaArgs args, CallbackContext callbackContext) {
firebaseAnalytics.getAppInstanceId()
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
callbackContext.success(task.getResult());
} else {
callbackContext.error(task.getException().getMessage());
}
});
}

private static Bundle parse(JSONObject params) throws JSONException {
Bundle bundle = new Bundle();
Iterator<String> it = params.keys();
Expand Down
1 change: 1 addition & 0 deletions src/ios/FirebaseAnalyticsPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
- (void)setCurrentScreen:(CDVInvokedUrlCommand*)command;
- (void)resetAnalyticsData:(CDVInvokedUrlCommand*)command;
- (void)setDefaultEventParameters:(CDVInvokedUrlCommand*)command;
- (void)getAppInstanceId:(CDVInvokedUrlCommand*)command;

@end
7 changes: 7 additions & 0 deletions src/ios/FirebaseAnalyticsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,11 @@ - (void)setDefaultEventParameters:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)getAppInstanceId:(CDVInvokedUrlCommand *)command {
NSString* appInstanceId = [FIRAnalytics appInstanceID];

CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:appInstanceId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

@end
9 changes: 9 additions & 0 deletions types/FirebaseAnalytics.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ export function setCurrentScreen(screenName: string): Promise<void>;
* cordova.plugins.firebase.analytics.setDefaultEventParameters({foo: "bar"});
*/
export function setDefaultEventParameters(defaults: Record<string, number | string | Array<object>>): Promise<void>;
/**
* Returns app instance identifier from Firebase.
*
* @returns {Promise<string>} Callback when operation is completed
*
* @example
* cordova.plugins.firebase.analytics.getAppInstanceId();
*/
export function getAppInstanceId(): Promise<string>;
15 changes: 15 additions & 0 deletions www/FirebaseAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,18 @@ function(defaults) {
exec(resolve, reject, PLUGIN_NAME, "setDefaultEventParameters", [defaults || {}]);
});
};

exports.getAppInstanceId =
/**
* Returns app instance identifier from Firebase.
*
* @returns {Promise<string>} Callback when operation is completed
*
* @example
* cordova.plugins.firebase.analytics.getAppInstanceId();
*/
function() {
return new Promise(function(resolve, reject) {
exec(resolve, reject, PLUGIN_NAME, "getAppInstanceId", []);
});
};