diff --git a/CountlyRNExample/.eslintignore b/CountlyRNExample/.eslintignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/CountlyRNExample/.eslintignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/CountlyRNExample/.eslintrc.js b/CountlyRNExample/.eslintrc.js deleted file mode 100644 index 40c6dcd..0000000 --- a/CountlyRNExample/.eslintrc.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - root: true, - extends: '@react-native-community', -}; diff --git a/CountlyRNExample/.eslintrc.json b/CountlyRNExample/.eslintrc.json new file mode 100644 index 0000000..223dfc0 --- /dev/null +++ b/CountlyRNExample/.eslintrc.json @@ -0,0 +1,123 @@ +{ + "env": { + "react-native/react-native": true + }, + "extends": ["plugin:react/recommended", "prettier", "eslint:recommended", "plugin:@typescript-eslint/recommended"], + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 8, + "sourceType": "module" + }, + "parser": "@typescript-eslint/parser", + "plugins": ["react", "react-native", "@typescript-eslint"], + "root": true, + "rules": { + //JavaScript rules + + // allow .js files to contain JSX code + "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx", ".tsx"] }], + + // prevent eslint to complain about the "styles" variable being used before it was defined + "no-use-before-define": ["error", { "variables": false }], + + // ignore errors for the react-navigation package + "react/prop-types": ["error", { "ignore": ["navigation", "navigation.navigate"] }], + "no-var": "warn", + "curly": ["error", "all"], + + //TypeScript related rules + "@typescript-eslint/adjacent-overload-signatures": "error", + "@typescript-eslint/array-type": "warn", + "@typescript-eslint/await-thenable": "error", + "@typescript-eslint/ban-ts-comment": "error", //??? + "@typescript-eslint/ban-types": "error", + "@typescript-eslint/class-literal-property-style": "warn", + "@typescript-eslint/consistent-generic-constructors": "warn", + "@typescript-eslint/consistent-indexed-object-style": "warn", + "@typescript-eslint/consistent-type-assertions": "warn", + "@typescript-eslint/consistent-type-definitions": "warn", + "@typescript-eslint/consistent-type-exports": "warn", + "@typescript-eslint/consistent-type-imports": "warn", + "@typescript-eslint/explicit-function-return-type": "warn", + "@typescript-eslint/explicit-member-accessibility": "warn", + "@typescript-eslint/explicit-module-boundary-types": "warn", + "@typescript-eslint/member-ordering": "warn", //??? + "@typescript-eslint/method-signature-style": "warn", + //"@typescript-eslint/naming-convention": "warn" + "@typescript-eslint/no-base-to-string": "warn", + "@typescript-eslint/no-confusing-non-null-assertion": "warn", + "@typescript-eslint/no-confusing-void-expression": "warn", + "@typescript-eslint/no-duplicate-enum-values": "warn", + "@typescript-eslint/no-dynamic-delete": "warn", + "@typescript-eslint/no-empty-interface": "error", + "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/no-extra-non-null-assertion": "error", + "@typescript-eslint/no-extraneous-class": "warn", + "@typescript-eslint/no-floating-promises": "error", + "@typescript-eslint/no-for-in-array": "error", + "@typescript-eslint/no-inferrable-types": "error", + "@typescript-eslint/no-invalid-void-type": "warn", + "@typescript-eslint/no-meaningless-void-operator": "warn", + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/no-misused-promises": "error", + "@typescript-eslint/no-namespace": "error", + "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "warn", + "@typescript-eslint/no-non-null-asserted-optional-chain": "error", + "@typescript-eslint/no-non-null-assertion": "warn", + "@typescript-eslint/no-redundant-type-constituents": "warn", + "@typescript-eslint/no-require-imports": "warn", + "@typescript-eslint/no-this-alias": "error", + "@typescript-eslint/no-type-alias": "warn", + "@typescript-eslint/no-unnecessary-boolean-literal-compare": "warn", + "@typescript-eslint/no-unnecessary-condition": "warn", + "@typescript-eslint/no-unnecessary-qualifier": "warn", + "@typescript-eslint/no-unnecessary-type-arguments": "warn", + "@typescript-eslint/no-unnecessary-type-assertion": "error", + "@typescript-eslint/no-unnecessary-type-constraint": "error", + "@typescript-eslint/no-unsafe-argument": "error", + "@typescript-eslint/no-unsafe-assignment": "error", + "@typescript-eslint/no-unsafe-call": "error", + "@typescript-eslint/no-unsafe-declaration-merging": "warn", + "@typescript-eslint/no-unsafe-member-access": "error", + "@typescript-eslint/no-unsafe-return": "error", + "@typescript-eslint/no-useless-empty-export": "warn", + "@typescript-eslint/non-nullable-type-assertion-style": "warn", + "@typescript-eslint/parameter-properties": "warn", + "@typescript-eslint/prefer-as-const": "error", + "@typescript-eslint/prefer-enum-initializers": "warn", + "@typescript-eslint/prefer-for-of": "warn", + "@typescript-eslint/prefer-function-type": "warn", + "@typescript-eslint/prefer-includes": "warn", + "@typescript-eslint/prefer-literal-enum-member": "warn", + "@typescript-eslint/prefer-namespace-keyword": "error", + "@typescript-eslint/prefer-nullish-coalescing": "warn", + "@typescript-eslint/prefer-optional-chain": "warn", + "@typescript-eslint/prefer-readonly": "warn", + "@typescript-eslint/prefer-readonly-parameter-types": "warn", + "@typescript-eslint/prefer-reduce-type-parameter": "warn", + "@typescript-eslint/prefer-regexp-exec": "warn", + "@typescript-eslint/prefer-return-this-type": "warn", + "@typescript-eslint/prefer-string-starts-ends-with": "warn", + "@typescript-eslint/prefer-ts-expect-error": "warn", + "@typescript-eslint/promise-function-async": "warn", + "@typescript-eslint/require-array-sort-compare": "warn", + "@typescript-eslint/restrict-plus-operands": "error", + "@typescript-eslint/restrict-template-expressions": "error", + "@typescript-eslint/sort-type-constituents": "warn", + "@typescript-eslint/strict-boolean-expressions": "warn", + "@typescript-eslint/switch-exhaustiveness-check": "warn", + "@typescript-eslint/triple-slash-reference": "error", + "@typescript-eslint/typedef": "warn", + "@typescript-eslint/unbound-method": "error", + "@typescript-eslint/unified-signatures": "warn", + + "@typescript-eslint/no-use-before-define": "warn", + "@typescript-eslint/no-var-requires": "error", + + // Note: you must disable the base rule as it can report incorrect errors + "object-curly-spacing": "off", + "@typescript-eslint/object-curly-spacing": "warn" + } +} diff --git a/CountlyRNExample/.prettierrc.js b/CountlyRNExample/.prettierrc.js deleted file mode 100644 index 2b54074..0000000 --- a/CountlyRNExample/.prettierrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - arrowParens: 'avoid', - bracketSameLine: true, - bracketSpacing: false, - singleQuote: true, - trailingComma: 'all', -}; diff --git a/CountlyRNExample/.prettierrc.json b/CountlyRNExample/.prettierrc.json new file mode 100644 index 0000000..3487adb --- /dev/null +++ b/CountlyRNExample/.prettierrc.json @@ -0,0 +1,14 @@ +{ + "arrowParens": "always", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "jsxSingleQuote": false, + "quoteProps": "preserve", + "singleQuote": true, + "semi": true, + "printWidth": 300, + "useTabs": false, + "tabWidth": 4, + "trailingComma": "es5", + "endOfLine": "lf" +} diff --git a/CountlyRNExample/.vscode/settings.json b/CountlyRNExample/.vscode/settings.json new file mode 100644 index 0000000..a26b253 --- /dev/null +++ b/CountlyRNExample/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + }, + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "cSpell.words": ["Countly"], + "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } +} \ No newline at end of file diff --git a/CountlyRNExample/App.tsx b/CountlyRNExample/App.tsx index 81b0fa5..d28bcd6 100644 --- a/CountlyRNExample/App.tsx +++ b/CountlyRNExample/App.tsx @@ -8,710 +8,843 @@ import React, { Component } from 'react'; import { Text, Button, ScrollView, Image, View, TextInput, StyleSheet, SafeAreaView } from 'react-native'; -class Example extends Component { - constructor(props) { - super(props); - this.state = {ratingId: '61eac4627b8ad224e37bb3f5'}; - this.config = {}; - - this.onInit = this.onInit.bind(this); - this.onStart = this.onStart.bind(this); - this.basicEvent = this.basicEvent.bind(this); - this.eventWithSum = this.eventWithSum.bind(this); - this.eventWithSegment = this.eventWithSegment.bind(this); - this.eventWithSumAndSegment = this.eventWithSumAndSegment.bind(this); - this.startEvent = this.startEvent.bind(this); - this.test = this.test.bind(this); - this.onSendUserData = this.onSendUserData.bind(this); - this.onSendUserDataBulk = this.onSendUserDataBulk.bind(this); - this.onSetUserProperties = this.onSetUserProperties.bind(this); - this.onUpdateUserData = this.onUpdateUserData.bind(this); - this.userData_setProperty = this.userData_setProperty.bind(this); - this.userData_increment = this.userData_increment.bind(this); - this.userData_multiply = this.userData_multiply.bind(this); - this.userData_saveMax = this.userData_saveMax.bind(this); - this.userData_saveMin = this.userData_saveMin.bind(this); - this.userData_setOnce = this.userData_setOnce.bind(this); - this.changeDeviceId = this.changeDeviceId.bind(this); - this.askForNotificationPermission = - this.askForNotificationPermission.bind(this); - - this.startTrace = this.startTrace.bind(this); - this.endTrace = this.endTrace.bind(this); - this.recordNetworkTraceSuccess = this.recordNetworkTraceSuccess.bind(this); - this.recordNetworkTraceFailure = this.recordNetworkTraceFailure.bind(this); - this.random = this.random.bind(this); - this.setCustomCrashSegments = this.setCustomCrashSegments.bind(this); - this.presentRatingWidgetUsingEditBox = - this.presentRatingWidgetUsingEditBox.bind(this); - } - - componentDidMount = () => { - console.log('component did mount'); - // this.onInit(); - }; - - componentDidUpdate(prevProps, prevState) { - console.log('componentDidUpdate'); - } +const successCodes = [100, 101, 200, 201, 202, 205, 300, 301, 303, 305]; +const failureCodes = [400, 402, 405, 408, 500, 501, 502, 505]; - componentWillUnmount() { - console.log('componentWillUnmount'); - } - - 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("https://try.count.ly", "YOUR_APP_KEY"); // Initialize the countly SDK. - // Countly.appLoadingFinished(); - // /** - // * Push notifications settings - // * Should be call after init - // */ - // Countly.registerForNotification((theNotification) => { - // var jsonString = JSON.stringify(JSON.parse(theNotification)) - // console.log("Just received this notification data: " + jsonString); - // 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 = () => { - // Countly.start(); - }; - onStop = () => { - // Countly.stop(); - }; - onSendUserData = () => { - // // example for setUserData - // var options = {}; - // options.name = "Name of User"; - // options.username = "Username"; - // options.email = "User Email"; - // options.organization = "User Organization"; - // options.phone = "User Contact number"; - // options.picture = "https://count.ly/images/logos/countly-logo.png"; - // options.picturePath = ""; - // options.gender = "Male"; - // options.byear = 1989; - // Countly.setUserData(options); - }; - - onSetUserProperties = () => { - // // example for setUserData - // var options = {}; - // // Predefined user properties - // options.name = "Name of User"; - // options.username = "Username"; - // options.email = "User Email"; - // options.organization = "User Organization"; - // options.phone = "User Contact number"; - // options.picture = "https://count.ly/images/logos/countly-logo.png"; - // options.picturePath = ""; - // options.gender = "Male"; - // options.byear = 1989; - // // Custom User Properties - // options.customeValueA = "Custom value A"; - // options.customeValueB = "Custom value B"; - // Countly.userDataBulk.setUserProperties(options); - // Countly.userDataBulk.save(); - }; - - onSendUserDataBulk = () => { - // Promise.allSettled([Countly.userDataBulk.setProperty("key", "value"), - // Countly.userDataBulk.setProperty("increment", 5), - // Countly.userDataBulk.increment("increment"), - // Countly.userDataBulk.setProperty("incrementBy", 5), - // Countly.userDataBulk.incrementBy("incrementBy", 10), - // Countly.userDataBulk.setProperty("multiply", 5), - // Countly.userDataBulk.multiply("multiply", 20), - // Countly.userDataBulk.setProperty("saveMax", 5), - // Countly.userDataBulk.saveMax("saveMax", 100), - // Countly.userDataBulk.setProperty("saveMin", 5), - // Countly.userDataBulk.saveMin("saveMin", 50), - // Countly.userDataBulk.setOnce("setOnce", 200), - // Countly.userDataBulk.pushUniqueValue("type", "morning"), - // Countly.userDataBulk.pushValue("type", "morning"), - // Countly.userDataBulk.pullValue("type", "morning")]) - // .then(values => { - // // We need to call the "save" in then block else it will cause a race condition and "save" may call before all the user profiles calls are completed - // Countly.userDataBulk.save(); - // }) - }; - - onUpdateUserData = () => { - // // example for setUserData - // var options = {}; - // options.organization = "Updated User Organization"; - // options.phone = "Updated User Contact number"; - // options.gender = "Female"; - // options.byear = 1995; - // Countly.setUserData(options); - }; - basicEvent = () => { - // // example for basic event - // var event = {"eventName":"Basic Event","eventCount":1}; - // Countly.sendEvent(event); - }; - eventWithSum = () => { - // // example for event with sum - // var event = {"eventName":"Event With Sum","eventCount":1,"eventSum":"0.99"}; - // Countly.sendEvent(event); - }; - eventWithSegment = () => { - // // example for event with segment - // var event = {"eventName":"Event With Segment","eventCount":1}; - // event.segments = {"Country" : "Turkey", "Age" : "28"}; - // Countly.sendEvent(event); - // event = {"eventName":"Event With Segment","eventCount":1}; - // event.segments = {"Country" : "France", "Age" : "38"}; - // Countly.sendEvent(event); - }; - eventWithSumAndSegment = () => { - // // example for event with segment and sum - // var event = {"eventName":"Event With Sum And Segment","eventCount":1,"eventSum":"0.99"}; - // event.segments = {"Country" : "Turkey", "Age" : "28"}; - // Countly.sendEvent(event); - // event = {"eventName":"Event With Sum And Segment","eventCount":3,"eventSum":"1.99"}; - // event.segments = {"Country" : "France", "Age" : "38"}; - // Countly.sendEvent(event); - }; - - // TIMED EVENTS - startEvent = () => { - // Countly.startEvent("timedEvent"); - // setTimeout(() => { - // Countly.endEvent("timedEvent"); - // },1000); - }; - - /* +class Example extends Component { + constructor(props) { + super(props); + this.state = { ratingId: '61eac4627b8ad224e37bb3f5' }; + this.config = {}; + + this.onInit = this.onInit.bind(this); + this.onStart = this.onStart.bind(this); + this.basicEvent = this.basicEvent.bind(this); + this.eventWithSum = this.eventWithSum.bind(this); + this.eventWithSegment = this.eventWithSegment.bind(this); + this.eventWithSumAndSegment = this.eventWithSumAndSegment.bind(this); + this.startEvent = this.startEvent.bind(this); + this.test = this.test.bind(this); + this.onSendUserData = this.onSendUserData.bind(this); + this.onSendUserDataBulk = this.onSendUserDataBulk.bind(this); + this.onSetUserProperties = this.onSetUserProperties.bind(this); + this.onUpdateUserData = this.onUpdateUserData.bind(this); + this.userData_setProperty = this.userData_setProperty.bind(this); + this.userData_increment = this.userData_increment.bind(this); + this.userData_multiply = this.userData_multiply.bind(this); + this.userData_saveMax = this.userData_saveMax.bind(this); + this.userData_saveMin = this.userData_saveMin.bind(this); + this.userData_setOnce = this.userData_setOnce.bind(this); + this.changeDeviceId = this.changeDeviceId.bind(this); + this.askForNotificationPermission = this.askForNotificationPermission.bind(this); + + this.startTrace = this.startTrace.bind(this); + this.endTrace = this.endTrace.bind(this); + this.recordNetworkTraceSuccess = this.recordNetworkTraceSuccess.bind(this); + this.recordNetworkTraceFailure = this.recordNetworkTraceFailure.bind(this); + this.random = this.random.bind(this); + this.setCustomCrashSegments = this.setCustomCrashSegments.bind(this); + this.presentRatingWidgetUsingEditBox = this.presentRatingWidgetUsingEditBox.bind(this); + } + + componentDidMount = () => { + console.log('component did mount'); + // this.onInit(); + }; + + componentDidUpdate(prevProps, prevState) { + console.log('componentDidUpdate'); + } + + componentWillUnmount() { + console.log('componentWillUnmount'); + } + + 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("https://try.count.ly", "YOUR_APP_KEY"); // Initialize the countly SDK. + // Countly.appLoadingFinished(); + // /** + // * Push notifications settings + // * Should be call after init + // */ + // Countly.registerForNotification((theNotification) => { + // var jsonString = JSON.stringify(JSON.parse(theNotification)) + // console.log("Just received this notification data: " + jsonString); + // 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 = () => { + // Countly.start(); + }; + onStop = () => { + // Countly.stop(); + }; + onSendUserData = () => { + // // example for setUserData + // var options = {}; + // options.name = "Name of User"; + // options.username = "Username"; + // options.email = "User Email"; + // options.organization = "User Organization"; + // options.phone = "User Contact number"; + // options.picture = "https://count.ly/images/logos/countly-logo.png"; + // options.picturePath = ""; + // options.gender = "Male"; + // options.byear = 1989; + // Countly.setUserData(options); + }; + + onSetUserProperties = () => { + // // example for setUserData + // var options = {}; + // // Predefined user properties + // options.name = "Name of User"; + // options.username = "Username"; + // options.email = "User Email"; + // options.organization = "User Organization"; + // options.phone = "User Contact number"; + // options.picture = "https://count.ly/images/logos/countly-logo.png"; + // options.picturePath = ""; + // options.gender = "Male"; + // options.byear = 1989; + // // Custom User Properties + // options.customeValueA = "Custom value A"; + // options.customeValueB = "Custom value B"; + // Countly.userDataBulk.setUserProperties(options); + // Countly.userDataBulk.save(); + }; + + onSendUserDataBulk = () => { + // Promise.allSettled([Countly.userDataBulk.setProperty("key", "value"), + // Countly.userDataBulk.setProperty("increment", 5), + // Countly.userDataBulk.increment("increment"), + // Countly.userDataBulk.setProperty("incrementBy", 5), + // Countly.userDataBulk.incrementBy("incrementBy", 10), + // Countly.userDataBulk.setProperty("multiply", 5), + // Countly.userDataBulk.multiply("multiply", 20), + // Countly.userDataBulk.setProperty("saveMax", 5), + // Countly.userDataBulk.saveMax("saveMax", 100), + // Countly.userDataBulk.setProperty("saveMin", 5), + // Countly.userDataBulk.saveMin("saveMin", 50), + // Countly.userDataBulk.setOnce("setOnce", 200), + // Countly.userDataBulk.pushUniqueValue("type", "morning"), + // Countly.userDataBulk.pushValue("type", "morning"), + // Countly.userDataBulk.pullValue("type", "morning")]) + // .then(values => { + // // We need to call the "save" in then block else it will cause a race condition and "save" may call before all the user profiles calls are completed + // Countly.userDataBulk.save(); + // }) + }; + + onUpdateUserData = () => { + // // example for setUserData + // var options = {}; + // options.organization = "Updated User Organization"; + // options.phone = "Updated User Contact number"; + // options.gender = "Female"; + // options.byear = 1995; + // Countly.setUserData(options); + }; + basicEvent = () => { + // // example for basic event + // var event = {"eventName":"Basic Event","eventCount":1}; + // Countly.sendEvent(event); + }; + eventWithSum = () => { + // // example for event with sum + // var event = {"eventName":"Event With Sum","eventCount":1,"eventSum":"0.99"}; + // Countly.sendEvent(event); + }; + eventWithSegment = () => { + // // example for event with segment + // var event = {"eventName":"Event With Segment","eventCount":1}; + // event.segments = {"Country" : "Turkey", "Age" : "28"}; + // Countly.sendEvent(event); + // event = {"eventName":"Event With Segment","eventCount":1}; + // event.segments = {"Country" : "France", "Age" : "38"}; + // Countly.sendEvent(event); + }; + eventWithSumAndSegment = () => { + // // example for event with segment and sum + // var event = {"eventName":"Event With Sum And Segment","eventCount":1,"eventSum":"0.99"}; + // event.segments = {"Country" : "Turkey", "Age" : "28"}; + // Countly.sendEvent(event); + // event = {"eventName":"Event With Sum And Segment","eventCount":3,"eventSum":"1.99"}; + // event.segments = {"Country" : "France", "Age" : "38"}; + // Countly.sendEvent(event); + }; + + // TIMED EVENTS + startEvent = () => { + // Countly.startEvent("timedEvent"); + // setTimeout(() => { + // Countly.endEvent("timedEvent"); + // },1000); + }; + + /* setTimeout may not work correctly if you are attached to Chrome Debugger. for workaround see: https://github.com/facebook/react-native/issues/9436 */ - timedEventWithSum = () => { - // // Event with sum - // Countly.startEvent("timedEventWithSum"); - // var event = { - // "eventName": "timedEventWithSum", - // "eventSum": "0.99" - // }; - // setTimeout(() => { - // Countly.endEvent(event); - // },1000); - }; - - timedEventWithSegment = () => { - // // Event with segment - // Countly.startEvent("timedEventWithSegment"); - // var event = { - // "eventName": "timedEventWithSegment" - // }; - // event.segments = { - // "Country": "Germany", - // "Age": "32" - // }; - // setTimeout(() => { - // Countly.endEvent(event); - // },1000); - }; - - timedEventWithSumAndSegment = () => { - // // Event with Segment, sum and count - // Countly.startEvent("timedEventWithSumAndSegment"); - // var event = { - // "eventName": "timedEventWithSumAndSegment", - // "eventCount": 1, - // "eventSum": "0.99" - // }; - // event.segments = { - // "Country": "India", - // "Age": "21" - // }; - // setTimeout(() => { - // Countly.endEvent(event); - // },1000); - }; - // TIMED EVENTS - - userData_setProperty = () => { - // Countly.userData.setProperty("setProperty", "keyValue"); - }; - - userData_increment = () => { - // Countly.userData.setProperty("increment", 5); - // Countly.userData.increment("increment"); - }; - - userData_incrementBy = () => { - // Countly.userData.setProperty("incrementBy", 5); - // Countly.userData.incrementBy("incrementBy", 10); - }; - - userData_multiply = () => { - // Countly.userData.setProperty("multiply", 5); - // Countly.userData.multiply("multiply", 20); - }; - - userData_saveMax = () => { - // Countly.userData.setProperty("saveMax", 5); - // Countly.userData.saveMax("saveMax", 100); - }; - - userData_saveMin = () => { - // Countly.userData.setProperty("saveMin", 5); - // Countly.userData.saveMin("saveMin", 50); - }; - - userData_setOnce = () => { - // Countly.userData.setOnce("setOnce", 200); - }; - - userData_pushUniqueValue = () => { - // Countly.userData.pushUniqueValue("type", "morning"); - }; - - userData_pushValue = () => { - // Countly.userData.pushValue("type", "morning"); - }; - - userData_pullValue = () => { - // Countly.userData.pullValue("type", "morning"); - }; - - changeDeviceId = () => { - // Countly.changeDeviceId('02d56d66-6a39-482d-aff0-d14e4d5e5fda'); - }; - - giveConsent = (name) => { - // Countly.giveConsent([name]); - }; - - removeConsent = (name) => { - // Countly.removeConsent([name]); - }; - - giveMultipleConsent = () => { - // Countly.giveConsent(["events", "views", "star-rating", "crashes", "invalidFeatureName"]); - }; - - removeMultipleConsent = () => { - // Countly.removeConsent(["events", "views"]); - }; - - giveAllConsent = () => { - // Countly.giveAllConsent(); - }; - - removeAllConsent = () => { - // Countly.removeAllConsent(); - }; - - remoteConfigUpdate = () => { - // Countly.remoteConfigUpdate((data) => { - // console.log(data); - // }); - }; - - updateRemoteConfigForKeysOnly = () => { - // Countly.updateRemoteConfigForKeysOnly(["test1"],(data) => { - // console.log(data); - // }); - }; - - updateRemoteConfigExceptKeys = () => { - // Countly.updateRemoteConfigExceptKeys(["test1"],(data) => { - // console.log(data); - // }); - }; - - getRemoteConfigValueForKeyBoolean = () => { - // Countly.getRemoteConfigValueForKey("booleanValue", (data) => { - // console.log(data); - // }); - }; - getRemoteConfigValueForKeyFloat = () => { - // Countly.getRemoteConfigValueForKey("floatValue", (data) => { - // console.log(data); - // }); - }; - getRemoteConfigValueForKeyInteger = () => { - // Countly.getRemoteConfigValueForKey("integerValue", (data) => { - // console.log(data); - // }); - }; - getRemoteConfigValueForKeyString = () => { - // Countly.getRemoteConfigValueForKey("stringValue", (data) => { - // console.log(data); - // }); - }; - getRemoteConfigValueForKeyJSON = () => { - // Countly.getRemoteConfigValueForKey("jsonValue", (data) => { - // console.log(data); - // }); - }; - - remoteConfigClearValues = () => { - // Countly.remoteConfigClearValues(); - }; - - setLocation = () => { - // var countryCode = "us"; - // var city = "Houston"; - // var latitude = "29.634933"; - // var longitude = "-95.220255"; - // var ipAddress = "103.238.105.167"; - // Countly.setLocation(countryCode, city, latitude + "," + longitude, ipAddress); - }; - disableLocation = () => { - // Countly.disableLocation(); - }; - - askForNotificationPermission = () => { - // Countly.askForNotificationPermission(); - }; - - setStarRatingDialogTexts = () => { - // Countly.setStarRatingDialogTexts(); - }; - - showStarRating = () => { - // Countly.showStarRating(); - }; - - showFeedbackPopup = () => { - // Countly.showFeedbackPopup("5f8c837a5294f7aae370067c", "Submit"); - }; - - presentRatingWidget = () => { - // Countly.presentRatingWidgetWithID("625f9032028614795fe5a85b", "Submit", (error) => { - // if (error != null) { - // console.log(error); - // } - // }); - }; - - presentRatingWidgetUsingEditBox = function () { - // Countly.presentRatingWidgetWithID(this.state.ratingId, "Submit", (error) => { - // if (error != null) { - // console.log("presentRatingWidgetUsingEditBox : " + error); - // } - // }); - }; - - showSurvey = () => { - // Countly.getFeedbackWidgets((retrivedWidgets, error) => { - // if (error != null) { - // console.log("showSurvey Error : " + error); - // } - // else { - // console.log("showSurvey Success : " + retrivedWidgets.length); - // var surveyWidget = retrivedWidgets.find(x => x.type === 'survey') - // if(surveyWidget) { - // Countly.presentFeedbackWidgetObject(surveyWidget, "Close", function() { - // console.log("showSurvey presentFeedbackWidgetObject : " + "Widgetshown"); - // }, - // function() { - // console.log("showSurvey presentFeedbackWidgetObject : " + "Widgetclosed"); - // }) - // } - // } - // }); - }; - - showNPS = () => { - // Countly.getFeedbackWidgets((retrivedWidgets, error) => { - // if (error != null) { - // console.log("showNPS Error : " + error); - // } - // else { - // console.log("showNPS Success : " + retrivedWidgets.length); - // var npsWidget = retrivedWidgets.find(x => x.type === 'nps') - // if(npsWidget) { - // Countly.presentFeedbackWidgetObject(npsWidget, "Close", function() { - // console.log("showNPS presentFeedbackWidgetObject : " + "Widgetshown"); - // }, - // function() { - // console.log("showNPS presentFeedbackWidgetObject : " + "Widgetclosed"); - // }) - // } - // } - // }); - }; - - addCrashLog = () => { - // Countly.addCrashLog("My crash log in string."); - }; - - addLogException = () => { - // Countly.addCrashLog("User Performed Step A"); - // setTimeout(() => { - // Countly.addCrashLog("User Performed Step B"); - // },1000); - // setTimeout(() => { - // Countly.addCrashLog("User Performed Step C"); - // try { - // var a = {}; - // var x = a.b.c; // this will create error. - // } catch (error) { - // setTimeout(() => { - // var stack = error.stack.toString(); - // Countly.logException(stack, true, {"_facebook_version": "0.0.1"}); - // },1000); - // } - // },1000); - }; - - logException = () => { - // Countly.logException(); - }; - - // APM Examples - startTrace = () => { - // var traceKey = "Trace Key"; - // Countly.startTrace(traceKey); - }; - endTrace = () => { - // var traceKey = "Trace Key"; - // var customMetric = { - // "ABC": 1233, - // "C44C": 1337 - // }; - // Countly.endTrace(traceKey, customMetric); - }; - random = (number) => { - return Math.floor(Math.random() * number); - }; - recordNetworkTraceSuccess = () => { - // var networkTraceKey = "api/endpoint.1"; - // var responseCode = successCodes[this.random(successCodes.length)]; - // var requestPayloadSize = this.random(700) + 200; - // var responsePayloadSize = this.random(700) + 200; - // Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize); - }; - recordNetworkTraceFailure = () => { - // var networkTraceKey = "api/endpoint.1"; - // var responseCode = failureCodes[this.random(failureCodes.length)]; - // var requestPayloadSize = this.random(700) + 250; - // var responsePayloadSize = this.random(700) + 250; - // var startTime = new Date().getTime(); - // var endTime = startTime + 500; - // Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime); - }; - - setCustomCrashSegments = () => { - // var segment = {"Key": "Value"}; - // Countly.setCustomCrashSegments(segment); - }; - - /* + timedEventWithSum = () => { + // // Event with sum + // Countly.startEvent("timedEventWithSum"); + // var event = { + // "eventName": "timedEventWithSum", + // "eventSum": "0.99" + // }; + // setTimeout(() => { + // Countly.endEvent(event); + // },1000); + }; + + timedEventWithSegment = () => { + // // Event with segment + // Countly.startEvent("timedEventWithSegment"); + // var event = { + // "eventName": "timedEventWithSegment" + // }; + // event.segments = { + // "Country": "Germany", + // "Age": "32" + // }; + // setTimeout(() => { + // Countly.endEvent(event); + // },1000); + }; + + timedEventWithSumAndSegment = () => { + // // Event with Segment, sum and count + // Countly.startEvent("timedEventWithSumAndSegment"); + // var event = { + // "eventName": "timedEventWithSumAndSegment", + // "eventCount": 1, + // "eventSum": "0.99" + // }; + // event.segments = { + // "Country": "India", + // "Age": "21" + // }; + // setTimeout(() => { + // Countly.endEvent(event); + // },1000); + }; + // TIMED EVENTS + + userData_setProperty = () => { + // Countly.userData.setProperty("setProperty", "keyValue"); + }; + + userData_increment = () => { + // Countly.userData.setProperty("increment", 5); + // Countly.userData.increment("increment"); + }; + + userData_incrementBy = () => { + // Countly.userData.setProperty("incrementBy", 5); + // Countly.userData.incrementBy("incrementBy", 10); + }; + + userData_multiply = () => { + // Countly.userData.setProperty("multiply", 5); + // Countly.userData.multiply("multiply", 20); + }; + + userData_saveMax = () => { + // Countly.userData.setProperty("saveMax", 5); + // Countly.userData.saveMax("saveMax", 100); + }; + + userData_saveMin = () => { + // Countly.userData.setProperty("saveMin", 5); + // Countly.userData.saveMin("saveMin", 50); + }; + + userData_setOnce = () => { + // Countly.userData.setOnce("setOnce", 200); + }; + + userData_pushUniqueValue = () => { + // Countly.userData.pushUniqueValue("type", "morning"); + }; + + userData_pushValue = () => { + // Countly.userData.pushValue("type", "morning"); + }; + + userData_pullValue = () => { + // Countly.userData.pullValue("type", "morning"); + }; + + changeDeviceId = () => { + // Countly.changeDeviceId('02d56d66-6a39-482d-aff0-d14e4d5e5fda'); + }; + + giveConsent = (name) => { + // Countly.giveConsent([name]); + }; + + removeConsent = (name) => { + // Countly.removeConsent([name]); + }; + + giveMultipleConsent = () => { + // Countly.giveConsent(["events", "views", "star-rating", "crashes", "invalidFeatureName"]); + }; + + removeMultipleConsent = () => { + // Countly.removeConsent(["events", "views"]); + }; + + giveAllConsent = () => { + // Countly.giveAllConsent(); + }; + + removeAllConsent = () => { + // Countly.removeAllConsent(); + }; + + remoteConfigUpdate = () => { + // Countly.remoteConfigUpdate((data) => { + // console.log(data); + // }); + }; + + updateRemoteConfigForKeysOnly = () => { + // Countly.updateRemoteConfigForKeysOnly(["test1"],(data) => { + // console.log(data); + // }); + }; + + updateRemoteConfigExceptKeys = () => { + // Countly.updateRemoteConfigExceptKeys(["test1"],(data) => { + // console.log(data); + // }); + }; + + getRemoteConfigValueForKeyBoolean = () => { + // Countly.getRemoteConfigValueForKey("booleanValue", (data) => { + // console.log(data); + // }); + }; + getRemoteConfigValueForKeyFloat = () => { + // Countly.getRemoteConfigValueForKey("floatValue", (data) => { + // console.log(data); + // }); + }; + getRemoteConfigValueForKeyInteger = () => { + // Countly.getRemoteConfigValueForKey("integerValue", (data) => { + // console.log(data); + // }); + }; + getRemoteConfigValueForKeyString = () => { + // Countly.getRemoteConfigValueForKey("stringValue", (data) => { + // console.log(data); + // }); + }; + getRemoteConfigValueForKeyJSON = () => { + // Countly.getRemoteConfigValueForKey("jsonValue", (data) => { + // console.log(data); + // }); + }; + + remoteConfigClearValues = () => { + // Countly.remoteConfigClearValues(); + }; + + setLocation = () => { + // var countryCode = "us"; + // var city = "Houston"; + // var latitude = "29.634933"; + // var longitude = "-95.220255"; + // var ipAddress = "103.238.105.167"; + // Countly.setLocation(countryCode, city, latitude + "," + longitude, ipAddress); + }; + disableLocation = () => { + // Countly.disableLocation(); + }; + + askForNotificationPermission = () => { + // Countly.askForNotificationPermission(); + }; + + setStarRatingDialogTexts = () => { + // Countly.setStarRatingDialogTexts(); + }; + + showStarRating = () => { + // Countly.showStarRating(); + }; + + showFeedbackPopup = () => { + // Countly.showFeedbackPopup("5f8c837a5294f7aae370067c", "Submit"); + }; + + presentRatingWidget = () => { + // Countly.presentRatingWidgetWithID("625f9032028614795fe5a85b", "Submit", (error) => { + // if (error != null) { + // console.log(error); + // } + // }); + }; + + presentRatingWidgetUsingEditBox = function () { + // Countly.presentRatingWidgetWithID(this.state.ratingId, "Submit", (error) => { + // if (error != null) { + // console.log("presentRatingWidgetUsingEditBox : " + error); + // } + // }); + }; + + showSurvey = () => { + // Countly.getFeedbackWidgets((retrivedWidgets, error) => { + // if (error != null) { + // console.log("showSurvey Error : " + error); + // } + // else { + // console.log("showSurvey Success : " + retrivedWidgets.length); + // var surveyWidget = retrivedWidgets.find(x => x.type === 'survey') + // if(surveyWidget) { + // Countly.presentFeedbackWidgetObject(surveyWidget, "Close", function() { + // console.log("showSurvey presentFeedbackWidgetObject : " + "Widgetshown"); + // }, + // function() { + // console.log("showSurvey presentFeedbackWidgetObject : " + "Widgetclosed"); + // }) + // } + // } + // }); + }; + + showNPS = () => { + // Countly.getFeedbackWidgets((retrivedWidgets, error) => { + // if (error != null) { + // console.log("showNPS Error : " + error); + // } + // else { + // console.log("showNPS Success : " + retrivedWidgets.length); + // var npsWidget = retrivedWidgets.find(x => x.type === 'nps') + // if(npsWidget) { + // Countly.presentFeedbackWidgetObject(npsWidget, "Close", function() { + // console.log("showNPS presentFeedbackWidgetObject : " + "Widgetshown"); + // }, + // function() { + // console.log("showNPS presentFeedbackWidgetObject : " + "Widgetclosed"); + // }) + // } + // } + // }); + }; + + addCrashLog = () => { + // Countly.addCrashLog("My crash log in string."); + }; + + addLogException = () => { + // Countly.addCrashLog("User Performed Step A"); + // setTimeout(() => { + // Countly.addCrashLog("User Performed Step B"); + // },1000); + // setTimeout(() => { + // Countly.addCrashLog("User Performed Step C"); + // try { + // var a = {}; + // var x = a.b.c; // this will create error. + // } catch (error) { + // setTimeout(() => { + // var stack = error.stack.toString(); + // Countly.logException(stack, true, {"_facebook_version": "0.0.1"}); + // },1000); + // } + // },1000); + }; + + logException = () => { + // Countly.logException(); + }; + + // APM Examples + startTrace = () => { + // var traceKey = "Trace Key"; + // Countly.startTrace(traceKey); + }; + endTrace = () => { + // var traceKey = "Trace Key"; + // var customMetric = { + // "ABC": 1233, + // "C44C": 1337 + // }; + // Countly.endTrace(traceKey, customMetric); + }; + random = (number) => { + return Math.floor(Math.random() * number); + }; + recordNetworkTraceSuccess = () => { + // var networkTraceKey = "api/endpoint.1"; + // var responseCode = successCodes[this.random(successCodes.length)]; + // var requestPayloadSize = this.random(700) + 200; + // var responsePayloadSize = this.random(700) + 200; + // Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize); + }; + recordNetworkTraceFailure = () => { + // var networkTraceKey = "api/endpoint.1"; + // var responseCode = failureCodes[this.random(failureCodes.length)]; + // var requestPayloadSize = this.random(700) + 250; + // var responsePayloadSize = this.random(700) + 250; + // var startTime = new Date().getTime(); + // var endTime = startTime + 500; + // Countly.recordNetworkTrace(networkTraceKey, responseCode, requestPayloadSize, responsePayloadSize, startTime, endTime); + }; + + setCustomCrashSegments = () => { + // var segment = {"Key": "Value"}; + // Countly.setCustomCrashSegments(segment); + }; + + /* testCrash = () => { Countly.testCrash(); } */ - setCustomMetrics = () => { - // var customMetric = { - // "_carrier": "Custom Carrier" - // }; - // Countly.setCustomMetrics(customMetric); - }; - - test = () => { - // this.onInit(); - // this.onStart(); - // this.basicEvent(); - // this.eventWithSum(); - // this.eventWithSegment(); - // this.eventWithSumAndSegment(); - // this.startEvent(); - // this.onSendUserData(); - // this.onSendUserDataBulk(); - // this.onSetUserProperties(); - // this.onUpdateUserData(); - // this.userData_setProperty(); - // this.userData_increment(); - // this.userData_incrementBy(); - // this.userData_multiply(); - // this.userData_saveMax(); - // this.userData_saveMin(); - // this.userData_setOnce(); - // // Note: Crash test for setLocation method. - // // Countly.setLocation(null, city, latitude + "," + longitude, ipAddress); - // // Countly.setLocation(null, null, latitude + "," + longitude, ipAddress); - // // Countly.setLocation(null, null, null, ipAddress); - // // Countly.setLocation(null, null, null, null); - // // Countly.setLocation(countryCode, null, null, null); - // // Countly.setLocation(countryCode, city, null, null); - // // Countly.setLocation(countryCode, city, latitude + "," + longitude, null); - // // Countly.setLocation(countryCode, city, ",", ipAddress); - // // Countly.setLocation(countryCode, city, "0,0", ipAddress); - // // Countly.setLocation(countryCode, city, "a,b", ipAddress); - // // Countly.setLocation(countryCode, city, "abcd", ipAddress); - }; - - render() { - return ( - - - - console.log(e.nativeEvent.error)} - /> - - React Native Demo App - - -