metrix_plugin 1.5.0 copy "metrix_plugin: ^1.5.0" to clipboard
metrix_plugin: ^1.5.0 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;
    });

    // iOS only
    Metrix.initialize('lcqmfsnvhzznvhe');

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

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

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

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

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

    // iOS only
    Metrix.setStore("AppStore");
    
    // iOS only
    Metrix.setAppSecret(1, 429751687, 1057026454, 796046595, 610423971);

    // iOS only
    Metrix.setDefaultTracker("uevt4h");
  }

  @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', {
                    "first": "second"
                  });
                  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('User attribution status: ${attribution?.attributionStatus ?? ""}')
            ),
          ]))
      ),
    );
  }
}