trackier_sdk_flutter 1.6.75 copy "trackier_sdk_flutter: ^1.6.75" to clipboard
trackier_sdk_flutter: ^1.6.75 copied to clipboard

This is trackier flutter SDK

example/lib/main.dart

import 'dart:ffi';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:trackier_sdk_flutter/trackierfluttersdk.dart';
import 'package:trackier_sdk_flutter/trackierconfig.dart';
import 'package:trackier_sdk_flutter/trackierevent.dart';
import 'package:app_links/app_links.dart';
import 'package:fluttertoast/fluttertoast.dart';


void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    TrackerSDKConfig trackerSDKConfig = new TrackerSDKConfig( // simulator app - ee9f21fb-5848-4ed9-8d9c-e4093e6d220c
        "ee9f21fb-5848-4ed9-8d9c-e4093e6d220c", "development"); // tic tac toe - b551b474-e91c-470e-900b-971e5b954169
    //trackerSDKConfig.setManualMode(true);
    //trackerSDKConfig.disableOrganicTracking(false);
    trackerSDKConfig.deferredDeeplinkCallback = (uri){
      print('The value of deeplinkUrl is: $uri');
      Fluttertoast.showToast(
        msg:"The value of deeplinkUrl is: $uri",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.BOTTOM,
        backgroundColor: Colors.black,
        textColor: Colors.white,
        fontSize: 16.0,
      );
    };

   // Trackierfluttersdk.updatePostbackConversion(0);
    Trackierfluttersdk.setUserId("737263"); //Pass your userid
    Trackierfluttersdk.setUserEmail("userEmail@gmail.com");
    //trackerSDKConfig.enableAppleSearchAds(false);

    //trackerSDKConfig.setManualMode(true);
    trackerSDKConfig.setFacebookAppId("897kiw9239820930232");
    trackerSDKConfig.setAndroidId("783483343849837");
    Trackierfluttersdk.updateAppleAdsToken("897239283092309283");
    trackerSDKConfig.setAttributionParams({"partnerId": "google-ads-", "channel": "facebook",
      "adId": "ad_9876", "siteId":"sanu882", "ad":"sanu"});
    // var userAdditonalDetail = Map<String, Object>();
    // userAdditonalDetail["phoneNumber"] = 9876453210;
    //
    // Trackierfluttersdk.setUserAdditonalDetail(userAdditonalDetail);

    //Trackierfluttersdk.setLocalRefTrack(true, "_");

    //Trackierfluttersdk.parseDeeplink("https://www.sanu.com");

   //trackerSDKConfig.setRegion(TrackierRegion.IN);
    Trackierfluttersdk.initializeSDK(trackerSDKConfig);


    Trackierfluttersdk.resolveDeeplinkUrl("").then((deeplinkData) {
      print("Resolved URL: ${deeplinkData['url']}");
      //print("Product ID: ${deeplinkData['sdkParams']['product_id']}");
      print("Product ID: ${deeplinkData['sdkParams']}");
      Fluttertoast.showToast(
        msg:"The value of uriLinkStream is: $deeplinkData",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.BOTTOM,
        backgroundColor: Colors.black,
        textColor: Colors.white,
        fontSize: 16.0,
      );
    }).catchError((error) {
      print("Error resolving deeplink: $error");
    });

    final appLinks = AppLinks(); // AppLinks is singleton

// Subscribe to all events (initial link and further)
    final sub = appLinks.uriLinkStream.listen((uri) {
      Trackierfluttersdk.parseDeeplink(uri.toString());

      Trackierfluttersdk.resolveDeeplinkUrl(uri.toString()).then((deeplinkData) {
        print("Resolved URL: ${deeplinkData['url']}");
        print("Product ID: ${deeplinkData['sdkParams']['product_id']}");
        Fluttertoast.showToast(
          msg:"The value of uriLinkStream is: $deeplinkData",
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.BOTTOM,
          backgroundColor: Colors.black,
          textColor: Colors.white,
          fontSize: 16.0,
        );
      }).catchError((error) {
        print("Error resolving deeplink: $error");
      });
    });


    // Trackierfluttersdk.getTrackierId().then((trackierId) {
    //   print("Trackier ID: $trackierId");
    // }).catchError((error) {
    //   print("Error fetching Trackier ID: $error");
    // });

    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    // try {
    //   platformVersion = await Trackierfluttersdk.platformVersion ??
    //       'Unknown platform version';
    // } on PlatformException {
    //   platformVersion = 'Failed to get platform version.';
    // }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
     // _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Trackier Flutter Sample App'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextButton(
                style: TextButton.styleFrom(
                 // primary: Colors.blue,
                ),
                onPressed: _trackSimpleEvent,
                child: Text('Simple Events'),
              ),
              TextButton(
                style: TextButton.styleFrom(
                 // primary: Colors.blue,
                ),
                onPressed: _trackRevenueEvent,
                child: Text('Revenue Events'),
              ),
            ],
          ),
        ),
      ),
    );
  }

 /* Future<void> initUniLinks() async {
    // Get the initial uri that was used to start the app
    try {
      _initialUri = await getInitialUri();

      // Attach a listener to the uri stream
      _sub = uriLinkStream.listen((Uri? uri) {
        setState(() {
          _currentUri = uri;
        });
      }, onError: (err) {
        // Handle any errors here
      });

      // Get the action if the app was opened with an action intent
      _action = await getInitialLink();
    } on FormatException catch (e) {
      // Handle exception when parsing the URI
      print('Error parsing URI: $e');
    } on Exception catch (e) {
      // Handle general errors
      print('Error: $e');
    }
  }*/

  _trackSimpleEvent() {
    TrackierEvent trackierEvent = new TrackierEvent("1CFfUn3xEY");
    Trackierfluttersdk.setUserId("798e9w8ew09e8"); // Pass your userId here
    Trackierfluttersdk.setUserName("abc");
    Trackierfluttersdk.setUserPhone("6562127727");
    Gender gender = Gender.Male;
    trackierEvent.param1 = "pass your data";
    Trackierfluttersdk.setGender(gender);
    Trackierfluttersdk.setDOB("12/12/2003");
    trackierEvent.couponCode = "72378728372";
    //Trackierfluttersdk.fireInstall()
    Trackierfluttersdk.setIMEI("imei1", "iemi222");
    Trackierfluttersdk.setMacAddress("88239823232");
    var userData = Map<String, Object>();
    userData["phoneNumber"] = 9876453210;
    userData["name"] = "Test";
    trackierEvent.evMap = userData;
    //Trackierfluttersdk.parseDeeplink("https://trackier58.u9ilnk.me/d/aKDqzm0Rbp");
    Trackierfluttersdk.trackEvent(trackierEvent);

    Trackierfluttersdk
        .createDynamicLink(
      templateId: 'wy23Px',
      link: 'https://trackier58.u9ilnk.me',
      domainUriPrefix: 'trackier58.u9ilnk.me',
      deepLinkValue: 'CakeActivity',
      androidRedirect:
      'https://play.google.com/store/apps/details?id=com.trackier.vistmarket',
      sdkParameters: {'product_id': 'chocochip', 'quantity': '2'},
      attributionParameters: {
        'channel': 'my_channel',
        'media_source': 'at_invite',
        'campaign': 'sanu',
      },
      iosRedirect: 'https://www.example.com/ios',
      desktopRedirect: 'https://trackier.com',
      socialMeta: {
        'title': 'Your Title',
        'description': 'Your Description',
        'imageLink': 'https://www.example.com/image.jpg',
      },
    )
        .then((url) {
      // Success callback
      print('Deep Link URL: $url');
    })
        .catchError((err) {
      // Error callback
      print('Failed to create link: $err');
    });


    Trackierfluttersdk.resolveDeeplinkUrl("https://trackier58.u9ilnk.me/d/NKmWH9E7b1").then((deeplinkData) {
      print("Resolved URL: ${deeplinkData['url']}");
      print("Product ID: ${deeplinkData['sdkParams']['product_id']}");
    }).catchError((error) {
      print("Error resolving deeplink: $error");
    });
  }

  _trackRevenueEvent() {
    TrackierEvent trackierEvent = new TrackierEvent("1CFfUn3xEY");
    trackierEvent.revenue = 10.0;
    trackierEvent.currency = "INR";
    trackierEvent.orderId = "orderID";
    trackierEvent.param1 = "param1";
    trackierEvent.param2 = "param2";
    trackierEvent.discount = 2.0;
    trackierEvent.couponCode = "test1";
    Trackierfluttersdk.setUserName("abc");
    Trackierfluttersdk.setUserPhone("6562127727");
    trackierEvent.setEventValue("ev1", "eventValue1");
    trackierEvent.setEventValue("ev2", 1);
    Trackierfluttersdk.trackerEvent(trackierEvent);


    AppLinks().uriLinkStream.listen((uri) {
      debugPrint('deeplink app_link: $uri');
      Trackierfluttersdk.parseDeeplink(uri.toString());
    });
  }
}