Skip to content

Commit

Permalink
Merge pull request #11 from drybnikov/maintance/update_sdk_2_2_1
Browse files Browse the repository at this point in the history
Update native SDK
  • Loading branch information
drybnikov authored Apr 2, 2024
2 parents e866dc4 + a61415f commit 76f59e6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.1.0+13

* Updated Android SDK to 2.2.1, Updated iOS SDK to 3.0.4

## 0.0.4+1

* Improved sending events in Android and iOS
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
Flutter wrapper for Klaviyo [Android](https://github.com/klaviyo/klaviyo-android-sdk),
and [iOS](https://github.com/klaviyo/klaviyo-swift-sdk) projects.

- Uses Klaviyo Android SDK Version `1.1.1`.
- Uses Klaviyo Android SDK Version `2.2.1`.
- The minimum Android SDK `minSdkVersion` required is 23.
- Uses Klaviyo iOS SDK Version `2.0.1`.
- Uses Klaviyo iOS SDK Version `3.0.4`.
- The minimum iOS target version required is 13.

## Usage
Expand Down
10 changes: 5 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.rightbite.denisr'
version '1.0-SNAPSHOT'
version '0.1.0'

buildscript {
ext.kotlin_version = '1.7.20'
Expand All @@ -26,7 +26,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 33
compileSdk 34

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -42,7 +42,7 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "com.github.klaviyo.klaviyo-android-sdk:analytics:1.3.4"
implementation "com.github.klaviyo.klaviyo-android-sdk:push-fcm:1.3.4"
implementation 'com.google.firebase:firebase-messaging-ktx:23.1.2'
implementation "com.github.klaviyo.klaviyo-android-sdk:analytics:2.2.1"
implementation "com.github.klaviyo.klaviyo-android-sdk:push-fcm:2.2.1"
implementation 'com.google.firebase:firebase-messaging-ktx:23.4.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.content.Context
import com.klaviyo.analytics.Klaviyo
import com.klaviyo.analytics.model.Event
import com.klaviyo.analytics.model.EventKey
import com.klaviyo.analytics.model.EventType
import com.klaviyo.analytics.model.EventMetric
import com.klaviyo.analytics.model.Profile
import com.klaviyo.analytics.model.ProfileKey
import io.flutter.Log
Expand Down Expand Up @@ -112,15 +112,15 @@ class KlaviyoFlutterPlugin : MethodCallHandler, FlutterPlugin {
val metaDataRaw = call.argument<Map<String, Any>?>("metaData")

if (eventName != null && metaDataRaw != null) {
val event = Event(EventType.CUSTOM(eventName))
val event = Event(EventMetric.CUSTOM(eventName))

val metaData = convertMapToSeralizedMap(metaDataRaw)
for (item in metaData) {
event.setProperty(EventKey.CUSTOM(item.key), value = item.value)
}
Klaviyo.createEvent(event)

Log.d(TAG, "Event created: $event, type: ${event.type}, value:${event.value} eventMap: ${event.toMap()}")
Log.d(TAG, "Event created: $event, metric: ${event.metric}, value:${event.value} eventMap: ${event.toMap()}")
result.success("Event[$eventName] created with metadataMap: $metaData")
}
}
Expand All @@ -130,7 +130,7 @@ class KlaviyoFlutterPlugin : MethodCallHandler, FlutterPlugin {
call.argument<HashMap<String, String>>("message") ?: emptyMap<String, String>()

if (isKlaviyoPush(metaData)) {
val event = Event(EventType.CUSTOM("\$opened_push"), metaData.mapKeys {
val event = Event(EventMetric.CUSTOM("\$opened_push"), metaData.mapKeys {
EventKey.CUSTOM(it.key)
})
return try {
Expand Down Expand Up @@ -177,7 +177,7 @@ class KlaviyoFlutterPlugin : MethodCallHandler, FlutterPlugin {
}
}

private fun isKlaviyoPush(payload: Map<String, String>) = payload.containsKey("_k")
private fun isKlaviyoPush(payload: Map<String, String>) = payload.containsKey("com.klaviyo._k")

companion object {
private const val CHANNEL_NAME = "com.rightbite.denisr/klaviyo"
Expand Down
11 changes: 10 additions & 1 deletion ios/Classes/KlaviyoFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public class KlaviyoFlutterPlugin: NSObject, FlutterPlugin, UNUserNotificationCe

// below method will be called when the user interacts with the push notification
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// decrement the badge count on the app icon
if #available(iOS 16.0, *) {
UNUserNotificationCenter.current().setBadgeCount(UIApplication.shared.applicationIconBadgeNumber - 1)
} else {
UIApplication.shared.applicationIconBadgeNumber -= 1
}

// If this notification is Klaviyo's notification we'll handle it
// else pass it on to the next push notification service to which it may belong
let handled = KlaviyoSDK().handle(notificationResponse: response, withCompletionHandler: completionHandler)
if !handled {
completionHandler()
Expand Down Expand Up @@ -116,7 +125,7 @@ public class KlaviyoFlutterPlugin: NSObject, FlutterPlugin, UNUserNotificationCe

if let properties = arguments["message"] as? [String: Any],
let _ = properties["_k"] {
klaviyo.create(event: Event(name: .OpenedPush, properties: properties, profile: [:]))
klaviyo.create(event: Event(name: .OpenedPush, properties: properties))

return result(true)
}
Expand Down
4 changes: 2 additions & 2 deletions ios/klaviyo_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'klaviyo_flutter'
s.version = '0.0.1'
s.version = '0.1.0'
s.summary = 'Klaviyo integration for Flutter'
s.description = <<-DESC
A new flutter plugin project.
Expand All @@ -14,7 +14,7 @@ A new flutter plugin project.
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'KlaviyoSwift', '~> 2.2.1'
s.dependency 'KlaviyoSwift', '~> 3.0.4'
s.ios.deployment_target = '13.0'
s.swift_version = '5.0'
end
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: klaviyo_flutter
description: Flutter plugin for Klaviyo integration. Provides push messaging
and Klaviyo analitics services
version: 0.0.4+1
version: 0.1.0+13
homepage: https://github.com/drybnikov/klaviyo_flutter

environment:
Expand Down

0 comments on commit 76f59e6

Please sign in to comment.