Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mylo.ai/react-native-usebutton

Package Overview
Dependencies
Maintainers
17
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mylo.ai/react-native-usebutton

React native module for the Button SDK

  • 0.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
17
Created
Source

react-native-usebutton

React native module for the Button's publisher SDK

Example app

Installation

$ yarn add @mylo.ai/react-native-usebutton

or

$ npm install --save @mylo.ai/react-native-usebutton

iOS setup

$ cd ios && pod install

Usage

import ButtonSdk from 'react-native-usebutton';

// Before you do anything you have to configure Button with your appID
const applicationId = Platform.select({
  ios: 'app-xxxxxxxxxxxxxxxx',
  android: 'app-xxxxxxxxxxxxxxxx',
});

ButtonSdk.identifyButtonApp(applicationId, error => {
  // If an error has occured, currently only works on iOS
  console.log(error);
});

// Identify a user (on user login)
const userId = 'user-123';
ButtonSdk.setIdentifier(userId);

// Clear all user's data (on user logout)
ButtonSdk.clearAllData();

// Fetch a purchase path from Button
ButtonSDK.startPurchasePath(
  {
    url: 'https://the.button.url',
    token: 'my-tracking-token',
    headerTitle: 'My Button Browser Title',
    headerSubtitle: 'My Button Browser Subtitle',
    headerTitleColor: '#FFFFF',
    headerSubtitleColor: '#FFFFF',
    headerBackgroundColor: '#FFFFF',
    headerTintColor: '#FFFFF',
    footerBackgroundColor: '#FFFFF',
    footerTintColor: '#FFFFF',
  },
  (error) => {
    // If error while fetching the url, you can get it in here!
    console.log(error);
  }
);

// Track impression
ButtonSdk.setImpressionView({
  url: 'https://the.button.url',
  visibleRateType: ButtonSdk.RATE_TYPE.PERCENT,
  creativeType: ButtonSdk.CREATIVE_TYPE.HERO,
  visibleRate: 7,
});

// Event when the browser is closed
ButtonSdk.addEventListener(
  ButtonSdk.EVENT.ON_BROWSER_CLOSED
  onHandlePurchaseClosed
);

// Remove event listener
ButtonSdk.removeEventListener(
  ButtonSdk.EVENT.ON_BROWSER_CLOSED
  onHandlePurchaseClosed
);

Properties for startPurchasePath

PropertyDescriptionRequiredDefault
urlThe merchant's url to fetchtrueNone
tokenA unique token that can be usefull for tracking a campaign for examplefalseNone
headerTitleThe title displayed in the headertrueNone
headerSubtitleThe subitle displayed in the headertrueNone
headerTitleColorThe title's colorfalsergb(255, 255, 255)
headerSubtitleColorThe subtitle's colorfalsergb(255, 255, 255)
headerBackgroundColorThe header's background colorfalsergb(0,0,0)
headerTintColorThe header's tint colorfalsergb(255, 255, 255)
footerBackgroundColorThe footer's background colorfalsergb(0,0,0)
footerTintColorThe footer's tint colorfalsergb(255, 255, 255)

Properties for setImpressionView

PropertyDescriptionRequiredDefault
urlThe merchant's url to tracktrueNone
visibleRateTypeThe rate type : could be percent or fixedtrueNone
creativeTypeThe creative typefalseCREATIVE_TYPE.HERO
visibleRateThe rate the user will be grantedtrueNone

Visible rate type

PropertyDescription
RATE_TYPE.PERCENTThe rate type is percentage
RATE_TYPE.FIXEDThe rate type is a fixed amount

Creative type

PropertyDescription
CREATIVE_TYPE.HEROThe hero creative type
CREATIVE_TYPE.CAROUSELThe carousel creative type
CREATIVE_TYPE.LISTThe list creative type
CREATIVE_TYPE.GRIDThe grid creative type
CREATIVE_TYPE.HEROThe hero creative type
CREATIVE_TYPE.OTHERThe other creative type

Events

PropertyDescription
EVENT.ON_BROWSER_CLOSEDThe user has closed the webview

Typescript

Here a list of the differrent types available:

interface ButtonEvent {
  ON_BROWSER_CLOSED: 'ON_BROWSER_CLOSED';
}

interface RateType {
  FIXED: 'FIXED';
  PERCENT: 'PERCENT';
}

interface CreativeType {
  HERO: 'HERO';
  CAROUSEL: 'CAROUSEL';
  LIST: 'LIST';
  GRID: 'GRID';
  DETAIL: 'DETAIL';
  OTHER: 'OTHER';
}

interface PurchasePathOptions {
  url: string;
  token?: string;
  headerTitle: string;
  headerSubtitle: string;
  headerTitleColor?: string;
  headerSubtitleColor?: string;
  headerBackgroundColor?: string;
  headerTintColor?: string;
  footerBackgroundColor?: string;
  footerTintColor?: string;
}

interface ImpressionViewOptions {
  url: string;
  visibleRateType: IRateType;
  visibleRate: number;
  offerId?: string;
  creativeType?: ICreativeType;
}

type ErrorCallback = (error: string) => void;

Troubleshooting

Android

The Button's SDK can cause your Android app not to be able to connect to the metro server, once installed.

To resolve this, you have to add in the directory android/app/src/main/res/xml of your application, a file named network_security_config.xml and copy/paste this content in it:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="true">localhost</domain>
  </domain-config>
</network-security-config>

Then in your AndroidManifest, add this android:networkSecurityConfig="@xml/network_security_config" inside the application tag.

It has been implemented in the Example app, if you want to see more.

Example app

To run the example app :

$ yarn bootstrap #Install all dependencies (node_modules and pods)
$ cd example && yarn start #Run the metro instance
$ cd .. && yarn example ios/android #Run the application on a simulator

Community

Contribution and development instructions can be found in CONTRIBUTING

License

MIT

Keywords

FAQs

Package last updated on 05 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc