Skip to content

Commit

Permalink
Merge pull request #3 from AppsFlyerSDK/custom_event_params
Browse files Browse the repository at this point in the history
added custom_event_parameters to LogEvent
  • Loading branch information
gilmor-af authored Oct 25, 2023
2 parents c3e7d3a + d41a87f commit 41f09ec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
8 changes: 7 additions & 1 deletion Assets/AppsflyerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public void Stop()
}

// report inapp event to AppsFlyer
public void LogEvent(string event_name, Dictionary<string, object> event_parameters)
public void LogEvent(
string event_name,
Dictionary<string, object> event_parameters,
Dictionary<string, object> event_custom_parameters = null
)
{
if (isStopped)
{
Expand All @@ -126,6 +130,7 @@ public void LogEvent(string event_name, Dictionary<string, object> event_paramet
// setting the event name and value
req.event_name = event_name;
req.event_parameters = event_parameters;
req.event_custom_parameters = event_custom_parameters;

// set request type
AppsflyerRequestType REQ_TYPE = AppsflyerRequestType.INAPP_EVENT_REQUEST;
Expand Down Expand Up @@ -324,6 +329,7 @@ class RequestData
public string customer_user_id;
public string event_name;
public Dictionary<string, object> event_parameters;
public Dictionary<string, object> event_custom_parameters;
}

[Serializable]
Expand Down
16 changes: 12 additions & 4 deletions Assets/AppsflyerScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@ public class AppsflyerScript : MonoBehaviour

void Start()
{
// init the SDK
AppsflyerModule afm = new AppsflyerModule(DEV_KEY, APP_ID, this, IS_SANDBOX);

// set CUID
afm.SetCustomerUserId("testTEST12345");
// start the SDK (send firstopen/session request)
afm.Start();

// LogEvent example
// set event name
string event_name = "af_purchase";
// set event values
Dictionary<string, object> event_parameters = new Dictionary<string, object>();
event_parameters.Add("af_currency", "USD");
event_parameters.Add("af_price", 6.66);
event_parameters.Add("af_revenue", 12.12);
event_parameters.Add("goodsName", "新人邀约购物日");
// send logEvent request
afm.LogEvent(event_name, event_parameters);

// afm.SetCustomerUserId("test-willnotwork");
// afm.Stop();
// send logEvent request with custom params
Dictionary<string, object> event_custom_parameters = new Dictionary<string, object>();
event_custom_parameters.Add("goodsName", "新人邀约购物日");
afm.LogEvent(event_name, event_parameters, event_custom_parameters);

// the creation date in this example is "2023-03-23T08:30:00+00:00"
bool newerDate = afm.IsInstallOlderThanDate("2023-06-13T10:00:00+00:00");
Expand All @@ -38,6 +43,9 @@ void Start()
Debug.Log("newerDate:" + (newerDate ? "true" : "false"));
// will return false
Debug.Log("olderDate:" + (olderDate ? "true" : "false"));

// stop the SDK
afm.Stop();
}

private void Update() { }
Expand Down
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ This method receives your API key, App ID, the parent MonoBehaviour and a sandbo
AppsflyerModule(string devkey, string appid, MonoBehaviour mono, bool isSandbox = false)
```

**Arguments**:

- `DEV_KEY`: Get from the marketer or [AppsFlyer HQ](https://support.appsflyer.com/hc/en-us/articles/211719806-App-settings-#general-app-settings).
- `APP_ID`: The app id on Appsflyer HQ
- `MonoBehaviour mono`: the parent MonoBehaviour.
- `bool isSandbox`: Whether to activate sandbox mode. False by default. This option is for debugging. With the sandbox mode, AppsFlyer dashboard does not show the data.

**Usage**:

```c#
Expand All @@ -43,13 +50,6 @@ AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this);
AppsflyerModule afm = new AppsflyerModule(<< DEV_KEY >>, << APP_ID >>, this, true);
```

**Arguments**:

- `DEV_KEY`: Get from the marketer or [AppsFlyer HQ](https://support.appsflyer.com/hc/en-us/articles/211719806-App-settings-#general-app-settings).
- `APP_ID`: The app id on Appsflyer HQ
- `MonoBehaviour mono`: the parent MonoBehaviour.
- `bool isSandbox`: Whether to activate sandbox mode. False by default. This option is for debugging. With the sandbox mode, AppsFlyer dashboard does not show the data.

### Start

This method sends first open/session requests to AppsFlyer.
Expand Down Expand Up @@ -98,9 +98,19 @@ This method receives an event name and JSON object and sends an in-app event to

**Method signature**

```c#
void LogEvent(
string event_name,
Dictionary<string, object> event_parameters,
Dictionary<string, object> event_custom_parameters = null
)
```
void LogEvent(string event_name, Dictionary<string, object> event_parameters)
```

**Arguments**:

- `string event_name`-
- `Dictionary<string, object> event_parameters`: dictionary object which contains the [predefined event parameters](https://dev.appsflyer.com/hc/docs/ctv-log-event-event-parameters).
- `Dictionary<string, object> event_custom_parameters` (non-mandatory): dictionary object which contains the any custom event parameters.

**Usage**:

Expand All @@ -114,6 +124,11 @@ event_parameters.Add("af_price", 6.66);
event_parameters.Add("af_revenue", 12.12);
// send logEvent request
afm.LogEvent(event_name, event_parameters);

// send logEvent request with custom params
Dictionary<string, object> event_custom_parameters = new Dictionary<string, object>();
event_custom_parameters.Add("goodsName", "新人邀约购物日");
afm.LogEvent(event_name, event_parameters, event_custom_parameters);
```

### IsInstallOlderThanDate
Expand Down

0 comments on commit 41f09ec

Please sign in to comment.