Skip to content

Commit

Permalink
Merge pull request #234 from CleverTap/web_old_version_fix
Browse files Browse the repository at this point in the history
Adding js package
  • Loading branch information
KambleSonam authored May 9, 2024
2 parents 02e287e + c958d6c commit 598d9ac
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 47 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## CHANGE LOG

### Version 2.3.2 *(9th May 2024)*
-------------------------------------------
**What's new**
* **[Web Platform]**
* Added the method 'recordChargedEvent' for web

**Bug Fixes**
* **[Web Platform]**
* Added [JS package](https://pub.dev/packages/js) dependency to handle latest versions.

### Version 2.3.1 *(19th April 2024)*
-------------------------------------------
**Bug Fixes**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To get started, sign up [here](https://clevertap.com/live-product-demo/).

```yaml
dependencies:
clevertap_plugin: 2.3.1
clevertap_plugin: 2.3.2
```
- Run `flutter packages get` to install the SDK
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'com.clevertap.clevertap_plugin'
version '2.3.1'
version '2.3.2'

rootProject.allprojects {
repositories {
Expand Down
6 changes: 1 addition & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1731,11 +1731,7 @@ class _MyAppState extends State<MyApp> {
'total': '200',
'payment': 'cash'
};
if (kIsWeb) {
CleverTapPlugin.recordEvent("Charged", chargeDetails);
} else {
CleverTapPlugin.recordChargedEvent(chargeDetails, items);
}
CleverTapPlugin.recordChargedEvent(chargeDetails, items);
showToast("Raised event - Charged");
}

Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description: A CleverTap Flutter Example project.
version: 1.0.0+1

environment:
sdk: '>=3.2.0-0 <4.0.0'
sdk: '>=2.12.0 <4.0.0'

dependencies:
flutter_styled_toast: ^2.0.1
Expand Down
2 changes: 1 addition & 1 deletion ios/clevertap_plugin.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'clevertap_plugin'
s.version = '2.3.1'
s.version = '2.3.2'
s.summary = 'CleverTap Flutter plugin.'
s.description = 'The CleverTap iOS SDK for App Analytics and Engagement.'
s.homepage = 'https://github.com/CleverTap/clevertap-ios-sdk'
Expand Down
2 changes: 1 addition & 1 deletion lib/clevertap_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CleverTapPlugin {
static const libName = 'Flutter';

static const libVersion =
20301; // If the current version is X.X.X then pass as X0X0X
20302; // If the current version is X.X.X then pass as X0X0X

CleverTapPlugin._internal() {
/// Set the CleverTap Flutter library name and the current version for version tracking
Expand Down
58 changes: 35 additions & 23 deletions lib/clevertap_plugin_web.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'dart:async';
import 'dart:js_interop';
import 'dart:js_util';
import 'dart:html' as html;

import 'package:clevertap_plugin/src/clevertap_plugin_web_binding.dart';
import 'package:flutter/services.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:js/js_util.dart' as js_util;
import 'package:js/js.dart';
import 'dart:html' as html;

/// A web implementation of the CleverTapPlugin plugin.
class CleverTapPlugin {
Expand Down Expand Up @@ -48,6 +48,8 @@ class CleverTapPlugin {
return _toggleInbox(call);
case 'recordEvent':
return _recordEvent(call);
case 'recordChargedEvent':
return _recordChargedEvent(call);
case 'onUserLogin':
return _onUserLogin(call);
case 'profileSet':
Expand Down Expand Up @@ -147,47 +149,55 @@ class CleverTapPlugin {

void _toggleInbox(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
toggleInbox(jsify({'rect': args['rect']}));
toggleInbox(js_util.jsify({'rect': args['rect']}));
}

/// Pushes a basic event
void _recordEvent(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
String eventName = args['eventName'] as String;
Object eventData = args['eventData'] ?? {};
event_push(eventName, jsify(eventData));
Object? eventData = args['eventData'];
event_push(eventName, js_util.jsify(eventData ?? {}));
}

/// Pushed a Charged event
void _recordChargedEvent(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
Map chargeDetails = args['chargeDetails'] as Map;
chargeDetails["Items"] = args['items'] as List;
event_push("Charged", js_util.jsify(chargeDetails));
}

/// OnUserLogin request
void _onUserLogin(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
onUserLogin_push(jsify({"Site": args['profile']}));
onUserLogin_push(js_util.jsify({"Site": args['profile']}));
}

/// enable web push
void _enableWebPush(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
notifications_push(jsify(args));
notifications_push(js_util.jsify(args));
}

/// Profile push request
void _profileSet(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
onUserLogin_push(jsify({"Site": args['profile']}));
onUserLogin_push(js_util.jsify({"Site": args['profile']}));
}

/// Set Optout flag
void _setOptOut(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
bool value = args['value'] as bool;
privacy_push(jsify({"optOut": value}));
privacy_push(js_util.jsify({"optOut": value}));
}

/// Set useIP flag
void _setUseIP(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
bool value = args['value'] as bool;
privacy_push(jsify({"useIP": value}));
privacy_push(js_util.jsify({"useIP": value}));
}

/// Set Log Level
Expand Down Expand Up @@ -290,15 +300,17 @@ class CleverTapPlugin {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
String msgId = args['msgId'] as String;
String pivotId = args['pivotId'] as String;
renderNotificationViewed(jsify({"msgId": msgId, "pivotId": pivotId}));
renderNotificationViewed(
js_util.jsify({"msgId": msgId, "pivotId": pivotId}));
}

/// Method for notification clicked
void _renderNotificationClicked(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
String msgId = args['msgId'] as String;
String pivotId = args['pivotId'] as String;
renderNotificationClicked(jsify({"msgId": msgId, "pivotId": pivotId}));
renderNotificationClicked(
js_util.jsify({"msgId": msgId, "pivotId": pivotId}));
}

/// Get total inbox message count
Expand All @@ -313,19 +325,19 @@ class CleverTapPlugin {

/// Get All Inbox Messages
List _getAllInboxMessages(MethodCall call) {
return List.from((getAllInboxMessages().dartify() as Map).values);
return List.from((js_util.dartify(getAllInboxMessages()) as Map).values);
}

/// Get All Inbox Unread Messages
List _getUnreadInboxMessages(MethodCall call) {
return List.from((getUnreadInboxMessages().dartify() as Map).values);
return List.from((js_util.dartify(getUnreadInboxMessages()) as Map).values);
}

/// Get Inbox Message for the given message-id
Map _getInboxMessageForId(MethodCall call) {
Object _getInboxMessageForId(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
String messageId = args['messageId'] as String;
return getInboxMessageForId(messageId).dartify() as Map;
return (js_util.dartify(getInboxMessageForId(messageId)) as Map);
}

/// Delete Message for the given message-id
Expand Down Expand Up @@ -356,7 +368,7 @@ class CleverTapPlugin {
void _defineVariables(MethodCall call) {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
Object variables = args['variables'] as Object;
defineVariables(jsify(variables));
defineVariables(js_util.jsify(variables));
}

/// Sync Variables
Expand All @@ -378,30 +390,30 @@ class CleverTapPlugin {
name,
allowInterop((object) => {
_nativeToDartMethodChannel?.invokeMethod(
'onValueChanged', dartify(object))
'onValueChanged', js_util.dartify(object))
}));
}

void _onVariablesChanged(MethodCall call) {
onVariablesChanged(allowInterop((object) => {
_nativeToDartMethodChannel?.invokeMethod(
'onVariablesChanged', dartify(object))
'onVariablesChanged', js_util.dartify(object))
}));
}

Future<Map<Object?, Object?>> _getVariables(MethodCall call) async {
var completer = Completer<Map<Object?, Object?>>();
getVariables(allowInterop((object) =>
completer.complete(dartify(object) as Map<Object?, Object?>)));
completer.complete(js_util.dartify(object) as Map<Object?, Object?>)));
return completer.future;
}

Future<dynamic> _getVariable(MethodCall call) async {
Map<Object?, Object?> args = call.arguments as Map<Object?, Object?>;
String name = args['name'] as String;
var completer = Completer<dynamic>();
getVariable(
name, allowInterop((object) => completer.complete(dartify(object))));
getVariable(name,
allowInterop((object) => completer.complete(js_util.dartify(object))));
return completer.future;
}
}
26 changes: 13 additions & 13 deletions lib/src/clevertap_plugin_web_binding.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@JS("clevertap")
library clevertap;

import 'dart:js_interop';
import 'package:js/js.dart';

@JS('init')
external void init(
Expand All @@ -14,22 +14,22 @@ external void setLibrary(
);

@JS('toggleInbox')
external void toggleInbox(JSObject object);
external void toggleInbox(Object object);

@JS('event.push')
external void event_push(String event, JSObject? object);
external void event_push(String event, Object? object);

@JS('onUserLogin.push')
external void onUserLogin_push(JSObject object);
external void onUserLogin_push(Object object);

@JS('notifications.push')
external void notifications_push(JSObject object);
external void notifications_push(Object object);

@JS('profile.push')
external void profile_push(JSObject object);
external void profile_push(Object object);

@JS('privacy.push')
external void privacy_push(JSObject object);
external void privacy_push(Object object);

@JS('setLogLevel')
external void setLogLevel(int value);
Expand Down Expand Up @@ -71,10 +71,10 @@ external void handleDecrementValue(String key, num value);
external void getLocation(double latitude, double longitude);

@JS('renderNotificationViewed')
external void renderNotificationViewed(JSObject object);
external void renderNotificationViewed(Object object);

@JS('renderNotificationViewed')
external void renderNotificationClicked(JSObject object);
external void renderNotificationClicked(Object object);

@JS('getInboxMessageCount')
external int getInboxMessageCount();
Expand All @@ -83,13 +83,13 @@ external int getInboxMessageCount();
external int getInboxMessageUnreadCount();

@JS('getAllInboxMessages')
external JSAny getAllInboxMessages();
external Map getAllInboxMessages();

@JS('getUnreadInboxMessages')
external JSAny getUnreadInboxMessages();
external Map getUnreadInboxMessages();

@JS('getInboxMessageForId')
external JSAny getInboxMessageForId(String messageId);
external Object getInboxMessageForId(String messageId);

@JS('deleteInboxMessage')
external void deleteInboxMessage(String messageId);
Expand All @@ -104,7 +104,7 @@ external void markReadAllInboxMessage();
external void markReadInboxMessagesForIds(List messageIds);

@JS('defineVariables')
external void defineVariables(JSObject object);
external void defineVariables(Object object);

@JS('syncVariables')
external void syncVariables();
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: clevertap_plugin
description: The CleverTap Flutter SDK for Mobile Customer Engagement,Analytics and Retention solutions.
version: 2.3.1
version: 2.3.2
homepage: https://github.com/CleverTap/clevertap-flutter

environment:
Expand All @@ -12,6 +12,7 @@ dependencies:
sdk: flutter
flutter_web_plugins:
sdk: flutter
js: ">=0.6.5"

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 598d9ac

Please sign in to comment.