Skip to content

Commit

Permalink
Merge pull request #53 from capacitor-community/capacitor-v3
Browse files Browse the repository at this point in the history
Capacitor V3 Support
  • Loading branch information
brownoxford authored May 26, 2021
2 parents 5fbb7bf + 6c19c9b commit f5aa55d
Show file tree
Hide file tree
Showing 20 changed files with 5,819 additions and 799 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
node-version: "12"
- name: Install NPM Dependencies
run: npm install
run: npm ci
- name: Build NPM Module
run: npm run build
- name: Install Cocoapods
Expand All @@ -47,7 +47,7 @@ jobs:
distribution: "zulu"
java-version: "8"
- name: Install NPM Dependencies
run: npm install
run: npm ci
- name: Build NPM Module
run: npm run build
- name: Run Android Tests
Expand Down
2 changes: 1 addition & 1 deletion CapacitorCommunityFirebaseAnalytics.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.author = package['author']
s.source = { :git => 'https://github.com/capacitor-community/firebase-analytics', :tag => s.version.to_s }
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '11.0'
s.ios.deployment_target = '12.0'
s.static_framework = true
s.dependency 'Capacitor'
s.dependency 'Firebase'
Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ git checkout -b firebase-analytics
## Usage

```typescript
// Must import the package once to make sure the web support initializes
import "@capacitor-community/firebase-analytics";

import { Plugins } from "@capacitor/core";

const { FirebaseAnalytics } = Plugins;
import { FirebaseAnalytics } from "@capacitor-community/firebase-analytics";

/**
* Platform: Web
Expand Down
4 changes: 3 additions & 1 deletion android/.npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
.gradle
build
local.properties
10 changes: 6 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ext {
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.12'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.1'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.2.0'
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
}

buildscript {
Expand All @@ -19,10 +20,10 @@ buildscript {
apply plugin: 'com.android.library'

android {
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 29
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
defaultConfig {
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 29
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -48,6 +49,7 @@ repositories {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':capacitor-android')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
Expand Down
7 changes: 3 additions & 4 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.getcapacitor.community.firebaseanalytics.firebaseanalytics">
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.getcapacitor.community.firebaseanalytics.firebaseanalytics">
</manifest>

Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.getcapacitor.annotation.Permission;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import java.util.Iterator;
import org.json.JSONObject;

@NativePlugin(
@CapacitorPlugin(
name = "FirebaseAnalytics",
permissions = {
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.INTERNET,
Manifest.permission.WAKE_LOCK,
@Permission(
strings = { Manifest.permission.ACCESS_NETWORK_STATE },
alias = "network"
),
@Permission(strings = { Manifest.permission.INTERNET }, alias = "internet"),
@Permission(
strings = { Manifest.permission.WAKE_LOCK },
alias = "wakelock"
),
}
)
public class FirebaseAnalytics extends Plugin {
Expand All @@ -33,7 +41,7 @@ public void load() {
// Obtain the FirebaseAnalytics instance.
mFirebaseAnalytics =
com.google.firebase.analytics.FirebaseAnalytics.getInstance(
this.bridge.getActivity()
bridge.getActivity()
);
}

Expand All @@ -45,20 +53,20 @@ public void load() {
public void setUserId(PluginCall call) {
try {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

if (!call.hasOption("userId")) {
call.error("userId property is missing");
call.reject("userId property is missing");
return;
}

String userId = call.getString("userId");
mFirebaseAnalytics.setUserId(userId);
call.success();
call.resolve();
} catch (Exception ex) {
call.error(ex.getLocalizedMessage());
call.reject(ex.getLocalizedMessage());
}
}

Expand All @@ -71,27 +79,27 @@ public void setUserId(PluginCall call) {
public void setUserProperty(PluginCall call) {
try {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

if (!call.hasOption("name")) {
call.error("name property is missing");
call.reject("name property is missing");
return;
}

if (!call.hasOption("value")) {
call.error("value property is missing");
call.reject("value property is missing");
return;
}

String name = call.getString("name");
String value = call.getString("value");

mFirebaseAnalytics.setUserProperty(name, value);
call.success();
call.resolve();
} catch (Exception ex) {
call.error(ex.getLocalizedMessage());
call.reject(ex.getLocalizedMessage());
}
}

Expand All @@ -102,7 +110,7 @@ public void setUserProperty(PluginCall call) {
@PluginMethod
public void getAppInstanceId(final PluginCall call) {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}
Task<String> task = mFirebaseAnalytics.getAppInstanceId();
Expand All @@ -112,15 +120,15 @@ public void onComplete(@NonNull Task<String> task) {
if (task.isSuccessful()) {
String instanceId = task.getResult();
if (instanceId.isEmpty()) {
call.error("failed to obtain app instance id");
call.reject("failed to obtain app instance id");
} else {
JSObject result = new JSObject();
result.put("instanceId", instanceId);
call.success(result);
call.resolve(result);
}
} else {
Exception exception = task.getException();
call.error(exception.getLocalizedMessage());
call.reject(exception.getLocalizedMessage());
}
}
});
Expand All @@ -135,12 +143,12 @@ public void onComplete(@NonNull Task<String> task) {
public void setScreenName(final PluginCall call) {
try {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

if (!call.hasOption("screenName")) {
call.error("screenName property is missing");
call.reject("screenName property is missing");
return;
}

Expand All @@ -167,12 +175,12 @@ public void run() {
com.google.firebase.analytics.FirebaseAnalytics.Event.SCREEN_VIEW,
bundle
);
call.success();
call.resolve();
}
}
);
} catch (Exception ex) {
call.error(ex.getLocalizedMessage());
call.reject(ex.getLocalizedMessage());
}
}

Expand All @@ -184,14 +192,14 @@ public void run() {
public void reset(PluginCall call) {
try {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

mFirebaseAnalytics.resetAnalyticsData();
call.success();
call.resolve();
} catch (Exception ex) {
call.error(ex.getLocalizedMessage());
call.reject(ex.getLocalizedMessage());
}
}

Expand All @@ -204,12 +212,12 @@ public void reset(PluginCall call) {
public void logEvent(PluginCall call) {
try {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

if (!call.hasOption("name")) {
call.error("name property is missing");
call.reject("name property is missing");
return;
}

Expand Down Expand Up @@ -240,9 +248,9 @@ public void logEvent(PluginCall call) {
}

mFirebaseAnalytics.logEvent(name, bundle);
call.success();
call.resolve();
} catch (Exception ex) {
call.error(ex.getLocalizedMessage());
call.reject(ex.getLocalizedMessage());
}
}

Expand All @@ -253,14 +261,14 @@ public void logEvent(PluginCall call) {
@PluginMethod
public void setCollectionEnabled(PluginCall call) {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

boolean enabled = call.getBoolean("enabled", false);

mFirebaseAnalytics.setAnalyticsCollectionEnabled(enabled);
call.success();
call.resolve();
}

/**
Expand All @@ -272,12 +280,12 @@ public void setCollectionEnabled(PluginCall call) {
@PluginMethod
public void enable(PluginCall call) {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

mFirebaseAnalytics.setAnalyticsCollectionEnabled(true);
call.success();
call.resolve();
}

/**
Expand All @@ -289,12 +297,12 @@ public void enable(PluginCall call) {
@PluginMethod
public void disable(PluginCall call) {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

mFirebaseAnalytics.setAnalyticsCollectionEnabled(false);
call.success();
call.resolve();
}

/**
Expand All @@ -304,13 +312,13 @@ public void disable(PluginCall call) {
@PluginMethod
public void setSessionTimeoutDuration(PluginCall call) {
if (mFirebaseAnalytics == null) {
call.error(MISSING_REF_MSSG);
call.reject(MISSING_REF_MSSG);
return;
}

int duration = call.getInt("duration", 1800);

mFirebaseAnalytics.setSessionTimeoutDuration(duration);
call.success();
call.resolve();
}
}
4 changes: 4 additions & 0 deletions ios/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Pods/
Podfile.lock
contents.xcworkspacedata
xcuserdata/
Loading

0 comments on commit f5aa55d

Please sign in to comment.