Skip to content

Commit

Permalink
Merge pull request #166 from ifsnow/fix/update-api-example
Browse files Browse the repository at this point in the history
Update API.md and example for v5.4.1
  • Loading branch information
sokoloff06 authored Jul 23, 2020
2 parents 90ea758 + 90de87d commit c5a5e75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 99 deletions.
63 changes: 0 additions & 63 deletions Docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


- [initSdk](#initSdk)
- [trackAppLaunch](#trackAppLaunch)
- [onInstallConversionData](#onInstallConversionData)
- [onAppOpenAttribution](#onAppOpenAttribution)
- [trackEvent](#trackEvent)
Expand Down Expand Up @@ -79,68 +78,6 @@ try {
```

---
##### <a id="trackAppLaunch"> **`trackAppLaunch()`**

(iOS Only)

Necessary for tracking sessions and deep link callbacks in iOS on background-to-foreground transitions.<br/>
This API Should be used with the relevant [AppState](https://facebook.github.io/react-native/docs/appstate.html) logic.

*Example:*

```javascript
state = {
appState: AppState.currentState,
};

componentDidMount();
{
AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount();
{
AppState.removeEventListener('change', this._handleAppStateChange);
}

_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
if (Platform.OS === 'ios') {
appsFlyer.trackAppLaunch();
}
}

this.setState({appState: nextAppState});
};
```


Or with Hooks:

```javascript
const [appState, setAppState] = useState(AppState.currentState);

useEffect(() => {
function handleAppStateChange(nextAppState) {
if (appState.match(/inactive|background/) && nextAppState === 'active') {
if (Platform.OS === 'ios') {
appsFlyer.trackAppLaunch();
}
}

setAppState(nextAppState);
}

AppState.addEventListener('change', handleAppStateChange);

return () => {
AppState.removeEventListener('change', handleAppStateChange);
};
});
```

---

##### <a id="onInstallConversionData"> **`onInstallConversionData(callback) : function:unregister`**

Accessing AppsFlyer Attribution / Conversion Data from the SDK (Deferred Deeplinking).<br/>
Expand Down
51 changes: 15 additions & 36 deletions examples/demo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
View,
Text,
Button,
AppState
} from 'react-native';
import appsFlyer from 'react-native-appsflyer';

Expand Down Expand Up @@ -59,17 +58,7 @@ class App extends React.Component {

}

state = {
appState: AppState.currentState
}

componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);

// Optionaly remove listeners for deep link data if you no longer need them
if (onInstallConversionDataCanceller) {
onInstallConversionDataCanceller();
Expand All @@ -83,32 +72,22 @@ class App extends React.Component {
}
}

_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
if (Platform.OS === 'ios') {
appsFlyer.trackAppLaunch();
TrackEventPressed() {
const eventName = "af_test_event";
const eventValues = {
"af_event_param0" : "biz",
"af_event_param1" : "buz",
"af_event_param2" : "bizbuz"
};
appsFlyer.trackEvent(eventName, eventValues,
(result) => {
console.log(result);
},
(error) => {
console.error(error);
}
}
this.setState({appState: nextAppState});
};


TrackEventPressed() {
const eventName = "af_test_event";
const eventValues = {
"af_event_param0" : "biz",
"af_event_param1" : "buz",
"af_event_param2" : "bizbuz"
};
appsFlyer.trackEvent(eventName, eventValues,
(result) => {
console.log(result);
},
(error) => {
console.error(error);
}
)
}
)
}

render() {
return (
Expand Down

0 comments on commit c5a5e75

Please sign in to comment.