Skip to content

Commit

Permalink
Merge pull request #288 from Countly/content-builder
Browse files Browse the repository at this point in the history
WIP: Implemented content builder
  • Loading branch information
turtledreams authored Nov 7, 2024
2 parents 4e2da14 + 17a421b commit 5c5aeda
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
* Added the config interface `experimental` to group experimental features.
* Added a flag `enablePreviousNameRecording` to add previous event/view and current view names as segmentation (Experimental!)
* Added a flag `enableVisibilityTracking` to add app visibility info to views (Experimental!)
* Added `Content` feature methods:
* `enterContentZone`, to start Content checks(Experimental!)
* `exitContentZone`, to stop content checks (Experimental!)
* Added support for `List` values in user given segmentations of timed events.

* Updated the underlying Firebase Messaging SDK to version 24.0.3

* Mitigated an issue where an event was not recorded if a `count` was not provided.
* Fixed an issue where automatic crash reporting failed to capture Flutter framework errors when using the newly introduced config option.
* Addressed an issue where asynchronous Dart errors were not being captured.
* Addressed an issue that prevented the stacktrace from being properly recognized on the server

* Updated the underlying Firebase Messaging SDK to version 24.0.3

* Updated underlying Android SDK version to 24.7.4
* Updated underlying iOS SDK version to 24.7.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,12 @@ else if ("getRequestQueue".equals(call.method)) {
} else if ("halt".equals(call.method)) {
Countly.sharedInstance().halt();
result.success("halt: success");
} else if ("enterContentZone".equals(call.method)) {
Countly.sharedInstance().contents().enterContentZone();
result.success(null);
} else if ("exitContentZone".equals(call.method)) {
Countly.sharedInstance().contents().exitContentZone();
result.success(null);
}
//------------------End------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions example/lib/page_others.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class OthersPage extends StatelessWidget {
Countly.instance.views.stopAllViews();
}

void enterContentZone() {
Countly.instance.content.enterContentZone();
}

void exitContentZone() {
Countly.instance.content.exitContentZone();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -90,6 +98,8 @@ class OthersPage extends StatelessWidget {
child: Center(
child: Column(
children: [
MyButton(text: 'Enter Content Zone', color: 'olive', onPressed: enterContentZone),
MyButton(text: 'Exit Content Zone', color: 'olive', onPressed: exitContentZone),
MyButton(text: 'Record Direct Attribution', color: 'olive', onPressed: recordDirectAttribution),
MyButton(text: 'Record Indirect Attribution', color: 'olive', onPressed: recordIndirectAttribution),
MyButton(text: 'Push Notification', color: 'blue', onPressed: askForNotificationPermission),
Expand Down
14 changes: 14 additions & 0 deletions ios/Classes/CountlyFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,20 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[Countly.sharedInstance appLoadingFinished];
});
result(@"appLoadingFinished: success");
} else if ([@"enterContentZone" isEqualToString:call.method]) {
dispatch_async(dispatch_get_main_queue(), ^{
[Countly.sharedInstance.content enterContentZone];
result(nil);
});

// setRequiresConsent
} else if ([@"exitContentZone" isEqualToString:call.method]) {
dispatch_async(dispatch_get_main_queue(), ^{
[Countly.sharedInstance.content exitContentZone];
result(nil);
});

// setRequiresConsent
} else {
result(FlutterMethodNotImplemented);
}
Expand Down
14 changes: 14 additions & 0 deletions lib/src/content_builder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//indicates the content status
enum ContentStatus { completed, closed}

typedef ContentCallback = void Function(ContentStatus contentStatus, Map<String, dynamic> contentData);

abstract class ContentBuilder {
/// This is an experimental feature and it can have breaking changes
// Opt in user for the content fetching and updates
Future<void> enterContentZone();

/// This is an experimental feature and it can have breaking changes
// Opt out user for the content fetching and updates
Future<void> exitContentZone();
}
29 changes: 29 additions & 0 deletions lib/src/content_builder_internal.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'content_builder.dart';
import 'countly_flutter.dart';
import 'countly_state.dart';

class ContentBuilderInternal implements ContentBuilder {
ContentBuilderInternal(this._countlyState);

final CountlyState _countlyState;

@override
Future<void> enterContentZone() async {
if (!_countlyState.isInitialized) {
Countly.log('enterContentZone, "initWithConfig" must be called before "clear"', logLevel: LogLevel.ERROR);
return;
}
Countly.log('Calling "enterContentZone"');
await _countlyState.channel.invokeMethod('enterContentZone');
}

@override
Future<void> exitContentZone() async {
if (!_countlyState.isInitialized) {
Countly.log('exitContentZone, "initWithConfig" must be called before "clear"', logLevel: LogLevel.ERROR);
return;
}
Countly.log('Calling "exitContentZone"');
await _countlyState.channel.invokeMethod('exitContentZone');
}
}
7 changes: 7 additions & 0 deletions lib/src/countly_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'dart:io' show Platform;
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:pedantic/pedantic.dart';

import 'content_builder_internal.dart';
import 'countly_config.dart';
import 'countly_state.dart';
import 'device_id.dart';
Expand Down Expand Up @@ -49,6 +51,7 @@ abstract class CountlyConsent {
static const String apm = 'apm';
static const String feedback = 'feedback';
static const String remoteConfig = 'remote-config';
static const String content = 'content';
}

class Countly {
Expand All @@ -59,6 +62,7 @@ class Countly {
_userProfileInternal = UserProfileInternal(_countlyState);
_viewsInternal = ViewsInternal(_countlyState);
_sessionsInternal = SessionsInternal(_countlyState);
_contentBuilderInternal = ContentBuilderInternal(_countlyState);
}
static final instance = _instance;
static final _instance = Countly._();
Expand All @@ -80,6 +84,9 @@ class Countly {
late final DeviceIDInternal _deviceIdInternal;
DeviceID get deviceId => _deviceIdInternal;

late final ContentBuilderInternal _contentBuilderInternal;
ContentBuilderInternal get content => _contentBuilderInternal;

/// ignore: constant_identifier_names
static const bool BUILDING_WITH_PUSH_DISABLED = false;
static const String _pushDisabledMsg = 'In this plugin Push notification is disabled, Countly has separate plugin with push notification enabled';
Expand Down

0 comments on commit 5c5aeda

Please sign in to comment.