Skip to content

Commit

Permalink
Merge pull request #12 from Countly/init-config-object
Browse files Browse the repository at this point in the history
added CountlyConfig and initWithConfig
  • Loading branch information
ArtursKadikis authored Apr 25, 2023
2 parents 6884892 + fc32cc9 commit e7a77e6
Show file tree
Hide file tree
Showing 6 changed files with 1,443 additions and 800 deletions.
96 changes: 63 additions & 33 deletions CountlyRNExample/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ import React, { Component } from 'react';
import { Text, ScrollView, Image, View, TextInput, StyleSheet, SafeAreaView, Platform, Alert } from 'react-native';
import CountlyButton from './CountlyButton';
import Countly from 'countly-sdk-react-native-bridge';
import CountlyConfig from 'countly-sdk-react-native-bridge/CountlyConfig';

const successCodes = [100, 101, 200, 201, 202, 205, 300, 301, 303, 305];
const failureCodes = [400, 402, 405, 408, 500, 501, 502, 505];
const COUNTLY_APP_KEY = 'YOUR_APP_KEY';
const COUNTLY_SERVER_KEY = 'https://xxx.count.ly';

class AttributionKey {
static IDFA = 'idfa';
static AdvertisingID = 'adid';
}
const campaignData = '{"cid":"[PROVIDED_CAMPAIGN_ID]", "cuid":"[PROVIDED_CAMPAIGN_USER_ID]"}';

//Base Countly Interfaces
interface UserDataPredefined {
name?: string;
Expand Down Expand Up @@ -102,39 +109,45 @@ class Example extends Component {
}

onInit = async () => {
if (!(await Countly.isInitialized())) {
/** Recommended settings for Countly initialisation */
Countly.setLoggingEnabled(true); // Enable countly internal debugging logs
Countly.enableCrashReporting(); // Enable crash reporting to report unhandled crashes to Countly
Countly.setRequiresConsent(true); // Set that consent should be required for features to work.
Countly.giveConsentInit(['location', 'sessions', 'attribution', 'push', 'events', 'views', 'crashes', 'users', 'push', 'star-rating', 'apm', 'feedback', 'remote-config']); // give conset for specific features before init.
Countly.setLocationInit('TR', 'Istanbul', '41.0082,28.9784', '10.2.33.12'); // Set user initial location.
/** Optional settings for Countly initialisation */
Countly.enableParameterTamperingProtection('salt'); // Set the optional salt to be used for calculating the checksum of requested data which will be sent with each request
// Countly.pinnedCertificates("count.ly.cer"); // It will ensure that connection is made with one of the public keys specified
// Countly.setHttpPostForced(false); // Set to "true" if you want HTTP POST to be used for all requests
Countly.enableApm(); // Enable APM features, which includes the recording of app start time.
Countly.pushTokenType(Countly.messagingMode.DEVELOPMENT, 'ChannelName', 'ChannelDescription'); // Set messaging mode for push notifications
if (Platform.OS.match('ios')) {
Countly.recordAttributionID('ADVERTISING_ID');
} else {
Countly.enableAttribution(); // Enable to measure your marketing campaign performance by attributing installs from specific campaigns.
}
Countly.configureIntentRedirectionCheck(['MainActivity'], ['com.countly.demo']);
Countly.setStarRatingDialogTexts('Title', 'Message', 'Dismiss');
await Countly.init(COUNTLY_SERVER_KEY, COUNTLY_APP_KEY); // Initialize the countly SDK.
Countly.appLoadingFinished();
/**
* Push notifications settings
* Should be call after init
*/
Countly.registerForNotification((theNotification: string) => {
let jsonString = JSON.stringify(JSON.parse(theNotification));
console.log('Just received this notification data: ' + jsonString);
Alert.alert('theNotification: ' + jsonString);
}); // Set callback to receive push notifications
Countly.askForNotificationPermission('android.resource://com.countly.demo/raw/notif_sample'); // This method will ask for permission, enables push notification and send push token to countly server.
const attributionValues = {};
if (Platform.OS.match('ios')) {
attributionValues[AttributionKey.IDFA] = 'IDFA';
} else {
attributionValues[AttributionKey.AdvertisingID] = 'AdvertisingID';
}

if (await Countly.isInitialized()) {
return;
}
const countlyConfig = new CountlyConfig(COUNTLY_SERVER_KEY, COUNTLY_APP_KEY)
.setLoggingEnabled(true) // Enable countly internal debugging logs
.enableCrashReporting() // Enable crash reporting to report unhandled crashes to Countly
.setRequiresConsent(true) // Set that consent should be required for features to work.
.giveConsent(['location', 'sessions', 'attribution', 'push', 'events', 'views', 'crashes', 'users', 'push', 'star-rating', 'apm', 'feedback', 'remote-config']) // give consent for specific features before init.
.setLocation('TR', 'Istanbul', '41.0082,28.9784', '10.2.33.12') // Set user initial location.
/** Optional settings for Countly initialisation */
.enableParameterTamperingProtection('salt') // Set the optional salt to be used for calculating the checksum of requested data which will be sent with each request
// .pinnedCertificates("count.ly.cer") // It will ensure that connection is made with one of the public keys specified
// .setHttpPostForced(false) // Set to "true" if you want HTTP POST to be used for all requests
.enableApm() // Enable APM features, which includes the recording of app start time.
.pushTokenType(Countly.messagingMode.DEVELOPMENT, 'ChannelName', 'ChannelDescription') // Set messaging mode for push notifications
.configureIntentRedirectionCheck(['MainActivity'], ['com.countly.demo'])
.setStarRatingDialogTexts('Title', 'Message', 'Dismiss')
.recordDirectAttribution('countly', campaignData)
.recordIndirectAttribution(attributionValues);

await Countly.initWithConfig(countlyConfig); // Initialize the countly SDK.
Countly.appLoadingFinished();
/**
* Push notifications settings
* Should be call after init
*/
Countly.registerForNotification((theNotification: string) => {
let jsonString = JSON.stringify(JSON.parse(theNotification));
console.log('Just received this notification data: ' + jsonString);
Alert.alert('theNotification: ' + jsonString);
}); // Set callback to receive push notifications
Countly.askForNotificationPermission('android.resource://com.countly.demo/raw/notif_sample'); // This method will ask for permission, enables push notification and send push token to countly server.
};

onStart = () => {
Expand Down Expand Up @@ -595,6 +608,21 @@ class Example extends Component {
Countly.setCustomMetrics(customMetric);
};

recordDirectAttribution = () => {
Countly.recordDirectAttribution('countly', campaignData);
};

recordIndirectAttribution = () => {
const attributionValues = {};
if (Platform.OS.match('ios')) {
attributionValues[AttributionKey.IDFA] = 'IDFA';
} else {
attributionValues[AttributionKey.AdvertisingID] = 'AdvertisingID';
}

Countly.recordIndirectAttribution(attributionValues);
};

test = () => {
this.onInit();
this.onStart();
Expand Down Expand Up @@ -637,7 +665,7 @@ class Example extends Component {
<Text style={[{ fontSize: 24, textAlign: 'center' }]}>React Native Demo App</Text>
</View>
<CountlyButton onPress={this.test} title="Test" color="#1b1c1d" lightText={true} />
<CountlyButton onPress={this.onInit} title="Init" color="#ffffff" />
<CountlyButton onPress={this.onInit} title="Init" color="#f0f0f0" />
<CountlyButton onPress={this.onStart} title="Start" color="#5bbd72" />
<CountlyButton onPress={this.onStop} title="Stop" color="#d95c5c" />
<Text style={[{ textAlign: 'center' }]}>.</Text>
Expand Down Expand Up @@ -882,6 +910,8 @@ class Example extends Component {
<CountlyButton onPress={this.endTrace} title="End Trace" color="#1b1c1d" lightText={true} />
<CountlyButton onPress={this.recordNetworkTraceSuccess} title="End Network Request Success" color="#1b1c1d" lightText={true} />
<CountlyButton onPress={this.recordNetworkTraceFailure} title="End Network Request Failure" color="#1b1c1d" lightText={true} />
<CountlyButton onPress={this.recordDirectAttribution} title="Record Direct Attribution" color="#1b1c1d" lightText={true} />
<CountlyButton onPress={this.recordIndirectAttribution} title="Record Indirect Attribution" color="#1b1c1d" lightText={true} />
<Text style={[{ textAlign: 'center' }]}>APM Example Start</Text>
<Text style={[{ textAlign: 'center' }]}>.</Text>
{/*
Expand Down
Loading

0 comments on commit e7a77e6

Please sign in to comment.