-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJS.uno
More file actions
61 lines (48 loc) · 1.72 KB
/
Copy pathJS.uno
File metadata and controls
61 lines (48 loc) · 1.72 KB
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
using Uno;
using Uno.UX;
using Uno.Threading;
using Uno.Text;
using Uno.Platform;
using Uno.Platform2;
using Uno.Compiler.ExportTargetInterop;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
using Google.Analytics;
namespace Google.Analytics.JS
{
[UXGlobalModule]
public sealed class AnalyticsModule : NativeModule
{
static readonly AnalyticsModule _instance;
static AnalyticsService _analyticsService;
public AnalyticsModule()
{
if(_instance != null) return;
Uno.UX.Resource.SetGlobalKey(_instance = this, "Google/Analytics");
AddMember(new NativeFunction("ScreenView", ScreenView));
AddMember(new NativeFunction("TrackEvent", TrackEvent));
_analyticsService = new AnalyticsService();
Fuse.Platform.Lifecycle.Started += _analyticsService.StartService;
debug_log("Analytics Module Initialized");
}
public object ScreenView(Context context, object[] args)
{
debug_log("Screen View Fired");
var name = (string)args[0];
_analyticsService.ScreenView(name);
return null;
}
public object TrackEvent(Context context, object[] args)
{
debug_log("Track Event Fired");
var eventCategory = (args.Length>0) ? (string)args[0] : null;
var eventAction = (args.Length>1) ? (string)args[1] : null;
var eventLabel = (args.Length>2) ? (string)args[2] : null;
var eventValue = (args.Length>3) ? (string)args[3] : null;
_analyticsService.TrackEvent(eventCategory, eventAction, eventLabel, eventValue);
return null;
}
}
}