{"id":20340197,"url":"https://github.com/webengage/xamarin-android-sample","last_synced_at":"2025-03-04T14:44:55.504Z","repository":{"id":82265249,"uuid":"143364748","full_name":"WebEngage/xamarin-android-sample","owner":"WebEngage","description":"Sample Xamarin Android project.","archived":false,"fork":false,"pushed_at":"2020-02-27T08:45:03.000Z","size":3786,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-14T18:10:13.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebEngage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-03T01:59:22.000Z","updated_at":"2020-02-27T08:45:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"6aeb00ea-8bf6-4536-8d91-5b6f20811969","html_url":"https://github.com/WebEngage/xamarin-android-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-android-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-android-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-android-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebEngage%2Fxamarin-android-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebEngage","download_url":"https://codeload.github.com/WebEngage/xamarin-android-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241867649,"owners_count":20033815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T21:20:12.048Z","updated_at":"2025-03-04T14:44:55.486Z","avatar_url":"https://github.com/WebEngage.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# WebEngage Xamarin Android Sample\n\nThis is Xamarin Android sample application to demonstrate usage of Xamarin binding library of WebEngage Android SDK.\n\n\n## Installation\n\n1. Download [WebEngage Xamarin Android Library (v0.4.0.0)](https://s3-us-west-2.amazonaws.com/webengage-sdk/xamarin/android/0.4.0.0/WebEngageXamarinAndroid.dll).\n\n2. To consume this downloaded .DLL in your Xamarin.Android app, you must first add a reference to your Xamarin.Android project by right-clicking on the References node of your project and select Add Reference.\n\n\n## Initialization\n\nInitialize WebEngage SDK with your license code from onCreate callback of your Application class as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\n...\n\n    [Application]\n    public class YourApplication : Application\n    {\n    \t...\n\n    \tpublic override void OnCreate()\n        {\n            base.OnCreate();\n\n            WebEngageConfig config = new WebEngageConfig.Builder()\n                                                        .SetWebEngageKey(YOUR-LICENSE-CODE)\n                                                        .SetDebugMode(true)\n                                                        .Build();\n            RegisterActivityLifecycleCallbacks(new WebEngageActivityLifeCycleCallbacks(this, config));\n\n            ...\n        }\n    }\n```\n\n**Note:** Replace YOUR-LICENSE-CODE with your own license code.\n\n\n## Attribution Tracking\n\nIn order to track 'App Installed' events and install-referrer URLs, follow the steps below.\n\n1. Make sure that you are using WebEngage Xamarin Android Library version 0.4.0.0 or above.\n\n2. Download the latest version of [Android Install Referrer library](https://mvnrepository.com/artifact/com.android.installreferrer/installreferrer).\n\n3. Add the aar file to your Xamarin.Android project, for example at location `YourProject/lib/installreferrer-1.1.1.aar`.\n\n4. Set Build Action for the installreferrer aar to AndroidAarLibrary.\n\n\n## Tracking Users\n\n1. Login and logout users as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\n...\n\n\t// User login\n\tWebEngage.Get().User().Login(\"userId\");\n\n\t// User logout\n\tWebEngage.Get().User().Logout();\n```\n\n2. Set system user attributes as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\nusing Com.Webengage.Sdk.Android.Utils;\n...\n\n\t// Set user first name\n\tWebEngage.Get().User().SetFirstName(\"John\");\n\n\t// Set user last name\n\tWebEngage.Get().User().SetLastName(\"Doe\");\t\n\n\t// Set user email\n\tWebEngage.Get().User().SetEmail(\"john.doe@email.com\");\n\n\t// Set user gender\n\tWebEngage.Get().User().SetGender(Gender.Male);\n\n\t// Set user birth-date\n\tWebEngage.Get().User().SetBirthDate(\"1994-04-29\");\n\n\t// Set user company\n\tWebEngage.Get().User().SetCompany(\"Google\");\n```\n\n3. Set custom user attributes as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\nusing Java.Lang;\n...\n\n    // Set custom user attribute\n    WebEngage.Get().User().SetAttribute(\"age\", (Java.Lang.Integer)23);\n    WebEngage.Get().User().SetAttribute(\"premium\", (Boolean)true);\n\n    // Set complex custom user attributes\n    IDictionary\u003cstring, Object\u003e customAttributes = new Dictionary\u003cstring, Object\u003e();\n    customAttributes.Add(\"Twitter Email\", \"john.twitter@mail.com\");\n    customAttributes.Add(\"Subscribed\", true);\n    WebEngage.Get().User().SetAttributes(customAttributes);\n```\n\n**Note:** WebEngage SDK only supports the following data-types: string, Java.Lang.Boolean, Java.Util.Date, Java.Lang.Number, IList\u003cJava.Lang.Object\u003e and IDictionary\u003cstring, Java.Lang.Object\u003e.\n\n4. Delete custom user attributes as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\n...\n\n\t// Delete age attribute\n\tWebEngage.Get().User().DeleteAttribute(\"age\");\n```\n\n\n## Tracking Events\n\nTrack custom events as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\nusing Java.Lang;\n...\n\t\n    // Track simple event\n    WebEngage.Get().Analytics().Track(\"Searched\");\n\n    // Track event with attributes\n    IDictionary\u003cstring, Object\u003e attributes = new Dictionary\u003cstring, Object\u003e();\n    attributes.Add(\"id\", \"~123\");\n    attributes.Add(\"price\", 100);\n    attributes.Add(\"discount\", true);\n    WebEngage.Get().Analytics().Track(\"Added to cart\", attributes);\n\n    // Track events with reporting priority\n    WebEngage.Get().Analytics().Track(\"Added to cart\", attributes, new Analytics.Options().SetHighReportingPriority(true));\n```\n\n**Note:** WebEngage SDK only supports the following data-types: string, Java.Lang.Boolean, Java.Util.Date, Java.Lang.Number, IList\u003cJava.Lang.Object\u003e and IDictionary\u003cstring, Java.Lang.Object\u003e.\n\n\n## Push Notifications\n\n1. Integrate Xamarin.Firebase.Messaging Nuget package with your Xamarin.Android app\n\n2. Send FCM Registration token to WebEngage from your FirebaseInstanceIdService class as shown below.\n\n```csharp\nusing Firebase.Iid;\nusing Com.Webengage.Sdk.Android;\n...\n\n    [Service]\n    [IntentFilter(new[] {\n        \"com.google.firebase.INSTANCE_ID_EVENT\"\n    })]\n    public class YourFirebaseInstanceIdService : FirebaseInstanceIdService\n    {\n        public override void OnTokenRefresh()\n        {\n            var refreshedToken = FirebaseInstanceId.Instance.Token;\n            SendRegistrationToServer(refreshedToken);\n        }\n\n        void SendRegistrationToServer(string token)\n        {\n            WebEngage.Get().SetRegistrationID(token);\n        }\n    }\n\n```\n\nIt is recommended to also send this token to WebEngage from your Application class as shown below.\n\n```csharp\nusing Firebase.Iid;\nusing Com.Webengage.Sdk.Android;\n...\n\t\n    [Application]\n    public class YourApplication : Application\n    {\n        ...\n\n        public override void OnCreate()\n        {\n            base.OnCreate();\n            ...\n\n            string token = FirebaseInstanceId.Instance.Token;\n            WebEngage.Get().SetRegistrationID(token);\n        }\n    }\n\n```\n\n3. Send the notification message data to WebEngage from your FirebaseMessagingService class as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\n...\n\n    [Service]  \n    [IntentFilter(new[] {\n        \"com.google.firebase.MESSAGING_EVENT\"\n    })]\n    public class YourFirebaseMessagingService : FirebaseMessagingService\n    {\n        public override void OnMessageReceived(RemoteMessage message)\n        {\n            base.OnMessageReceived(message);\n            IDictionary\u003cstring, string\u003e data = message.Data;\n            if (data.ContainsKey(\"source\") \u0026\u0026 \"webengage\".Equals(data[\"source\"])) {\n                WebEngage.Get().Receive(data);\n            }\n        }\n    }\n\n```\n\n4. Log in to your WebEngage dashboard and navigate to Integrations \u003e Channels. Select Push tab and paste the your FCM/GCM server key under the field labeled “GCM/FCM Server Key” under Android section. Enter your application package name under the field labeled “Package Name” and click Save.\n\n### Push Notification Callbacks\n\nThis is optional, but if you wish to receive push notification callbacks, then follow the below steps.\n\n1. Implement IPushNotificationCallbacks as shown below.\n\n```csharp\nusing Android.Content;\nusing Android.Util;\nusing Com.Webengage.Sdk.Android.Actions.Render;\nusing Com.Webengage.Sdk.Android.Callbacks;\n\nnamespace YourNamespace\n{\n    public class YourPushNotificationCallbacks : Java.Lang.Object, IPushNotificationCallbacks\n    {\n        public YourPushNotificationCallbacks()\n        {\n        }\n\n        public bool OnPushNotificationActionClicked(Context p0, PushNotificationData p1, string p2)\n        {\n            ...\n            return false;\n        }\n\n        public bool OnPushNotificationClicked(Context p0, PushNotificationData p1)\n        {\n            ...\n            return false;\n        }\n\n        public void OnPushNotificationDismissed(Context p0, PushNotificationData p1)\n        {\n            ...\n        }\n\n        public PushNotificationData OnPushNotificationReceived(Context p0, PushNotificationData p1)\n        {\n            ...\n            return p1;\n        }\n\n        public void OnPushNotificationShown(Context p0, PushNotificationData p1)\n        {\n            ...\n        }\n    }\n}\n```\n\n2. Register IPushNotificationCallbacks implementation in your Application class as shown below.\n\n```csharp\n...\nusing Com.Webengage.Sdk.Android;\nusing Com.Webengage.Sdk.Android.Callbacks;\n...\n\n    [Application]\n    public class YourApplication : Application\n    {\n        ...\n\n        public override void OnCreate()\n        {\n            base.OnCreate();\n            ...\n\n            WebEngage.RegisterPushNotificationCallback(new YourPushNotificationCallbacks());\n        }\n    }\n}\n```\n\n\n\n## In-app Notifications\n\nNo additional integration steps are required for receiving in-app notifications. You can create in-app notifications by logging into your WebEngage Dashboard and navigate to In-app section.\n\n### Tracking Screens\n\nScreens can be tracked to set rules for showing in-app notifications. For example, you can create a rule in WebEngage dashboard to show in-app notification on a particular screen.\n\nTrack screen and screen data as shown below.\n\n```csharp\nusing Com.Webengage.Sdk.Android;\nusing Java.Lang;\n...\n\n    public class YourActivity : Activity\n    {\n        ...\n        protected override void OnStart()\n        {\n            base.OnStart();\n\n            // Track screen data\n            IDictionary\u003cstring, Object\u003e attributes = new Dictionary\u003cstring, Object\u003e();\n            attributes.Add(\"name\", \"Home\");\n            attributes.Add(\"launcher\", true);\n            WebEngage.Get().Analytics().ScreenNavigated(\"Home\", attributes);\n            ...\n        }\n    }\n\n```\n\n### In-app Notification Callbacks\n\nIf you wish to receive in-app notification callbacks, then follow the below steps.\n\n1. Implement IInAppNotificationCallbacks as shown below.\n\n```csharp\nusing Android.Content;\nusing Android.Util;\nusing Com.Webengage.Sdk.Android.Actions.Render;\nusing Com.Webengage.Sdk.Android.Callbacks;\n\nnamespace YourNamespace\n{\n    public class YourInAppNotificationCallbacks : Java.Lang.Object, IInAppNotificationCallbacks\n    {\n        public YourInAppNotificationCallbacks()\n        {\n        }\n\n        public bool OnInAppNotificationClicked(Context p0, InAppNotificationData p1, string p2)\n        {\n            ...\n            return false;\n        }\n\n        public void OnInAppNotificationDismissed(Context p0, InAppNotificationData p1)\n        {\n            ...\n        }\n\n        public InAppNotificationData OnInAppNotificationPrepared(Context p0, InAppNotificationData p1)\n        {\n            ...\n            return p1;\n        }\n\n        public void OnInAppNotificationShown(Context p0, InAppNotificationData p1)\n        {\n            ...\n        }\n    }\n}\n```\n\n2. Register IInAppNotificationCallbacks implementation in your Application class as shown below.\n\n```csharp\n...\nusing Com.Webengage.Sdk.Android;\nusing Com.Webengage.Sdk.Android.Callbacks;\n...\n\n    [Application]\n    public class YourApplication : Application\n    {\n        ...\n\n        public override void OnCreate()\n        {\n            base.OnCreate();\n            ...\n\n            WebEngage.RegisterInAppNotificationCallback(new YourInAppNotificationCallbacks());\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebengage%2Fxamarin-android-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebengage%2Fxamarin-android-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebengage%2Fxamarin-android-sample/lists"}