Skip to content

Commit 58ebe11

Browse files
authored
Merge pull request #793 from OneSignal/fadi/sdk-2963-add-custom-events-for-unity-package
Unity SDK Custom Events
2 parents def8368 + e6a4b41 commit 58ebe11

File tree

25 files changed

+657
-232
lines changed

25 files changed

+657
-232
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
OneSignalExample/.idea/
33

44
.DS_Store
5+
.gradle/

OneSignalExample/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
#
33
# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
44
#
5+
/.utmp/
56
/[Ll]ibrary/
67
/[Tt]emp/
78
/[Oo]bj/
89
/[Bb]uild/
910
/[Bb]uilds/
1011
/[Ll]ogs/
1112
/[Mm]emoryCaptures/
13+
/UserSettings/
1214

1315
# Asset meta data should only be ignored when the corresponding asset is also ignored
1416
!/[Aa]ssets/**/*.meta
@@ -58,3 +60,12 @@ sysinfo.txt
5860
# Crashlytics generated file
5961
crashlytics-build.properties
6062

63+
# User-specific Unity Editor settings
64+
/[Uu]serSettings/
65+
66+
# Gradle template backup files
67+
*.backup
68+
*.backup.meta
69+
*.backup2
70+
*.backup2.meta
71+

OneSignalExample/Assets/OneSignal/Example/OneSignalExampleBehaviour.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,58 @@ public void GetTags()
461461
_log($"Get all user tags " + dictionaryString.TrimEnd(',', ' ') + "}");
462462
}
463463

464+
public void TrackEvent()
465+
{
466+
// Detect platform
467+
string platform =
468+
Application.platform == RuntimePlatform.Android ? "android"
469+
: Application.platform == RuntimePlatform.IPhonePlayer ? "ios"
470+
: "unknown";
471+
472+
// Track event without properties
473+
_log($"Tracking an event <b>Unity-{platform}-noprops</b> without properties");
474+
OneSignal.User.TrackEvent($"Unity-{platform}-noprops");
475+
476+
// Track event with comprehensive properties
477+
var properties = new Dictionary<string, object>
478+
{
479+
{ "someNum", 123 },
480+
{ "someFloat", 3.14159f },
481+
{ "someString", "abc" },
482+
{ "someBool", true },
483+
{
484+
"someObject",
485+
new Dictionary<string, object>
486+
{
487+
{ "abc", "123" },
488+
{
489+
"nested",
490+
new Dictionary<string, object> { { "def", "456" } }
491+
},
492+
}
493+
},
494+
{
495+
"someArray",
496+
new List<object> { 1, 2 }
497+
},
498+
{
499+
"someMixedArray",
500+
new List<object>
501+
{
502+
1,
503+
"2",
504+
new Dictionary<string, object> { { "abc", "123" } },
505+
}
506+
},
507+
{ "someNull", null },
508+
};
509+
510+
_log(
511+
$"Tracking an event <b>Unity-{platform}</b> with properties: {Json.Serialize(properties)}"
512+
);
513+
OneSignal.User.TrackEvent($"Unity-{platform}", properties);
514+
}
515+
464516
/*
465517
* Outcomes
466518
*/

0 commit comments

Comments
 (0)