Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added CountlyConfig and initWithConfig #12

Merged
merged 11 commits into from
Apr 25, 2023
100 changes: 65 additions & 35 deletions CountlyRNExample/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ 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';
const COUNTLY_APP_KEY = '58594c9a3f461ebc000761a68c2146659ef75ea0';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not have realy keys here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

const COUNTLY_SERVER_KEY = 'https://master.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 {
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')
.recordIndirectAttribution(attributionValues)
.recordDirectAttribution('countly', campaignData);

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 @@ -600,6 +613,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 @@ -642,7 +670,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 @@ -886,6 +914,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.recordIndirectAttribution} title="Record Direct Attribution" color="#1b1c1d" lightText={true} />
<CountlyButton onPress={this.recordDirectAttribution} title="Record Indirect Attribution" color="#1b1c1d" lightText={true} />
<Text style={[{ textAlign: 'center' }]}>APM Example Start</Text>
<Text style={[{ textAlign: 'center' }]}>.</Text>
{/*
Expand Down
12 changes: 8 additions & 4 deletions CountlyRNExample/ios/CountlyRNExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
5DCACB8F33CDC322A6C60F78 /* libPods-CountlyRNExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CountlyRNExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = CountlyRNExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
89C6BE57DB24E9ADA2F236DE /* Pods-CountlyRNExample-CountlyRNExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CountlyRNExample-CountlyRNExampleTests.release.xcconfig"; path = "Target Support Files/Pods-CountlyRNExample-CountlyRNExampleTests/Pods-CountlyRNExample-CountlyRNExampleTests.release.xcconfig"; sourceTree = "<group>"; };
C0461DFB29CB723100024CD1 /* CountlyRNExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = CountlyRNExample.entitlements; path = CountlyRNExample/CountlyRNExample.entitlements; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -86,6 +87,7 @@
13B07FAE1A68108700A75B9A /* CountlyRNExample */ = {
isa = PBXGroup;
children = (
C0461DFB29CB723100024CD1 /* CountlyRNExample.entitlements */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
Expand Down Expand Up @@ -485,8 +487,9 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = CountlyRNExample/CountlyRNExample.entitlements;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 375CMG7Z24;
DEVELOPMENT_TEAM = 3S32KFMHB8;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = CountlyRNExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -499,7 +502,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlySwift;
PRODUCT_NAME = CountlyRNExample;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -513,8 +516,9 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = CountlyRNExample/CountlyRNExample.entitlements;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 375CMG7Z24;
DEVELOPMENT_TEAM = 3S32KFMHB8;
INFOPLIST_FILE = CountlyRNExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -526,7 +530,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = ly.count.CountlySwift;
PRODUCT_NAME = CountlyRNExample;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand Down
4 changes: 4 additions & 0 deletions CountlyRNExample/ios/CountlyRNExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
</dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
Expand Down
Loading