metrix_plugin 1.1.6
metrix_plugin: ^1.1.6 copied to clipboard

Metrix SDK flutter plugin.

example/lib/main.dart

import 'package:metrix_plugin/Metrix.dart';
import 'package:metrix_plugin/MetrixAttribution.dart';
import 'package:flutter/material.dart';

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

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

class _MyAppState extends State<MyApp> {
  String sessionNumber = "";
  String sessionId = "";
  String userId = "";
  String deeplink = "";
  MetrixAttribution? attribution;

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

    setState(() {
      sessionNumber = "";
      sessionId = "";
      userId = "";
      deeplink = "";
      attribution = null;
    });

    Metrix.setPushToken('pushToken');

    Metrix.addUserAttributes({
      "name": "hisName"
    });

    Metrix.getAttributionData().then((value) => {
      this.setState(() {
        attribution = value;
      })
    });

    Metrix.shouldLaunchDeeplink = true;
    Metrix.getDeeplinkResponse().then((value) => {
      this.setState(() {
        deeplink = value;
      })
    });

    Metrix.getUserId().then((value) => {
      this.setState(() {
        userId = value;
      })
    });

    Metrix.getSessionNumber().then((sessionNum) => {
      this.setState(() {
        sessionNumber = sessionNum.toString();
      })
    });

    Metrix.getSessionId().then((id) => {
      this.setState(() {
        sessionId = id;
      })
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Metrix plugin example app'),
          ),
          body: Center(child: Column(children: <Widget>[
            Container(
                margin: EdgeInsets.all(20),
                child: Text('Session number is: $sessionNumber')
            ),
            Container(
                margin: EdgeInsets.all(20),
                child: Text('Session id is: $sessionId')
            ),
            Container(
              margin: EdgeInsets.all(20),
              child: FlatButton(
                child: Text('SendEvent'),
                color: Colors.blueAccent,
                textColor: Colors.white,
                onPressed: () {
                  Metrix.newEvent('lbuoa', {
                    "name": "hisName"
                  });
                  Metrix.newEvent('lbuoa');
                },
              ),
            ),
            Container(
              margin: EdgeInsets.all(20),
              child: FlatButton(
                child: Text('SendRevenue'),
                color: Colors.blueAccent,
                textColor: Colors.white,
                onPressed: () {
                  Metrix.newRevenue('ykwyp', 2500.5);
                  Metrix.newRevenue('ykwyp', 2500.5, currency: 0);
                  Metrix.newRevenue('ykwyp', 2500.5, currency: 0, orderId: "someId");
                  Metrix.newRevenue('ykwyp', 2500.5, orderId: "someId");
                },
              ),
            ),
            Container(
                margin: EdgeInsets.all(20),
                child: Text('UserId is: $userId')
            ),
            Container(
                margin: EdgeInsets.all(20),
                child: Text('Deeplink is: $deeplink')
            ),
            Container(
                margin: EdgeInsets.all(20),
                child: Text('User attribution status: ${attribution?.attributionStatus ?? ""}')
            ),
          ]))
      ),
    );
  }
}
0
likes
75
pub points
73%
popularity

Publisher

metrix.cc

Metrix SDK flutter plugin.

Homepage

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on metrix_plugin