-
Notifications
You must be signed in to change notification settings - Fork 136
/
AnalyticsScreen.js
85 lines (71 loc) · 2.37 KB
/
AnalyticsScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React from 'react';
import {
Text,
View,
ScrollView,
TouchableOpacity
} from 'react-native';
import Analytics from 'appcenter-analytics';
import SharedStyles from './SharedStyles';
export default class AnalyticsScreen extends React.Component {
constructor() {
super();
this.state = {
analyticsEnabled: false
};
this.toggleEnabled = this.toggleEnabled.bind(this);
}
async componentDidMount() {
const component = this;
const analyticsEnabled = await Analytics.isEnabled();
component.setState({ analyticsEnabled });
}
async toggleEnabled() {
await Analytics.setEnabled(!this.state.analyticsEnabled);
const analyticsEnabled = await Analytics.isEnabled();
this.setState({ analyticsEnabled });
}
/* eslint-disable no-undef */
render() {
return (
<View style={SharedStyles.container}>
<ScrollView >
<Text style={SharedStyles.heading}>
Test Analytics
</Text>
<Text style={SharedStyles.enabledText}>
Analytics enabled: {this.state.analyticsEnabled ? 'yes' : 'no'}
</Text>
<TouchableOpacity onPress={this.toggleEnabled}>
<Text style={SharedStyles.toggleEnabled}>
toggle
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => Analytics.trackEvent('Button press', { page: 'Home page' })}>
<Text style={SharedStyles.button}>
Track Event
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => Analytics.trackEvent('Button press', { propertyValueTooLong: '12345678901234567890123456789012345678901234567890123456789012345' })}>
<Text style={SharedStyles.button}>
Track Event - event property value truncated after 64 characters
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => Analytics.trackEvent('Button press', data)}>
<Text style={SharedStyles.button}>
Track Event badly (Do not do this, only strings are supported)
</Text>
</TouchableOpacity>
</ScrollView>
</View>
);
}
/* eslint-enable no-undef */
}