@@ -16,16 +16,28 @@ import {
1616 useColorScheme ,
1717 View ,
1818 Button ,
19+ Dimensions ,
1920} from 'react-native' ;
21+ import { WebView } from 'react-native-webview' ;
2022
2123import { Colors , Header } from 'react-native/Libraries/NewAppScreen' ;
2224
2325import {
2426 createTracker ,
2527 removeTracker ,
26- // removeAllTrackers ,
28+ getWebViewCallback ,
2729} from '@snowplow/react-native-tracker' ;
2830
31+ /**
32+ * URI of the Snowplow collector (e.g., Micro, Mini, or BDP) to send events to
33+ */
34+ const collectorEndpoint = 'placeholder' ;
35+
36+ /**
37+ * URI of a website to load in the webview component
38+ */
39+ const webViewEndpoint = '' ;
40+
2941const Section = ( { children, title} ) => {
3042 const isDarkMode = useColorScheme ( ) === 'dark' ;
3143 return (
@@ -62,7 +74,10 @@ const App = () => {
6274 const tracker = createTracker (
6375 'sp1' ,
6476 {
65- endpoint : 'placeholder' ,
77+ endpoint : collectorEndpoint ,
78+ requestHeaders : {
79+ test : 'works' ,
80+ } ,
6681 } ,
6782 {
6883 trackerConfig : {
@@ -106,12 +121,29 @@ const App = () => {
106121 const secTracker = createTracker (
107122 'sp2' ,
108123 {
109- endpoint : 'placeholder' ,
124+ endpoint : collectorEndpoint ,
125+ } ,
126+ {
127+ trackerConfig : {
128+ screenViewAutotracking : false , // for tests predictability
129+ installAutotracking : false ,
130+ } ,
131+ } ,
132+ ) ;
133+
134+ const anonymousTracker = createTracker (
135+ 'sp_anon' ,
136+ {
137+ endpoint : collectorEndpoint ,
110138 } ,
111139 {
112140 trackerConfig : {
113141 screenViewAutotracking : false , // for tests predictability
114142 installAutotracking : false ,
143+ userAnonymisation : true ,
144+ } ,
145+ emitterConfig : {
146+ serverAnonymisation : true ,
115147 } ,
116148 } ,
117149 ) ;
@@ -298,6 +330,14 @@ const App = () => {
298330 } ) ;
299331 } ;
300332
333+ const onPressTestAnonymousTracker = ( ) => {
334+ anonymousTracker . trackScreenViewEvent ( { name : 'fromAnonymousTracker' } ) ;
335+ anonymousTracker . trackStructuredEvent ( {
336+ category : 'AnonymousTracker' ,
337+ action : 'trackAnonymous' ,
338+ } ) ;
339+ } ;
340+
301341 const onPressPlayGC = async ( ) => {
302342 try {
303343 await tracker . removeGlobalContexts ( 'testTag' ) ;
@@ -415,6 +455,14 @@ const App = () => {
415455 accessibilityLabel = "testSecTracker"
416456 />
417457 </ Section >
458+ < Section title = "Anonymous tracker" >
459+ < Button
460+ onPress = { onPressTestAnonymousTracker }
461+ title = "Track events with anonymous tracking"
462+ color = "#841584"
463+ accessibilityLabel = "testAnonymousTracker"
464+ />
465+ </ Section >
418466 < Section title = "Warnings" >
419467 < Button
420468 onPress = { onPressShowMeSomeWarnings }
@@ -456,6 +504,20 @@ const App = () => {
456504 accessibilityLabel = "testRemove"
457505 />
458506 </ Section >
507+ < Section title = "Web view" >
508+ { webViewEndpoint ? (
509+ < WebView
510+ onMessage = { getWebViewCallback ( ) }
511+ source = { { uri : webViewEndpoint } }
512+ style = { {
513+ height : 400 ,
514+ width :
515+ Dimensions . get ( 'window' ) . width -
516+ styles . sectionContainer . paddingHorizontal ,
517+ } }
518+ />
519+ ) : null }
520+ </ Section >
459521 </ View >
460522 </ ScrollView >
461523 </ SafeAreaView >
0 commit comments