Skip to content

Commit 5e9d1bd

Browse files
fadi-georgegithub-actions[bot]
andauthored
feat: add custom events support (#845)
Co-authored-by: github-actions[bot] <noreply@onesignal.com>
1 parent 8ef01e8 commit 5e9d1bd

31 files changed

Lines changed: 556 additions & 1882 deletions

.github/workflows/create-release-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
126126
- name: Update Unity SDK version
127127
run: |
128-
PADDED_VERSION=$(printf "%06d" $(echo "${{ inputs.unity_version }}" | sed 's/[^0-9]//g'))
128+
PADDED_VERSION=$(echo "${{ inputs.unity_version }}" | awk -F. '{printf "%02d%02d%02d", $1, $2, $3}')
129129
printf "%s" "${{ inputs.unity_version }}" > OneSignalExample/Assets/OneSignal/VERSION
130130
for file in com.onesignal.unity.core/package.json com.onesignal.unity.android/package.json com.onesignal.unity.ios/package.json; do
131131
sed -i "s/\"version\": \".*\"/\"version\": \"${{ inputs.unity_version }}\"/" "$file"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ OneSignalExample/.utmp/
44
OneSignalExample/Packages/com.unity.asset-store-tools/
55

66
.DS_Store
7+
.gradle/
8+
9+
**/GvhProjectSettings.xml

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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,60 @@ 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+
{ "ghi", null },
493+
}
494+
},
495+
{
496+
"someArray",
497+
new List<object> { 1, 2 }
498+
},
499+
{
500+
"someMixedArray",
501+
new List<object>
502+
{
503+
1,
504+
"2",
505+
new Dictionary<string, object> { { "abc", "123" } },
506+
null,
507+
}
508+
},
509+
{ "someNull", null },
510+
};
511+
512+
_log(
513+
$"Tracking an event <b>Unity-{platform}</b> with properties: {Json.Serialize(properties)}"
514+
);
515+
OneSignal.User.TrackEvent($"Unity-{platform}", properties);
516+
}
517+
464518
/*
465519
* Outcomes
466520
*/

0 commit comments

Comments
 (0)