flutter_smartlook 3.0.10 copy "flutter_smartlook: ^3.0.10" to clipboard
flutter_smartlook: ^3.0.10 copied to clipboard

PlatformAndroidiOS
outdated

Smartlook SDK wrapper for Flutter. Analyze user behavior in ways never possible before.

example/lib/main.dart

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

import 'package:flutter_smartlook/flutter_smartlook.dart';
import 'package:flutter_smartlook/enum.dart';

void main() => runApp(MyApp());

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

class CustomIntegrationListener implements IntegrationListener {
  @override
  void onSessionReady(String? dashboardSessionUrl) {
    print("DashboardUrl:");
    print(dashboardSessionUrl);
  }

  @override
  void onVisitorReady(String? dashboardVisitorUrl) {
    print("DashboardVisitorUrl:");
    print(dashboardVisitorUrl);
  }
}

class _MyAppState extends State<MyApp> {
  bool isSet = false;
  @override
  void initState() {
    super.initState();
    initSmartlook();
  }

  Future<void> initSmartlook() async {
    final SetupOptions options =
        (SetupOptionsBuilder('a934b945c51eceb563df7a727bc56b828fda9191')
              ..Fps = 2
              ..StartNewSession = true)
            .build();

    await Smartlook.setupAndStartRecording(options);
    setState(() {
      isSet = true;
    });
    Smartlook.setEventTrackingMode(EventTrackingMode.FULL_TRACKING);
    const List<EventTrackingMode> eventTrackingModes = [
      EventTrackingMode.FULL_TRACKING,
      EventTrackingMode.IGNORE_USER_INTERACTION
    ];
    Smartlook.setEventTrackingModes(eventTrackingModes);
    Smartlook.registerIntegrationListener(CustomIntegrationListener());
    Smartlook.setUserIdentifier('FlutterLul', {"flutter-usr-prop": "valueX"});
    Smartlook.setGlobalEventProperty("key_", "value_", true);
    Smartlook.setGlobalEventProperties({"A": "B"}, false);
    Smartlook.removeGlobalEventProperty("A");
    Smartlook.removeAllGlobalEventProperties();
    Smartlook.setGlobalEventProperty("flutter_global", "value_", true);
    Smartlook.enableWebviewRecording(true);
    Smartlook.enableWebviewRecording(false);
    Smartlook.enableCrashlytics(true);
    Smartlook.setReferrer("referer", "source");
    Smartlook.getDashboardSessionUrl(true);
  }

  @override
  Widget build(BuildContext context) {
    return SmartlookHelperWidget(
        child: MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: !isSet
              ? const Center(child: CircularProgressIndicator())
              : Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Image.asset("lib/Smartlook.png"),
                    const TimerWidget(),
                    const SizedBox(height: 15.0),
                    FutureBuilder(
                        future: Smartlook.isRecording(),
                        builder: (context, snapshot) {
                          if (snapshot.connectionState ==
                              ConnectionState.waiting) {
                            return const CircularProgressIndicator();
                          }
                          if (snapshot.data == null || snapshot.data == false) {
                            return ElevatedButton(
                              onPressed: () async {
                                await Smartlook.startRecording();
                                setState(() {});
                              },
                              child: const Text('Start recording'),
                            );
                          }
                          return ElevatedButton(
                            onPressed: () async {
                              await Smartlook.stopRecording();
                              setState(() {});
                            },
                            child: const Text('Stop recording'),
                          );
                        }),
                    const SizedBox(height: 15),
                    ElevatedButton(
                      onPressed: () {
                        Smartlook.startTimedCustomEvent("timed-event");
                      },
                      child: const Text('Start timed event'),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        Smartlook.trackCustomEvent(
                            "timed-event", {"property1": "value1"});
                      },
                      child: const Text('Track event'),
                    ),
                    const SizedBox(height: 15.0),
                    ElevatedButton(
                      onPressed: () {
                        Smartlook.trackNavigationEvent(
                            "nav-event", SmartlookNavigationEventType.enter);
                      },
                      child: const Text('Enter Navigation Event'),
                    ),
                    ElevatedButton(
                      onPressed: () {
                        Smartlook.trackNavigationEvent(
                            "nav-event", SmartlookNavigationEventType.exit);
                      },
                      child: const Text('Exit Navigation Event'),
                    ),
                  ],
                ),
        ),
      ),
    ));
  }
}

class TimerWidget extends StatefulWidget {
  const TimerWidget({Key? key}) : super(key: key);

  @override
  State<TimerWidget> createState() => _TimerWidgetState();
}

class _TimerWidgetState extends State<TimerWidget> {
  String _timeString =
      "${DateTime.now().hour} : ${DateTime.now().minute} :${DateTime.now().second}";

  @override
  void initState() {
    super.initState();
    Timer.periodic(const Duration(seconds: 1), (Timer t) => _getCurrentTime());
  }

  @override
  Widget build(BuildContext context) {
    return Text(
      _timeString,
      style: const TextStyle(fontSize: 18.0),
    );
  }

  void _getCurrentTime() {
    setState(() {
      _timeString =
          "${DateTime.now().hour} : ${DateTime.now().minute} :${DateTime.now().second}";
    });
  }
}
46
likes
130
points
30k
downloads

Publisher

verified publishersmartlook.com

Weekly Downloads

Smartlook SDK wrapper for Flutter. Analyze user behavior in ways never possible before.

Homepage

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_smartlook