Getting Campaign Data
The AppTrove React Native SDK provides methods to retrieve campaign-related data, such as ad identifiers, campaign names, and click IDs, enabling personalized user experiences and detailed analytics. This section outlines how to access campaign data using the SDK.
Prerequisites
- AppTrove React Native SDK installed and initialized in your project
- A Trackier MMP account with access to the Trackier Panel
- React Native 0.60 or later
- Basic knowledge of JavaScript and React Native development
Retrieve Campaign Data
The SDK offers asynchronous methods to access various campaign attributes, which can be used to tailor user experiences or analyze campaign performance. These attributes include ad IDs, campaign IDs, channels, and custom parameters.
Steps to Retrieve Campaign Data
- Ensure the SDK is initialized in your React Native project.
- Use the provided
TrackierSDK
methods (e.g.,getAd
,getCampaign
,getClickId
) to retrieve specific campaign data attributes. - Handle the asynchronous responses using
.then
and.catch
to process the data or manage errors. - Optionally, integrate the retrieved data with an event or use it for in-app personalization.
JavaScript Example
import React from 'react';
import { TrackierConfig, TrackierSDK, TrackierEvent } from 'react-native-trackier';
import { StyleSheet, Text, View, TouchableHighlight } from 'react-native';
export default function App() {
// Initialize SDK
const trackierConfig = new TrackierConfig("xxxx-xx-4505-bc8b-xx", TrackierConfig.EnvironmentDevelopment);
TrackierSDK.initialize(trackierConfig);
const trackCampaignData = () => {
const trackierEvent = new TrackierEvent(TrackierEvent.UPDATE);
// Retrieve Campaign Data
TrackierSDK.getAd().then(val => console.log('Ad: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getAdSet().then(val => console.log('AdSet: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getAdSetID().then(val => console.log('AdSetID: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getCampaign().then(val => console.log('Campaign: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getCampaignID().then(val => console.log('CampaignID: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getChannel().then(val => console.log('Channel: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getClickId().then(val => console.log('ClickId: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getP1().then(val => console.log('P1: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getP2().then(val => console.log('P2: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getP3().then(val => console.log('P3: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getP4().then(val => console.log('P4: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getP5().then(val => console.log('P5: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getDlv().then(val => console.log('Dlv: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getPid().then(val => console.log('Pid: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.getIsRetargeting().then(val => console.log('IsRetargeting: ', val)).catch(e => console.log('Error: ', e));
TrackierSDK.trackEvent(trackierEvent);
};
return (
<View style={styles.container}>
<TouchableHighlight style={styles.button} onPress={trackCampaignData}>
<Text>Track Campaign Data</Text>
</TouchableHighlight>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
button: {
padding: 10,
backgroundColor: '#ddd',
},
});
Available Methods
The following asynchronous methods retrieve campaign-related data:
TrackierSDK.getAd()
: Returns the ad name.TrackierSDK.getAdSet()
: Returns the ad set name.TrackierSDK.getAdSetID()
: Returns the ad set ID.TrackierSDK.getCampaign()
: Returns the campaign name.TrackierSDK.getCampaignID()
: Returns the campaign ID.TrackierSDK.getChannel()
: Returns the channel name.TrackierSDK.getClickId()
: Returns the click ID.TrackierSDK.getP1()
toTrackierSDK.getP5()
: Returns custom parameters (P1 to P5).TrackierSDK.getDlv()
: Returns the deep link value.TrackierSDK.getPid()
: Returns the partner ID.TrackierSDK.getIsRetargeting()
: Returns whether the campaign is for retargeting.
Expected Outcome
The retrieved campaign data is logged to the console or can be used for analytics, personalization, or event tracking. The data is accessible in the Trackier Panel, enabling detailed campaign performance analysis.
Best Practices
- Handle Asynchronous Responses: Use
.then
and.catch
to properly handle the asynchronous nature of campaign data methods and manage errors. - Validate Data: Check for null or undefined values in the response to avoid runtime errors.
- Use for Personalization: Leverage campaign data (e.g.,
Campaign
,ClickId
) to customize user experiences, such as displaying targeted content. - Log for Debugging: Use
console.log
to verify retrieved data during development, especially inTrackierConfig.EnvironmentDevelopment
. - Integrate with Events: Combine campaign data with event tracking (e.g.,
TrackierEvent
) to enrich analytics in the Trackier Panel. - Comply with Privacy Regulations: Ensure campaign data handling complies with GDPR, CCPA, and other privacy laws, especially for user-specific data like
ClickId
. - Test in Development Mode: Use
TrackierConfig.EnvironmentDevelopment
to test campaign data retrieval without affecting production analytics.
Troubleshooting
- Campaign Data Returns Null or Undefined:
- Ensure the SDK is initialized before calling campaign data methods.
- Verify that the campaign is correctly set up in the Trackier Panel and associated with the app.
- Check console logs for errors in the
.catch
blocks.
- Incorrect Campaign Data:
- Confirm the app token and environment match the Trackier Panel configuration.
- Ensure the campaign data is populated in the Trackier MMP for the specific user or click.
- General Issues:
- Check console logs for errors related to
TrackierSDK
methods.
- Check console logs for errors related to
For further assistance, refer to the Trackier Documentation Portal or contact Trackier support at support@trackier.com.