Skip to content

Commit

Permalink
Added twillio segment Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Owen-Morris committed Feb 4, 2023
1 parent a2f76a2 commit d47a63c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
25 changes: 18 additions & 7 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {configureStore} from './redux/configureStore';
import MainNavigator from './navigation/MainNavigator';
import ErrorBoundary from 'react-native-error-boundary';

//Analytics
import {createClient, AnalyticsProvider} from '@segment/analytics-react-native';

//Font Awesome setup
import {library} from '@fortawesome/fontawesome-svg-core';
//import {fab} from '@fortawesome/free-brands-svg-icons';
Expand Down Expand Up @@ -63,16 +66,24 @@ library.add(
);
const {store, persistor} = configureStore();

const segmentClient = createClient({
writeKey: 'cdnZuncPQB0GQ7BMgKzz7zErgcZsuw7l',
trackAppLifecycleEvents: true,
collectDeviceId: true,
});

function App() {
return (
<Provider store={store}>
<PersistGate persistor={persistor}>
<ErrorBoundary>
<NavigationContainer>
<MainNavigator />
</NavigationContainer>
</ErrorBoundary>
</PersistGate>
<AnalyticsProvider client={segmentClient}>
<PersistGate persistor={persistor}>
<ErrorBoundary>
<NavigationContainer>
<MainNavigator />
</NavigationContainer>
</ErrorBoundary>
</PersistGate>
</AnalyticsProvider>
</Provider>
);
}
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target 'QualRNDEMO' do
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
)
pod 'Qualtrics', '~> 2.6.0'
pod 'Qualtrics', '~> 2.9.1'

pod 'RNCAsyncStorage', :path => '../node_modules/@react-native-async-storage/async-storage'

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"@react-native-community/masked-view": "^0.1.10",
"@react-navigation/native": "^5.7.1",
"@react-navigation/stack": "^5.7.1",
"@segment/analytics-react-native": "^2.12.0",
"@segment/sovran-react-native": "^0.4.5",
"axios": "^0.21.1",
"patch-package": "^6.2.2",
"postinstall-postinstall": "^2.1.0",
Expand Down
17 changes: 17 additions & 0 deletions screens/FirstIntercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import QualtVar from '../controls/QualtVar';
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
import WalkerLogoComponent from '../assets/Walker_Logo_JSX';
import QualtricsLogoComponent from '../assets/Qualtrics_logo_JSX';
import {useAnalytics} from '@segment/analytics-react-native';

function FirstIntercept({auth, setLogin, setCustomVars}) {
const [interceptIDs, setInterceptIDs] = useState([]);
const [customVars, setCVars] = useState(auth.custom_vars);
const {track} = useAnalytics();

useEffect(() => {
console.log('intercept-auth:', auth);
Expand Down Expand Up @@ -68,6 +70,14 @@ function FirstIntercept({auth, setLogin, setCustomVars}) {
console.log('evalRes:', res);
if (res.passed) {
console.log('creativeType:', res.creativeType);
// Segment Analyitics
track('Intercept Passed', {
intId,
brandID: auth.auth.brandID,
projectID: auth.auth.projectID,
extRefID: myExRef,
creativeType: res.creativeType,
});
var inter = await Qualtrics.displayIntercept(intId);
console.log('inter:', inter);
if (res.creativeType == 'MobileNotification') {
Expand All @@ -92,6 +102,13 @@ function FirstIntercept({auth, setLogin, setCustomVars}) {
}
} else {
console.log('intercept failed...');
// Segment Analyitics
track('Intercept Failed', {
intId,
brandID: auth.auth.brandID,
projectID: auth.auth.projectID,
extRefID: myExRef,
});
Alert.alert(
'Intercept Evaluated to FALSE\nNot displaying Intercept',
JSON.stringify(res),
Expand Down
28 changes: 28 additions & 0 deletions screens/WelcomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import CardView from '../controls/CardView';
import WalkerLogoComponent from '../assets/Walker_Logo_JSX';
import QualtricsLogoComponent from '../assets/Qualtrics_logo_JSX';
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome';
import {useAnalytics} from '@segment/analytics-react-native';

function WelcomeScreen({auth, setLogin, setCreds, setVars}) {
const [isBusy, setIsBusy] = useState(false);
Expand All @@ -36,6 +37,7 @@ function WelcomeScreen({auth, setLogin, setCreds, setVars}) {
const [doExtRef, toggleExtRef] = useState(auth.creds.doExtRef);
const navigation = useNavigation();
const walkerURL = 'https://walkerinfo.com/demo/DX/mobile-app';
const {track} = useAnalytics();

useEffect(() => {
//console.log("WelcomeAuth", auth);
Expand Down Expand Up @@ -86,6 +88,12 @@ function WelcomeScreen({auth, setLogin, setCreds, setVars}) {
doExtRef: true,
});
setIsBusy(false);
// Segment Analyitics
track('Init Success', {
brandID,
projectID,
extRefID,
});
} else {
let msg = '';
if (result.ERROR == null) {
Expand All @@ -94,6 +102,13 @@ function WelcomeScreen({auth, setLogin, setCreds, setVars}) {
} else {
msg = result.ERROR.message;
}
// Segment Analyitics
track('Init Failed', {
brandID,
projectID,
extRefID: '',
errorMessage: msg,
});
Alert.alert(
'Failed To Initialize',
msg + '\nResult:' + JSON.stringify(result),
Expand Down Expand Up @@ -131,6 +146,12 @@ function WelcomeScreen({auth, setLogin, setCreds, setVars}) {
doExtRef: false,
});
setIsBusy(false);
// Segment Analyitics
track('Init Success', {
brandID,
projectID,
extRefID: '',
});
} else {
let msg = '';
console.log('failed result:', result);
Expand All @@ -140,6 +161,13 @@ function WelcomeScreen({auth, setLogin, setCreds, setVars}) {
} else {
msg = result.ERROR.message;
}
// Segment Analyitics
track('Init Failed', {
brandID,
projectID,
extRefID: '',
errorMessage: msg,
});
Alert.alert(
'Failed To Initialize',
msg + '\nResult : ' + JSON.stringify(result),
Expand Down

0 comments on commit d47a63c

Please sign in to comment.