Skip to content

Commit

Permalink
Adding the work of userId and DeviceID statistics analytics (#12)
Browse files Browse the repository at this point in the history
* Added deviceId/userId handlers and support methods for native code
* Update documentation
* Update varioqub_configs.podspec
* Format messages.g.dart
* Update VarioqubConfigsPlugin.swift
* Update CHANGELOG
  • Loading branch information
meg4cyberc4t committed Feb 26, 2024
1 parent 606f793 commit d66a8b2
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 34 deletions.
19 changes: 13 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
## 0.6.1

- Added methods getUserId, updateUserId, getDeviceId, updateDeviceId for user analytics.
- Experiments for ios has been fixed.
- The Swift based version of Varioqub has been upgraded to 0.6.0 version.
- Updated docs.

## 0.6.0

Pigeon have been updated to version ^17.0.0.
Kotlin and swift packages have been updated to version 0.6.0.
Updated docs.
- Pigeon have been updated to version ^17.0.0.
- Kotlin and swift packages have been updated to version 0.6.0.
- Updated docs.

## 0.0.3

Changing dependencies in .podspec for ios projects, the library is now static
- Changing dependencies in .podspec for ios projects, the library is now static

## 0.0.2

Moving the lower sdk limits to >=3.2.0
- Moving the lower sdk limits to >=3.2.0

## 0.0.1

Initial release.
- Initial release.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ await configs.getString(

[Official docs from Yandex](https://yandex.ru/support2/varioqub-app/ru/)

# Limitations

At the moment, the library is used exclusively for obtaining and working with configs and experiments. Analytics elements are not used for fetch!

# Changelog

[Refer to the Changelog to get all release notes.](https://github.com/meg4cyberc4t/varioqub_configs/blob/main/CHANGELOG.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Autogenerated from Pigeon (v17.0.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.meg4cyberc4t.varioqub_configs

import android.util.Log
import io.flutter.plugin.common.BasicMessageChannel
Expand Down Expand Up @@ -99,6 +100,10 @@ private object VarioqubSenderCodec : StandardMessageCodec() {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface VarioqubSender {
fun build(settings: PigeonBuildSettings)
fun getDeviceId(): String
fun updateDeviceId(value: String)
fun getUserId(): String
fun updateUserId(value: String)
fun fetchConfig(callback: (Result<Unit>) -> Unit)
fun activateConfig(callback: (Result<Unit>) -> Unit)
fun setDefaults(values: Map<String, Any>)
Expand Down Expand Up @@ -138,6 +143,76 @@ interface VarioqubSender {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getDeviceId", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
var wrapped: List<Any?>
try {
wrapped = listOf<Any?>(api.getDeviceId())
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateDeviceId", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val valueArg = args[0] as String
var wrapped: List<Any?>
try {
api.updateDeviceId(valueArg)
wrapped = listOf<Any?>(null)
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getUserId", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
var wrapped: List<Any?>
try {
wrapped = listOf<Any?>(api.getUserId())
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateUserId", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val valueArg = args[0] as String
var wrapped: List<Any?>
try {
api.updateUserId(valueArg)
wrapped = listOf<Any?>(null)
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.varioqub_configs.VarioqubSender.fetchConfig", codec)
if (api != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.meg4cyberc4t.varioqub_configs

import PigeonBuildSettings
import VarioqubSender
import android.content.Context
import android.util.Log
import com.yandex.varioqub.config.FetchError
Expand All @@ -21,14 +19,15 @@ class VarioqubConfigsPlugin : FlutterPlugin, VarioqubSender {

private lateinit var api: VarioqubApi
private lateinit var context: Context
private val adapter: VarioqubAdapter = VarioqubAdapter()

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
try {
VarioqubSender.setUp(flutterPluginBinding.binaryMessenger, this)
context = flutterPluginBinding.applicationContext
api = Varioqub.getInstance()
} catch (error: Throwable) {
Log.e(TAG, "Failed to initialize TickerPlugin")
Log.e(TAG, "Failed to initialize VarioqubConfigsPlugin")
}
}

Expand All @@ -52,11 +51,25 @@ class VarioqubConfigsPlugin : FlutterPlugin, VarioqubSender {
}
api.init(
settingsBuilder.build(),
VarioqubAdapter(),
adapter,
context,
);
}

override fun updateDeviceId(value: String) {
adapter.deviceId = value;
}

override fun getDeviceId(): String {
return adapter.deviceId;
}
override fun updateUserId(value: String) {
adapter.userId = value;
}
override fun getUserId(): String {
return adapter.userId;
}

override fun fetchConfig(callback: (Result<Unit>) -> Unit) {
api.fetchConfig(
object : OnFetchCompleteListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import com.yandex.varioqub.analyticadapter.VarioqubConfigAdapter
class VarioqubAdapter : VarioqubConfigAdapter {
override val adapterName: String = "VarioqubAdapter"

var deviceId: String = "000"
var userId: String = "000"

override fun reportConfigChanged(configData: com.yandex.varioqub.analyticadapter.data.ConfigData) {}

override fun requestDeviceId(callback: AdapterIdentifiersCallback) {
callback.onSuccess("000")
callback.onSuccess(deviceId)
}

override fun requestUserId(callback: AdapterIdentifiersCallback) {
callback.onSuccess("000")
callback.onSuccess(userId)
}

override fun setExperiments(experiments: String) {}
Expand Down
2 changes: 1 addition & 1 deletion example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "com.android.application" version '7.4.2' apply false
}

include ":app"
17 changes: 6 additions & 11 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
PODS:
- Flutter (1.0.0)
- Varioqub (0.6.0):
- Varioqub/Core (= 0.6.0)
- Varioqub/Core (0.6.0):
- Varioqub/VQSwiftProtobuf
- Varioqub/MetricaAdapter (0.6.0):
- Varioqub/Core
- Varioqub/VQSwiftProtobuf
- YandexMobileMetrica/Dynamic/Core (~> 4.5.0)
- Varioqub/VQSwiftProtobuf (0.6.0)
- varioqub_configs (0.0.1):
- varioqub_configs (0.6.1):
- Flutter
- Varioqub/MetricaAdapter (~> 0.5)
- YandexMobileMetrica/Dynamic/Core (4.5.2)
- Varioqub (~> 0.6)

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand All @@ -19,7 +16,6 @@ DEPENDENCIES:
SPEC REPOS:
trunk:
- Varioqub
- YandexMobileMetrica

EXTERNAL SOURCES:
Flutter:
Expand All @@ -30,9 +26,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
Varioqub: 58ac5ff3e51a46aca97c3a9c9f3b5cc9d5bf949e
varioqub_configs: d8f4e7737df8a0e3149ca85105c09dee791b8d62
YandexMobileMetrica: f5368ee93f286c793d73b58da00929babfc897c1
varioqub_configs: 3bc95e7b23152922bf18d365c009bff6cff00c7b

PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796

COCOAPODS: 1.13.0
COCOAPODS: 1.15.0
60 changes: 60 additions & 0 deletions ios/Classes/Messages.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class VarioqubSenderCodec: FlutterStandardMessageCodec {
/// Generated protocol from Pigeon that represents a handler of messages from Flutter.
protocol VarioqubSender {
func build(settings: PigeonBuildSettings) throws
func getDeviceId() throws -> String
func updateDeviceId(value: String) throws
func getUserId() throws -> String
func updateUserId(value: String) throws
func fetchConfig(completion: @escaping (Result<Void, Error>) -> Void)
func activateConfig(completion: @escaping (Result<Void, Error>) -> Void)
func setDefaults(values: [String: Any]) throws
Expand Down Expand Up @@ -145,6 +149,62 @@ class VarioqubSenderSetup {
} else {
buildChannel.setMessageHandler(nil)
}
let getDeviceIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getDeviceId", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
getDeviceIdChannel.setMessageHandler { _, reply in
do {
let result = try api.getDeviceId()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
getDeviceIdChannel.setMessageHandler(nil)
}
let updateDeviceIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateDeviceId", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
updateDeviceIdChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let valueArg = args[0] as! String
do {
try api.updateDeviceId(value: valueArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
updateDeviceIdChannel.setMessageHandler(nil)
}
let getUserIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.getUserId", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
getUserIdChannel.setMessageHandler { _, reply in
do {
let result = try api.getUserId()
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
getUserIdChannel.setMessageHandler(nil)
}
let updateUserIdChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.updateUserId", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
updateUserIdChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let valueArg = args[0] as! String
do {
try api.updateUserId(value: valueArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
updateUserIdChannel.setMessageHandler(nil)
}
let fetchConfigChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.varioqub_configs.VarioqubSender.fetchConfig", binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
fetchConfigChannel.setMessageHandler { _, reply in
Expand Down
31 changes: 30 additions & 1 deletion ios/Classes/VarioqubConfigsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@ import Varioqub
#endif


public class VarioqubIdHandler: NSObject, VarioqubIdProvider {
public var deviceId: String = "000"
public var userId: String = "000"

public func fetchIdentifiers(completion: @escaping Completion) {
completion(Result.success(VarioqubIdentifiers(deviceId: deviceId, userId: userId)))
}

public var varioqubName: String = "VarioqubIdHandler"
}

public class VarioqubConfigsPlugin: NSObject, FlutterPlugin, VarioqubSender {
let idHandler: VarioqubIdHandler = VarioqubIdHandler();

init(binaryMessenger: FlutterBinaryMessenger) {
super.init()
VarioqubSenderSetup.setUp(binaryMessenger: binaryMessenger, api: self)
Expand All @@ -35,7 +48,7 @@ public class VarioqubConfigsPlugin: NSObject, FlutterPlugin, VarioqubSender {
VarioqubFacade.shared.initialize(
clientId: settings.clientId,
config: config,
idProvider: nil,
idProvider: idHandler,
reporter: nil
)
}
Expand Down Expand Up @@ -64,6 +77,22 @@ public class VarioqubConfigsPlugin: NSObject, FlutterPlugin, VarioqubSender {
return VarioqubFacade.shared.setDefaultsAndWait(defaults)
}

func getDeviceId() throws -> String {
return idHandler.deviceId
}

func updateDeviceId(value: String) throws {
return idHandler.deviceId = value
}

func getUserId() throws -> String {
return idHandler.userId
}

func updateUserId(value: String) throws {
return idHandler.userId = value
}

func getString(key: String, defaultValue: String) throws -> String {
return VarioqubFacade.shared.getString(for: VarioqubFlag(rawValue: key), defaultValue: defaultValue)
}
Expand Down
Loading

0 comments on commit d66a8b2

Please sign in to comment.