flutter_insider 1.1.0 flutter_insider: ^1.1.0 copied to clipboard
Flutter Plugin For Insider SDK. For more information, please visit our website.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter_insider/flutter_insider.dart';
import 'package:flutter_insider/src/user.dart';
import 'package:flutter_insider/src/product.dart';
import 'package:flutter_insider/enum/InsiderGender.dart';
import 'package:flutter_insider/enum/InsiderCallbackAction.dart';
import 'package:flutter_insider/enum/ContentOptimizerDataType.dart';
import 'package:flutter_insider/src/event.dart';
import 'package:flutter_insider/enum/Vendors.dart';
import 'package:flutter_insider/src/identifiers.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
String _callbackData = 'Unknown';
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
initInsider();
}
Future initInsider() async {
if (!mounted) return;
// Call in async method.
await FlutterInsider.Instance.init(
"shopbagg", "group.com.useinsider.iGurmeV3", (int type, dynamic data) {
switch (type) {
case InsiderCallbackAction.NOTIFICATION_OPEN:
print("[INSIDER][NOTIFICATION_OPEN]: " + data.toString());
setState(() {
_callbackData = data.toString();
});
break;
case InsiderCallbackAction.INAPP_BUTTON_CLICK:
print("[INSIDER][INAPP_BUTTON_CLICK]: " + data.toString());
setState(() {
_callbackData = data.toString();
});
break;
case InsiderCallbackAction.TEMP_STORE_PURCHASE:
print("[INSIDER][TEMP_STORE_PURCHASE]: " + data.toString());
setState(() {
_callbackData = data.toString();
});
break;
case InsiderCallbackAction.TEMP_STORE_ADDED_TO_CART:
print("[INSIDER][TEMP_STORE_ADDED_TO_CART]: " + data.toString());
setState(() {
_callbackData = data.toString();
});
break;
case InsiderCallbackAction.TEMP_STORE_CUSTOM_ACTION:
print("[INSIDER][TEMP_STORE_CUSTOM_ACTION]: " + data.toString());
setState(() {
_callbackData = data.toString();
});
break;
default:
print("[INSIDER][InsiderCallbackAction]: Unregistered Action!");
break;
}
});
// This is an utility method, if you want to handle the push permission in iOS own your own you can omit the following method.
FlutterInsider.Instance.registerWithQuietPermission(false);
FlutterInsider.Instance.startTrackingGeofence();
}
void regression() {
List<String> tax = new List(4);
tax[0] = "tax1";
tax[1] = "tax2";
tax[2] = "tax3";
FlutterInsider.Instance.startTrackingGeofence();
FlutterInsider.Instance.registerWithQuietPermission(false);
// FlutterInsider.Instance.getSmartRecommendation(1, "tr_TR", "TRY");
//FlutterInsider.Instance.getContentBoolWithName("variableName", true, 12);
// FlutterInsider.Instance.getContentIntWithName("variableName", 12, 212);
// FlutterInsider.Instance.getContentStringWithName("variableName", "defaultValue", 23);
tax[1] = "123";
FlutterInsiderProduct pro = FlutterInsider.Instance.createNewProduct(
"ID-123", "name-123", tax, "IMG-123", 523.23, "CUR-123"); //doğru
pro.setQuantity(3); //doğru
FlutterInsider.Instance.itemPurchased("sale-001", pro); //doğru e_guid
tax[1] = "124";
FlutterInsiderProduct pro1 = FlutterInsider.Instance.createNewProduct(
"ID-124", "name-124", tax, "IMG-124", 10, "CUR-124");
FlutterInsider.Instance.itemAddedToCart(pro1); //doğru
FlutterInsider.Instance.cartCleared(); //doğru
tax[1] = "125";
FlutterInsiderProduct pro7 = FlutterInsider.Instance.createNewProduct(
"ID-1",
"name-2",
tax,
"IMG-4",
12.34,
"CUR-5"); // item added to cartın içinde quantity otomatik 1 aldı set ettiklerim doğru geldi aşağıda
FlutterInsider.Instance.itemAddedToCart(pro7); //doğru
pro7.setQuantity(-2); //doğru pozitif olanı aldı
pro7.setQuantity(20); // doğru
pro7.setColor("maviiiii"); // YANLIŞ GELMEDİ?????????
pro7.setStock(null);
pro7.setStock(-2);
pro7.setColor("#2131321");
pro7.setVoucherName("test_v"); //gelmedi
pro7.setPromotionName("test_p"); // gelmedi
pro7.setPromotionName("azz_pro"); // YANLIŞ GELMEDİ ???????????
pro7.setSize("size_21"); //gelmedi
pro7.setStock(0); // st doğru
pro7.setSalePrice(1231.2121); // usp doğru
pro7.setShippingCost(23); // sc doğru
pro7.setVoucherDiscount(0); // vd doğru
pro7.setPromotionDiscount(2); // pd 2 doğru
pro7.setCustomAttributeWithString(
"my_name", "test_string"); // YANLIS GELMEDİİİİİİİİİİİİİİİİİİ ?
pro7.setCustomAttributeWithBoolean("is_got", true); //doğru
pro7.setCustomAttributeWithInt("inte_ger", 121212); //doğru
pro7.setCustomAttributeWithDouble("double_double", 33333.2); // doğru
pro7.setCustomAttributeWithDate("zaman_dursun", new DateTime.now()); //doğru
List<String> trr = new List(4);
trr[0] = "deneme1";
trr[1] = "deneme22";
trr[2] = "deneme3";
trr[3] = null;
pro7.setCustomAttributeWithArray(
"test_keko", trr); // doğru bosluklu yollayınca valid değil diyor.
FlutterInsider.Instance.itemPurchased("123", pro7); // doğru e_guid
tax[1] = "120";
FlutterInsiderProduct pro4 = FlutterInsider.Instance.createNewProduct(
"ID-120", "name-120", tax, "IMG-120", 12.34, "CUR-120");
pro4.setQuantity(4);
FlutterInsider.Instance.itemPurchased(null, null);
tax[1] = "122";
FlutterInsiderProduct pro3 = FlutterInsider.Instance.createNewProduct(
"ID-122", "name-122", tax, "IMG-122", 12.34, "CUR-122");
pro3.setQuantity(0);
FlutterInsider.Instance.itemAddedToCart(pro3);
List<FlutterInsiderProduct> products = new List(2);
products[0] = pro4;
products[1] = pro3;
FlutterInsider.Instance.visitCartPage(products);
FlutterInsider.Instance.visitHomePage(); //doğru
// FlutterInsider.Instance.visitListingPage(null);
tax[1] = "shooes";
FlutterInsider.Instance.visitListingPage(tax);
// FlutterInsider.Instance.visitProductDetailPage(null);//doğru
FlutterInsider.Instance.visitProductDetailPage(pro4);
FlutterInsider.Instance.itemRemovedFromCart("5"); //doğru
FlutterInsider.Instance.setGDPRConsent(true);
//FlutterInsider.Instance.setGDPRConsent(false);
List<String> arr = new List(4);
arr[0] = "item1";
arr[1] = "item2";
arr[2] = "item3";
arr[3] = null;
//user
DateTime time = new DateTime.now();
FlutterInsiderUser insiderUser = FlutterInsider.Instance.getCurrentUser();
insiderUser.setCustomAttributeWithString("key_str", "erdem");
// insiderUser.setCustomAttributeWithString("key,str", null);
insiderUser.setCustomAttributeWithInt("key_int", 122);
insiderUser.unsetCustomAttribute(
"key_int"); //doğru ama neden set ederken value koyabılıyorum da unsette koyamıyorum.
insiderUser.setCustomAttributeWithBoolean("key_bool", false);
// insiderUser.setCustomAttributeWithBoolean("key_bool",null);
// insiderUser.setCustomAttributeWithDouble("key_double", 121212.12);
insiderUser.setCustomAttributeWithDouble("key_double", null);
insiderUser.setCustomAttributeWithDate("key_date", new DateTime.now());
insiderUser.setCustomAttributeWithArray("key_array", arr);
insiderUser.setCustomAttributeWithInt("key_str22222", 121);
insiderUser.setBirthday(new DateTime.now());
insiderUser.setName("aziz");
insiderUser.setSurname("karayel");
insiderUser.setFacebookID("face");
insiderUser.setTwitterID("twit");
insiderUser.setGender(InsiderGender.MALE);
insiderUser.setEmail("azizkarayel@gmail.com");
insiderUser.setPhoneNumber("12345678");
insiderUser.setLanguage("arapca");
insiderUser.setAge(23);
insiderUser.setSMSOptin(true);
insiderUser.setEmailOptin(false);
insiderUser.setLocationOptin(true);
//insiderUser.setLocationOptin(false);
//insiderUser.login();
// insiderUser.logout();
// insiderUser.setUserIdentifierWithEmail("azizkarayel96@gmail.com");
// insiderUser.setUserIdentifierWithPhoneNumber("2323233223");
// insiderUser.setUserIdentifierWithUserID("131133");
// insiderUser.unsetUserIdentifierPhoneNumber();
//event
FlutterInsider.Instance.tagEvent("reg_event").build();
FlutterInsider.Instance.tagEvent("reg_tag_ev")
.addParameterWithBoolean("tag_bool", false)
.addParameterWithDouble("tag_double", 22.2)
.addParameterWithInt("tag_int", 122)
.addParameterWithString("tag_str", "keko")
.addParameterWithDate("tag_date", new DateTime.now())
.addParameterWithArray("tag_arr", arr)
.build();
}
Future<void> content() async {
List<int> vendors = new List();
vendors.add(Vendors.OPPO);
vendors.add(Vendors.XIAOMI);
FlutterInsider.Instance.getAutoStartPermission(vendors);
// String content = await FlutterInsider.Instance.getContentStringWithName("variableName", "defaultValue", ContentOptimizerDataType.CONTENT);
// print(content);
}
Future<void> reco() async {
Map recoo =
await FlutterInsider.Instance.getSmartRecommendation(0, "tr_TR", "TRY");
print(recoo);
}
Future<void> message() async {
List messages = await FlutterInsider.Instance.getMessageCenterData(
new DateTime(2019), new DateTime(2020), 20);
print(messages);
}
Future trigger() async {
// --- CANBERK DEFAULTS -- //
// --- USER --- //
// You can crete Insider User and add attributes later on it.
FlutterInsiderUser currentUser = FlutterInsider.Instance.getCurrentUser();
// Setting User Attributes
currentUser.setName("Insider");
currentUser.setSurname("Demo");
currentUser.setAge(23);
currentUser.setGender(InsiderGender.OTHER);
currentUser.setBirthday(new DateTime.now());
currentUser.setEmailOptin(true);
currentUser.setSMSOptin(false);
currentUser.setPushOptin(true);
currentUser.setLocationOptin(true);
currentUser.setFacebookID("Facebook-ID");
currentUser.setTwitterID("Twittter-ID");
currentUser.setLanguage("TR");
// Setting User Identifiers.
FlutterInsiderIdentifiers identifiers = new FlutterInsiderIdentifiers();
identifiers.addEmail("1");
identifiers.addPhoneNumber("2");
identifiers.addUserID("3");
// Login and Logout
await currentUser.login(identifiers);
await currentUser.logout();
// Setting custom attributes.
// MARK: Your attribute key should be all lowercased and should not include any special or non Latin characters or any space, otherwise this attribute will be ignored. You can use underscore _.
currentUser.setCustomAttributeWithString(
"string_attribute", "This is Insider.");
currentUser.setCustomAttributeWithInt("int_attribute", 10);
currentUser.setCustomAttributeWithDouble("double_attribute", 20.5);
currentUser.setCustomAttributeWithBoolean("bool_attribute", true);
currentUser.setCustomAttributeWithDate(
"date_attribute", new DateTime.now());
// MARK: You can only call the method with array of string otherwise this event will be ignored.
List<String> arr = new List(4);
arr[0] = "value1";
arr[1] = "value2";
arr[2] = "value3";
arr[3] = null;
FlutterInsider.Instance.getCurrentUser()
.setCustomAttributeWithArray("key", arr);
// --- EVENT --- //
// You can create an event without parameters and call the build method
FlutterInsider.Instance.tagEvent("first_event").build();
// You can create an event then add parameters and call the build method
FlutterInsider.Instance.tagEvent("second_event")
.addParameterWithInt("int_parameter", 10)
.build();
// You can create an object and add the parameters later
FlutterInsiderEvent insiderExampleEvent =
FlutterInsider.Instance.tagEvent("third_event");
insiderExampleEvent
.addParameterWithString("string_parameter", "This is Insider.")
.addParameterWithInt("int_parameter", 10)
.addParameterWithDouble("double_parameter", 10.5)
.addParameterWithBoolean("bool_parameter", true)
.addParameterWithDate("date_parameter", new DateTime.now());
// MARK: You can only call the method with array of string otherwise this event will be ignored.
insiderExampleEvent.addParameterWithArray("array_parameter", arr);
// Do not forget to call build method once you are done with parameters.
// Otherwise your event will be ignored.
insiderExampleEvent.build();
// --- PRODUCT --- //
// MARK: If any parameter which is passed to this method is nil / null or an empty string, it will return an empty and invalid Insider Product Object. Note that an invalid Insider Product object will be ignored for any product related operations.
// You can crete Insider Product and add attributes later on it.
List<String> taxonomy = new List(4);
taxonomy[0] = "tax1";
taxonomy[1] = "tax2";
taxonomy[2] = "tax3";
FlutterInsiderProduct insiderExampleProduct =
FlutterInsider.Instance.createNewProduct("productID", "productName",
taxonomy, "imageURL", 1000.5, "currency");
// Setting Product Attributes in chainable way.
insiderExampleProduct
.setColor("color")
.setVoucherName("voucherName")
.setVoucherDiscount(10.5)
.setPromotionName("promotionName")
.setPromotionDiscount(10.5)
.setSize("size")
.setSalePrice(10.5)
.setShippingCost(10.5)
.setQuantity(10)
.setStock(10);
// Setting custom attributes.
// MARK: Your attribute key should be all lowercased and should not include any special or non Latin characters or any space, otherwise this attribute will be ignored. You can use underscore _.
insiderExampleProduct
.setCustomAttributeWithString("string_parameter", "This is Insider.")
.setCustomAttributeWithInt("int_parameter", 10)
.setCustomAttributeWithDouble("double_parameter", 10.5)
.setCustomAttributeWithBoolean("bool_parameter", true)
.setCustomAttributeWithDate("date_parameter", new DateTime.now());
// MARK: You can only call the method with array of string otherwise this event will be ignored.
insiderExampleProduct.setCustomAttributeWithArray("array_parameter", arr);
// --- REVENUE TRACKING --- //
FlutterInsider.Instance.itemPurchased(
"uniqueSaleID", insiderExampleProduct);
// --- CART REMINDER --- //
// Adding item to cart.
FlutterInsider.Instance.itemAddedToCart(insiderExampleProduct);
// Removing item from the cart.
FlutterInsider.Instance.itemRemovedFromCart("productID");
// Removing all the items from the cart.
// This method will automatically triggered when you call Revenue Tracking.
FlutterInsider.Instance.cartCleared();
// --- RECOMMENDATION ENGINE --- //
// ID comes from your smart recommendation campaign.
// Please follow the language code structure. For instance tr:TR.
Map recommendationWithID =
await FlutterInsider.Instance.getSmartRecommendation(1, "tr:TR", "TRY");
print("[INSIDER][getSmartRecommendation]: " +
recommendationWithID.toString());
Map recommendationWithProduct =
await FlutterInsider.Instance.getSmartRecommendationWithProduct(
insiderExampleProduct, 1, "tr:TR");
print("[INSIDER][getSmartRecommendationWithProduct]: " +
recommendationWithProduct.toString());
// --- SOCIAL PROOF --- //
FlutterInsider.Instance.visitProductDetailPage(insiderExampleProduct);
// --- PAGE VISITING --- //
FlutterInsider.Instance.visitHomePage();
FlutterInsider.Instance.visitListingPage(taxonomy);
List<FlutterInsiderProduct> insiderExampleProducts = new List(2);
insiderExampleProducts[0] = insiderExampleProduct;
insiderExampleProducts[1] = insiderExampleProduct;
FlutterInsider.Instance.visitCartPage(insiderExampleProducts);
// --- GDPR --- //
// MARK: Please note that by default our SDK is collecting the data so you don't have to call this function if you are not asking users consents.
// MARK: If you set false, the user will not share any data or receive any push until you set back true.
FlutterInsider.Instance.setGDPRConsent(true);
// --- MESSAGE CENTER --- //
List messageCenterData = await FlutterInsider.Instance.getMessageCenterData(
new DateTime(2019), new DateTime(2020), 20);
print("[INSIDER][getMessageCenterData]: " + messageCenterData.toString());
// --- CONTENT OPTIMIZER --- //
// String
var contentOptimizerString =
await FlutterInsider.Instance.getContentStringWithName(
"string_variable_name",
"defaultValue",
ContentOptimizerDataType.ELEMENT);
print("[INSIDER][getContentStringWithName]: " +
contentOptimizerString.toString());
// Boolean
var contentOptimizerBool =
await FlutterInsider.Instance.getContentBoolWithName(
"bool_variable_name", true, ContentOptimizerDataType.ELEMENT);
print("[INSIDER][getContentBoolWithName]: " +
contentOptimizerBool.toString());
// Integer
var contentOptimizerInt =
await FlutterInsider.Instance.getContentIntWithName(
"int_variable_name", 10, ContentOptimizerDataType.ELEMENT);
print(
"[INSIDER][getContentIntWithName]: " + contentOptimizerInt.toString());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: FlatButton(
onPressed: () {
trigger();
},
child: Text(_callbackData),
color: Colors.lightBlue,
)),
),
);
}
}