tenjin_plugin 1.2.2 copy "tenjin_plugin: ^1.2.2" to clipboard
tenjin_plugin: ^1.2.2 copied to clipboard

A Flutter plugin to Tenjin SDK

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:tenjin_plugin/tenjin_sdk.dart';

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    TenjinSDK.instance.init(apiKey: '<API-KEY>');
    TenjinSDK.instance.optIn();
    TenjinSDK.instance.registerAppForAdNetworkAttribution();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Tenjin SDK')),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              TextButton(
                onPressed: () => TenjinSDK.instance.connect(),
                child: Text('connect'),
              ),
              TextButton(
                onPressed: () =>
                    TenjinSDK.instance.eventWithName('swipe_right'),
                child: Text('eventWithName'),
              ),
              TextButton(
                onPressed: () =>
                    TenjinSDK.instance.eventWithNameAndValue('item', 100),
                child: Text('eventWithNameAndValue'),
              ),
              if (Platform.isIOS)
                TextButton(
                  onPressed: () {
                    TenjinSDK.instance.requestTrackingAuthorization();
                  },
                  child: Text('Request Tracking Authorization'),
                ),
              TextButton(
                onPressed: () {
                  TenjinSDK.instance.transactionWithReceipt(
                    productId: 'productId',
                    currencyCode: 'USD',
                    quantity: 1,
                    unitPrice: 3.80,
                    iosReceipt: 'iosReceipt',
                    iosTransactionId: 'transactionId',
                    androidDataSignature: 'androidDataSignature',
                    androidPurchaseData: 'androidPurchaseData',
                  );
                },
                child: Text('Transaction with Receipt'),
              ),
              TextButton(
                onPressed: () {
                  TenjinSDK.instance.transaction('productId', 'USD', 1, 3.80);
                },
                child: Text('Transaction'),
              ),
              TextButton(
                onPressed: () {
                  TenjinSDK.instance.updatePostbackConversionValue(3);
                },
                child: Text('Update SKAN'),
              ),
              TextButton(
                onPressed: () {
                  TenjinSDK.instance.setCustomerUserId('test_user_id');
                },
                child: Text('Set customer userId'),
              ),
              TextButton(
                onPressed: () async {
                  try {
                    String? userId = await TenjinSDK.instance.getCustomerUserId();
                    if (userId != null) {
                      print(userId);
                    } else {
                      print('Failed to get customer user id');
                    }
                  } catch (e) {
                    print('Error: $e');
                  }
                },
                child: Text('Get user id'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
130
points
90
downloads

Publisher

verified publishertenjin.com

Weekly Downloads

A Flutter plugin to Tenjin SDK

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on tenjin_plugin