This module provides react-native bindings for the [Tapjoy SDK](https://home.tapjoy.com/developers/).
Tapjoy is a monetization and distribution services provider for mobile applications. Tapjoy’s goal is to maximize the value of every user for freemium mobile app publishers. Its Marketing Automation and Monetization Platform for mobile apps uses market leading data science, user segmentation and predictive analytics to drive deeper engagement and optimize revenue from every user.
React Native lets you build mobile apps using only JavaScript. It uses the same design as React, letting you compose a rich mobile UI from declarative components. You don't build a “mobile web app”, an “HTML5 app”, or a “hybrid app”. You build a real mobile app that's indistinguishable from an app built using Objective-C or Java.
npm install react-native-tapjoy --save
or:
yarn add react-native-tapjoy
react-native link
TypeScript definitions are included.
const options = {
sdkKeyIos: "12345",
sdkKeyAndroid: "12345",
gcmSenderIdAndroid: "12345",
debug: true
};
import { Tapjoy } from 'react-native-tapjoy';
const tapjoy = new Tapjoy(options);
try {
const initialized = await tapjoy.initialse();
// tapjoy is initialized
} catch (e) {
// error on initialization
}
import { useEffect } from 'react';
import { useTapjoy } from 'react-native-tapjoy';
const [
{
tapjoyEvents
},
{
initialiseTapjoy,
listenToEvent,
addTapjoyPlacement,
showTapjoyPlacement,
requestTapjoyPlacementContent,
isTapjoyConnected,
tapjoyListenForEarnedCurrency,
getTapjoyCurrencyBalance,
setTapjoyUserId,
spendTapjoyCurrency,
},
] = useTapjoy(tapjoyOptions);
useEffect(() => {
try {
const initialized = await initialiseTapjoy();
// tapjoy is initialized
} catch (e) {
// error on initialization
}
}, []);
This is a list of events you may subscribe to:
Event Name | Description |
---|---|
earnedCurrency |
Fired when currency was earned. The response contains the fields amount currencyName and currencyID (iOS only). |
onPlacementDismiss |
Fired when a shown placement was dismissed. The response contains the field placementName . |
onPlacementContentReady |
Fired when a placement's content is ready to be shown. The response contains the field placementName . |
onPurchaseRequest |
Fired when a purchase is requested. The response contains the fields placementName , requestId , token and productId . |
onRewardRequest |
Fired when a reward is requested. The response contains the fields placementName , requestId , token , itemId and quantity . |
tapjoy._on(eventName, () => {
// event has fired
})
You may get a list of events from the constants: tapjoy.constants
. It contains a events
field.
listenToEvent(eventName, () => {
// event has fired
})
You may get a list of events from useTapjoy
hook, named tapjoyEvents
.
try {
await tapjoy.addPlacement();
// tapjoy placement was added
} catch (e) {
// error
}
useEffect(() => {
try {
await addTapjoyPlacement('TestPlacement');
// tapjoy placement was added
} catch (e) {
// error
}
}, []);
try {
await tapjoy.requestContent('TestPlacement');
// tapjoy placement content request was successful
} catch (e) {
// request failed
}
useEffect(() => {
try {
await requestTapjoyPlacementContent('TestPlacement');
// tapjoy placement content request was successful
} catch (e) {
// request failed
}
}, []);
try {
await tapjoy.showPlacement('TestPlacement');
// tapjoy placement content is showing
} catch (e) {
// placement not added, or content not ready
}
useEffect(() => {
try {
await showTapjoyPlacement('TestPlacement');
// tapjoy placement content is showing
} catch (e) {
// placement not added, or content not ready
}
}, []);
try {
await tapjoy.listenForEarnedCurrency(({ amount, currencyName, currencyID }) => {
// user earned currency
});
} catch (e) {
// error
}
useEffect(() => {
try {
await tapjoyListenForEarnedCurrency(({ amount, currencyName, currencyID }) => {
// user earned currency
});
} catch (e) {
// error
}
}, []);
try {
const { amount, currencyName } = await tapjoy.getCurrencyBalance();
} catch (e) {
// error
}
useEffect(() => {
try {
const { amount, currencyName } = await getTapjoyCurrencyBalance();
} catch (e) {
// error
}
}, []);
try {
await tapjoy.spendCurrencyAction(42);
} catch (e) {
// error
}
useEffect(() => {
try {
await spendTapjoyCurrency(42);
} catch (e) {
// error
}
}, []);