Skip to content

Commit

Permalink
Merge pull request #7 from AppsFlyerSDK/osValidation
Browse files Browse the repository at this point in the history
Os validation
  • Loading branch information
GM-appsflyer authored May 28, 2023
2 parents fe94266 + 510ee92 commit 052d3c3
Show file tree
Hide file tree
Showing 36 changed files with 711 additions and 375 deletions.
146 changes: 33 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
### <a id="plugin-build-for"> This SDK is built for

- <img src="https://github.com/AppsFlyerSDK/AppsFlyerSDK-appsflyer-html5-ctv-sdk/blob/main/images/tizen.png?raw=true" alt="drawing" width="15"/> Samsung Tizen
- <img src="https://github.com/AppsFlyerSDK/AppsFlyerSDK-appsflyer-html5-ctv-sdk/blob/main/images/lg.png?raw=true" alt="drawing" width="15"/> LG Webos
- <img src="https://github.com/AppsFlyerSDK/AppsFlyerSDK-appsflyer-html5-ctv-sdk/blob/main/images/tizen.png?raw=true" alt="drawing" width="15"/> Samsung (Tizen 4 & above)
- <img src="https://github.com/AppsFlyerSDK/AppsFlyerSDK-appsflyer-html5-ctv-sdk/blob/main/images/lg.png?raw=true" alt="drawing" width="15"/> LG (Webos 4 & above)
- VIZIO & Vidaa. [Please follow the implementation guide](/docs/other-platforms.md)


## 📖 Guides
- [Adding the SDK to your project](#installation)
Expand All @@ -22,12 +24,19 @@
- [Platforms dependecy](#platform-dependency)
- [Samsung](#samsung)
- [LG](#lg)
- [Initializing the SDK](#integration)
- [Launch event](#launch)
- [In-app Events](#inappevents)
- [Testing the integration](#testing)
- [Response codes](#response-codes)
- [Sample App](#demo)
- [Support for other platforms](/docs/other-platforms.md)
- [Basic implemantation of the SDK](#integration)
- [API](/docs/api.md)
- [AppsFlyerSDK initialization](/docs/api.md#newAppsflyerSdk)
- [Start](/docs/api.md#start)
- [In-app events](/docs/api.md#inappevents)
- [Set custom payload](/docs/api.md#setCustomPayload)
- [Set customer user Id](/docs/api.md#setCustomerUserId)
- [Init (Deprecated!)](/docs/api.md#init)
- [Testing the integration](/docs/testing.md)
- [Logs](/docs/testing.md#logs)
- [Response codes](/docs/testing.md#response-codes)
- [Sample App](/docs/testing.md#demo)


#
Expand All @@ -52,7 +61,7 @@ Download the appsflyerSdk.bundle.js file from [here](dist/appsflyerSdk.bundle.js
<script src="[bundle-js-location]"></script>
```

## <a id="platform-dependency"> Platforms dependecy
## <a id="platform-dependency"> Platform dependency

In order for the SDK to fetch device data from the relevant platform, make sure to follow the following instructions:

Expand Down Expand Up @@ -82,120 +91,31 @@ In order for the SDK to fetch device data from the relevant platform, make sure
<script type="text/javascript" src="[webOSTVjs-1.2.4-directory]"></script>
```


## <a id="integration"> 🚀 Initializing the SDK
## <a id="integration"> 🚀 Basic implemantation of the SDK

Initialize the SDK to enable AppsFlyer to detect installations, sessions (app opens) and updates.<br>

```javascript
import AppsFlyerSDK from 'appsflyer-html5-ctv-sdk'

let appsflyer = new AppsFlyerSDK();
let appsflyer;
let config = {
devKey: "RxutGo4bSB9MKkM7bMCjHP",
appId: "3202204027284",
isDebug: true,
isSandbox: false
}

await appsflyer.init(config);

```

| Setting | Description |
| -------- | ------------- |
| devKey | Your application [devKey](https://support.appsflyer.com/hc/en-us/articles/207032066-Basic-SDK-integration-guide#retrieving-the-dev-key) provided by AppsFlyer (required) |
| appId | [App ID](https://support.appsflyer.com/hc/en-us/articles/207377436-Adding-a-new-app#available-in-the-app-store-google-play-store-windows-phone-store) you configured in your AppsFlyer dashboard (required) |
| isDebug | Show Debug logs - set to `true` for testing only! |
| isSandbox | Send events to sandbox endpoints - set to `true` for testing only! |


## <a id="launch"> Launch event

```javascript
appsflyer.start()
.then((response)=>{
console.log("start API response success: " + JSON.stringify(response));
}).catch((err)=>{
console.log("start API response err: " + JSON.stringify(err));
});
```


## <a id="inappevents"> In-app events

**<a id="logEvent"> `logEvent(String eventName, Object eventValues)`**

| parameter | type | description |
| ----------- |----------|------------------------------------------ |
| eventName | String | The event name, it is presented in your dashboard. |
| eventValues | Object | The event values that are sent with the event. |

```javascript
appsflyer.logEvent("af_purchase", {"af_revenue" : 1.99, "af_currency": "USD"})
.then((response)=>{
console.log("logEvent API response success: " + JSON.stringify(response));
}).catch((err)=>{
console.log("logEvent API response err: " + JSON.stringify(err));
});
```

## <a id="testing"> Testing the integration

- In order to check a succesful integration of the AppsFlyer SDK, please enable `isDebug` option to `true`;

- The following request should be sent:

```
// launch request:
AppsFlyerSDK :: Sending start request
AppsFlyerSDK :: https://events.appsflyer.com/v1.0/c2s/session/app/tizen/3202204027284
AppsFlyerSDK :: {"device_ids":[{"type":"custom","value":"c6577bb9-d4d1-4adf-809e-c3abf7c76b58"}],"limit_ad_tracking":true,"device_model":"UKS9000","device_os_version":"5.0","customer_user_id":"15667737-366d-4994-ac8b-653fe6b2be4a","app_version":"1.0.5","request_id":"aa64ea40-6cda-4fde-b4c5-31f600e1b50f","timestamp":1662035187532}
// logEvent request:
AppsFlyerSDK :: Sending logEvent request
AppsFlyerSDK :: https://events.appsflyer.com/v1.0/c2s/inapp/app/tizen/3202204027284
AppsFlyerSDK :: {"device_ids":[{"type":"custom","value":"c6577bb9-d4d1-4adf-809e-c3abf7c76b58"}],"limit_ad_tracking":true,"device_model":"UKS9000","device_os_version":"5.0","customer_user_id":"15667737-366d-4994-ac8b-653fe6b2be4a","app_version":"1.0.5","request_id":"c55bb0fe-fed5-4c02-8e5d-c6031f56ecaf","timestamp":1662035187534,"event_name":"af_purchase","event_parameters":{"af_revenue":1.99,"af_currency":"USD"}}
```


- Check the response code is 202/200

```
AppsFlyerSDK :: start request success with status code: 202 Message: Success
AppsFlyerSDK :: logEvent request success with status code: 202 Message: Success
```

### <a id="response-codes"> Response codes

| response code | description |
| ----------- |------------------------------------------ |
| 200/202 | Successful |
| 400 | In case the authentication succeeded, if any of the mandatory fields in the message body are missing, or if any of the fields are invalid|
| 401 | If the app doesn’t exist or the authentication failed |
| 403 | In case app traffic should be blocked due to Zero package limit |
| 404 | network error |

## <a id="demo"> Sample app

Try our demo app!

1. Clone the repo

2. Comment/uncomment the relevant config file for the relevant platform in example/main.js (LG/SAMSUNG)

3. Execute the following:

```bash
$ yarn buildDev
```

Open and run the following directory from your emulator/simulator or real device:

```
appsflyer-html5-ctv-sdk/example/app
```

![demo printscreen](https://github.com/AppsFlyerSDK/AppsFlyerSDK-appsflyer-html5-ctv-sdk/blob/main/images/demo.png?raw=true)
try{
appsflyer = await new AppsFlyerSDK(config);
}catch(e){
console.log("AppsFlyerSDK initialization failed. Error " + e);
}

try{
let response = await appsflyer.start();
console.log("start API response success: " + JSON.stringify(response));
}catch(err){
console.log("start API response err: " + JSON.stringify(err));
}
```
2 changes: 1 addition & 1 deletion __tests__/mock/responses.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const MOCK_SUCCESS_RESPONSE = {
"message": "Request Succeed",
"message": "Success",
"status": 200,
}
export const MOCK_FAILED_RESPONSE = {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/publicAPIs/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const dataSetBadInputs = [

describe.each(Platforms)("Init API", (config, payload) => {
beforeAll(async () => {
appsflyer = AppsFlyerCore.prototype.getInstance();
appsflyer = AppsFlyerCore;
await appsflyer.init(config, payload);
})

Expand All @@ -48,7 +48,7 @@ describe.each(Platforms)("Init API", (config, payload) => {

describe("Init wrong config", (_, payload) => {
beforeAll(async () => {
appsflyer = AppsFlyerCore.prototype.getInstance();
appsflyer = AppsFlyerCore;
})

it.each(dataSetBadInputs)("Bad inputs", async (config, expectedErr) => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/publicAPIs/logEvent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const dataSet = [
describe.each(Platforms)("Log event API ", (config, payload) => {
beforeAll(async () => {
fetch.resetMocks();
appsflyer = AppsFlyerCore.prototype.getInstance();
appsflyer = AppsFlyerCore;
await appsflyer.init(config, payload);
timesBeingCalled = 1;
})
Expand Down
26 changes: 13 additions & 13 deletions __tests__/publicAPIs/setCustomPayload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const dataSet = [

describe.each(Platforms)("setCustomPayload API ", (config, payload) => {
beforeAll(async () => {
appsflyer = AppsFlyerCore.prototype.getInstance();
appsflyer = AppsFlyerCore;
await appsflyer.init(config, payload);
})

Expand All @@ -44,18 +44,18 @@ describe.each(Platforms)("setCustomPayload API ", (config, payload) => {
}
});

it.each(dataSetBadInput)("setCustomPayload not overriding exsiting inputs", (additionalPayload) => {
let payload;
try {
response = appsflyer.setCustomPayload(additionalPayload);
payload = appsflyer.payload;
} catch(err){
response = err
};
// it.each(dataSetBadInput)("setCustomPayload not overriding exsiting inputs", (additionalPayload) => {
// let payload;
// try {
// response = appsflyer.setCustomPayload(additionalPayload);
// payload = appsflyer.payload;
// } catch(err){
// response = err
// };

Object.keys(additionalPayload).forEach((key) => {
expect(payload[key]).not.toEqual(additionalPayload[key]);
})
});
// Object.keys(additionalPayload).forEach((key) => {
// expect(payload[key]).not.toEqual(additionalPayload[key]);
// })
// });
})

2 changes: 1 addition & 1 deletion __tests__/publicAPIs/setCustomerUserId.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const dataSet = [

describe.each(Platforms)("setCustomerUserId API ", (config, payload) => {
beforeAll(async () => {
appsflyer = AppsFlyerCore.prototype.getInstance();
appsflyer = AppsFlyerCore;
await appsflyer.init(config, payload);
})

Expand Down
2 changes: 1 addition & 1 deletion __tests__/publicAPIs/start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.setTimeout(7000)
describe.each(Platforms)("Start API", (config, payload) => {
beforeAll(async () => {
fetch.resetMocks();
appsflyer = AppsFlyerCore.prototype.getInstance();
appsflyer = AppsFlyerCore;
await appsflyer.init(config, payload);
})

Expand Down
2 changes: 1 addition & 1 deletion __tests__/request/request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe.each(Platforms)("Test endpoints", (config, payload) => {
global.localStorage.setItem('appsflyer', '{"sessionCount":0,"appsflyerID":""}')
appId = config.appId;
platformType = payload.platform;
appsflyer = AppsFlyerCore.prototype.getInstance();
appsflyer = AppsFlyerCore;
await appsflyer.init(config, payload);

// define endpoints
Expand Down
3 changes: 3 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
2 changes: 1 addition & 1 deletion dist/appsflyerSdk.bundle.js

Large diffs are not rendered by default.

Loading

0 comments on commit 052d3c3

Please sign in to comment.