Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional properties to the page() API call + add "prepare" script to package.json #22

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion JoinfluxCapacitorSegment.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '13.0'
s.dependency 'Capacitor', '~> 5.0'
s.dependency 'Capacitor', '~> 6.0'
s.dependency 'Analytics', '~> 4.0'
s.swift_version = '5.1'
end
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ track(options: TrackOptions) => any
page(options: PageOptions) => any
```

| Param | Type |
| ------------- | ---------------------------------- |
| **`options`** | <code>{ pathname: string; }</code> |
| Param | Type |
| ------------- |-----------------------------------------------------|
| **`options`** | <code>{ pathname: string; properties: any; }</code> |

**Returns:** <code>any</code>

Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.0.0'
classpath 'com.android.tools.build:gradle:8.2.1'
}
}

apply plugin: 'com.android.library'

android {
namespace "com.joinflux.flux.segment"
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
defaultConfig {
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Binary file modified android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions android/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
7 changes: 5 additions & 2 deletions android/src/main/java/com/joinflux/flux/segment/Segment.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public void track(String eventName, JSObject properties, JSObject options) {
this.analytics.track(eventName, makePropertiesFromMap(makeMapFromJSON(properties)), makeOptionsFromJSON(options));
}

public void page(String pathname) {
this.analytics.screen(pathname);
public void page(String pathname, JSObject properties) {
this.analytics.screen(
pathname,
makePropertiesFromMap(makeMapFromJSON(properties))
);
}

public void reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public void page(PluginCall call) {
call.reject("Pathname was not supplied");
return;
}
JSObject properties = call.getObject("properties");

implementation.page(pathname);
implementation.page(pathname, properties);
call.resolve();
}

Expand Down
8 changes: 4 additions & 4 deletions ios/Plugin/Segment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Segment
@objc public func initialize(key: String, trackLifecycle: Bool) {
let config = AnalyticsConfiguration.init(writeKey: key)
config.trackApplicationLifecycleEvents = trackLifecycle;

Analytics.setup(with: config)
print("CapacitorSegment: initialized")
}
Expand All @@ -20,11 +19,12 @@ import Segment
return
}

@objc public func page(pathname: String) {
Analytics.shared().screen(pathname)

@objc public func page(pathname: String, properties: Dictionary<String, Any>) {
Analytics.shared().screen(pathname, properties: properties)
return
}

@objc func reset() {
Analytics.shared().reset()
return
Expand Down
6 changes: 4 additions & 2 deletions ios/Plugin/SegmentPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public class SegmentPlugin: CAPPlugin {
call.reject("Pathname was not supplied")
return
}

implementation.page(pathname: pathname)
let properties: Dictionary = call.getObject("properties") ?? [:]


implementation.page(pathname: pathname, properties: properties)
call.resolve()
}

Expand Down
Loading