paywallViewEvent method
Future<void>
paywallViewEvent(
)
Implementation
Future<void> paywallViewEvent() async {
await ConscentMethods().getOSVersion();
var anonId = await CoreDb.instance().getAnonId();
anonId ??= '${Uuid().v4()}';
await CoreDb.instance().setAnonId(anonId);
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
String createdAt = dateFormat.format(DateTime.now());
_messageBodyData.clientId = ConscentInitializer.mClientId;
_messageBodyData.contentId = ConscentInitializer.mContentId;
_messageBodyData.anonId = anonId;
_messageBodyData.userId = await CoreDb.instance().getUserId();
_messageBodyData.deviceType = "Mobile";
_messageBodyData.eventLocation = "PAYWALL";
_messageBodyData.eventType = "VIEW";
_messageBodyData.paywallDisplayType = "INARTICLE";
_messageBodyData.isCookieBlocked = 0;
_messageBodyData.numOfCta = Constants.numOfCta;
if (Constants.paywallConfig.data != null) {
_messageBodyData.paywallId = Constants.paywallConfig.data?.sId;
_messageBodyData.numOfCta = Constants
.paywallConfig.data?.configuration?.mobile?.templateId?.numberOfCta;
_messageBodyData.paywallType = Constants
.paywallConfig.data?.configuration?.mobile?.templateId?.paywallType;
_messageBodyData.paywallDisplayType = Constants
.paywallConfig.data?.configuration?.mobile?.templateId?.displayType;
}
_messageBodyData.osVersion = Constants.osVersion;
_messageBodyData.mobileModel = Constants.mobileModel;
_messageBodyData.osName = Constants.osName;
_messageBodyData.userAgent = Constants.userAgent;
var paywallViewEvent = PaywallViewEvent(messageBody: [_messageBodyData]);
paywallViewEvent.topic = "demoTopic";
final headers = {'Content-Type': 'application/json'};
Map<String, dynamic> body = paywallViewEvent.toJson();
String jsonBody = json.encode(body);
final encoding = Encoding.getByName('utf-8');
var response = await http.post(
Uri.parse('${APIMode.EVENT_BASE_URL}/collect/event'),
headers: headers,
body: jsonBody,
encoding: encoding,
);
}