forked from idehub/react-native-google-analytics-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
90 lines (79 loc) · 3.08 KB
/
index.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
86
87
88
89
90
"use strict";
const GoogleAnalyticsBridge = require("react-native").NativeModules.GoogleAnalyticsBridge;
class GoogleAnalytics {
/**
* Track the current screen/view
* @param {String} screenName The name of the current screen
*/
static trackScreenView(screenName) {
GoogleAnalyticsBridge.trackScreenView(screenName);
}
/**
* Track an event that has occured
* @param {String} category The event category
* @param {String} action The event action
* @param {Object} optionalValues An object containing optional label and value
*/
static trackEvent(category, action, optionalValues = {}) {
GoogleAnalyticsBridge.trackEvent(category, action, optionalValues);
}
/**
* Track an event that has occured
* @param {String} category The event category
* @param {Number} value The timing measurement in milliseconds
* @param {Object} optionalValues An object containing optional name and label
*/
static trackTiming(category, value, optionalValues = {}) {
GoogleAnalyticsBridge.trackTiming(category, value, optionalValues);
}
/**
* Track a purchase event. This uses the Enhanced Ecommerce GA feature.
* @param {Object} product An object with product values
* @param {Object} transaction An object with transaction values
* @param {String} eventCategory The event category, defaults to Ecommerce
* @param {String} eventAction The event action, defaults to Purchase
*/
static trackPurchaseEvent(product = {}, transaction = {}, eventCategory = "Ecommerce", eventAction = "Purchase") {
GoogleAnalyticsBridge.trackPurchaseEvent(product, transaction, eventCategory, eventAction);
}
/**
* Track an exception
* @param {String} error The description of the error
* @param {Boolean} fatal A value indiciating if the error was fatal, defaults to false
*/
static trackException(error, fatal = false) {
GoogleAnalyticsBridge.trackException(error, fatal);
}
/**
* Sets the current userId for tracking.
* @param {String} userId The current userId
*/
static setUser(userId) {
GoogleAnalyticsBridge.setUser(userId);
}
/**
* Sets if IDFA (identifier for advertisers) collection should be enabled
* @param {Boolean} enabled Defaults to true
*/
static allowIDFA(enabled = true) {
GoogleAnalyticsBridge.allowIDFA(enabled);
}
/**
* Track a social interaction, Facebook, Twitter, etc.
* @param {String} network
* @param {String} action
* @param {String} targetUrl
*/
static trackSocialInteraction(network, action, targetUrl) {
GoogleAnalyticsBridge.trackSocialInteraction(network, action, targetUrl);
}
/**
* Sets if the tracker should have dry run enabled.
* If dry run is enabled, no analytics data will be sent to your tracker.
* @param {Boolean} enabled
*/
static setDryRun(enabled) {
GoogleAnalyticsBridge.setDryRun(enabled);
}
}
module.exports = GoogleAnalytics;