1
+ using System ;
1
2
using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using System . Net . Http . Headers ;
4
5
using System . Reflection ;
5
6
using Segment . Analytics ;
6
7
using Segment . Serialization ;
7
8
8
- namespace Segment . Analytics . Compat {
9
+ namespace Segment . Analytics . Compat
10
+ {
11
+
12
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
9
13
public class Traits : Dictionary < string , object >
10
14
{
11
15
}
12
16
13
- public class Properties : Dictionary < string , object >
17
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
18
+ public class Properties : Dictionary < string , object >
14
19
{
15
20
}
16
21
17
22
public static class AnalyticsExtensions
18
23
{
24
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
19
25
public static void Track ( this Analytics analytics , string userId , string eventName )
20
26
{
21
- analytics . Track ( eventName , new JsonObject ( ) { { "userId" , userId } } ) ;
27
+ analytics . Track ( eventName , new JsonObject ( ) { { "userId" , userId } } ) ;
22
28
}
23
- public static void Track ( this Analytics analytics , string userId , string eventName , Dictionary < string , object > properties )
29
+
30
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
31
+ public static void Track ( this Analytics analytics , string userId , string eventName ,
32
+ Dictionary < string , object > properties )
24
33
{
25
34
properties . Add ( "userId" , userId ) ;
26
- analytics . Track ( eventName , JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( properties ) ) ) ;
35
+ analytics . Track ( eventName ,
36
+ JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( properties ) ) ) ;
27
37
}
28
38
39
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
29
40
public static void Screen ( this Analytics analytics , string userId , string eventName )
30
41
{
31
- analytics . Screen ( eventName , new JsonObject ( ) { { "userId" , userId } } ) ;
42
+ analytics . Screen ( eventName , new JsonObject ( ) { { "userId" , userId } } ) ;
32
43
}
33
- public static void Screen ( this Analytics analytics , string userId , string eventName , Dictionary < string , object > properties )
44
+
45
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
46
+ public static void Screen ( this Analytics analytics , string userId , string eventName ,
47
+ Dictionary < string , object > properties )
34
48
{
35
49
properties . Add ( "userId" , userId ) ;
36
- analytics . Screen ( eventName , JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( properties ) ) ) ;
50
+ analytics . Screen ( eventName ,
51
+ JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( properties ) ) ) ;
37
52
}
38
53
54
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
39
55
public static void Page ( this Analytics analytics , string userId , string eventName )
40
56
{
41
- analytics . Page ( eventName , new JsonObject ( ) { { "userId" , userId } } ) ;
57
+ analytics . Page ( eventName , new JsonObject ( ) { { "userId" , userId } } ) ;
42
58
}
43
- public static void Page ( this Analytics analytics , string userId , string eventName , Dictionary < string , object > properties )
59
+
60
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
61
+ public static void Page ( this Analytics analytics , string userId , string eventName ,
62
+ Dictionary < string , object > properties )
44
63
{
45
64
properties . Add ( "userId" , userId ) ;
46
- analytics . Page ( eventName , JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( properties ) ) ) ;
65
+ analytics . Page ( eventName ,
66
+ JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( properties ) ) ) ;
47
67
}
48
68
49
- public static void Group ( this Analytics analytics , string userId , string groupId , Dictionary < string , object > traits )
69
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
70
+ public static void Group ( this Analytics analytics , string userId , string groupId ,
71
+ Dictionary < string , object > traits )
50
72
{
51
73
traits . Add ( "userId" , userId ) ;
52
- analytics . Group ( groupId , JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( traits ) ) ) ;
74
+ analytics . Group ( groupId ,
75
+ JsonUtility . FromJson < Segment . Serialization . JsonObject > ( JsonUtility . ToJson ( traits ) ) ) ;
53
76
}
54
77
78
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
55
79
public static void Alias ( this Analytics analytics , string previousId , string userId )
56
80
{
57
81
analytics . _userInfo . _userId = previousId ;
58
82
analytics . Alias ( userId ) ;
59
83
}
60
- }
84
+ }
61
85
86
+ /// <summary>
87
+ /// Plugin that patches user id on a per event basis.
88
+ /// This plugin helps migration from the old Analytics.NET and Analytics.Xamarin libraries,
89
+ /// since Analytics-CSharp does not support passing user id on every track method.
90
+ /// </summary>
91
+ [ Obsolete ( "This should only be used if migrating from Analytics.NET or Analytics.Xamarin" ) ]
62
92
class UserIdPlugin : EventPlugin
63
- {
64
- public override PluginType Type => PluginType . Enrichment ;
65
-
66
- public override RawEvent Execute ( RawEvent incomingEvent )
67
93
{
68
- switch ( incomingEvent )
94
+ public override PluginType Type => PluginType . Enrichment ;
95
+
96
+ public override RawEvent Execute ( RawEvent incomingEvent )
69
97
{
70
- case TrackEvent e :
71
- PatchUserId ( e , e . Properties ) ;
72
- break ;
73
- case PageEvent e :
74
- PatchUserId ( e , e . Properties ) ;
75
- break ;
76
- case ScreenEvent e :
77
- PatchUserId ( e , e . Properties ) ;
78
- break ;
79
- case GroupEvent e :
80
- PatchUserId ( e , e . Traits ) ;
81
- break ;
82
- }
98
+ switch ( incomingEvent )
99
+ {
100
+ case TrackEvent e :
101
+ PatchUserId ( e , e . Properties ) ;
102
+ break ;
103
+ case PageEvent e :
104
+ PatchUserId ( e , e . Properties ) ;
105
+ break ;
106
+ case ScreenEvent e :
107
+ PatchUserId ( e , e . Properties ) ;
108
+ break ;
109
+ case GroupEvent e :
110
+ PatchUserId ( e , e . Traits ) ;
111
+ break ;
112
+ }
83
113
84
- return incomingEvent ;
85
- }
114
+ return incomingEvent ;
115
+ }
86
116
87
- private void PatchUserId ( RawEvent @event , JsonObject jsonObject )
88
- {
89
- if ( jsonObject . ContainsKey ( "userId" ) )
117
+ private void PatchUserId ( RawEvent @event , JsonObject jsonObject )
90
118
{
91
- @event . UserId = jsonObject . GetString ( "userId" ) ;
92
- jsonObject . Remove ( "userId" ) ;
119
+ if ( jsonObject . ContainsKey ( "userId" ) )
120
+ {
121
+ @event . UserId = jsonObject . GetString ( "userId" ) ;
122
+ jsonObject . Remove ( "userId" ) ;
123
+ }
93
124
}
94
125
}
95
126
}
96
- }
0 commit comments