Skip to content

Commit

Permalink
refactor platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
GM-appsflyer committed Jan 31, 2023
1 parent d31f6b1 commit 580eae7
Show file tree
Hide file tree
Showing 12 changed files with 813 additions and 46 deletions.
771 changes: 769 additions & 2 deletions dist/appsflyerSdk.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function main(){
let appsflyer;
let response;
let config = SAMSUNG_CONFIG;
// config = LG_CONFIG;
config = LG_CONFIG;
// config = CUSTOM_CONFIG;

try{
Expand Down
18 changes: 9 additions & 9 deletions src/AppsFlyerSDK.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import AppsFlyerCore from './core/AppsFlyerCore.js';
import Samsung from './platforms/samsung/samsung.js';
import LG from './platforms/lg/lg.js';
import Vizio from './platforms/custom/vizio.js';
import Vidaa from './platforms/custom/vidaa.js';
import Samsung from './platforms/samsung.js';
import LG from './platforms/lg.js';
import Vizio from './platforms/vizio.js';
import Vidaa from './platforms/vidaa.js';
import {INVALID_SDK, DEVICE_OS_NOT_SUPPORT, NO_PLATFORM_FOUND} from './core/utils/constants.js';
import {Platform} from './platforms/types/types.js';
import {Platform} from './platforms/utils/types.js';
import semver from 'semver';

const PLATFORM_MAPPING = [Samsung, LG, Vizio, Vidaa]
Expand Down Expand Up @@ -42,18 +42,18 @@ class AppsFlyerSDK {

async init(config) {
return new Promise( async(resolve, reject) => {
let platformPayload, platformLogs;
let platformData, platformLogs;
if(this.isSDKValid()){
try{
platformPayload = await this.platformInstance.getPlatformPayload();
platformData = await this.platformInstance.getPlatformData();
platformLogs = this.platformInstance.getPlatformLogs();
} catch (error){
platformLogs.push(error)
}
const isVersionValid = await this.validateOSVersion(platformPayload.platform, platformPayload.payload.device_os_version)
const isVersionValid = await this.validateOSVersion(platformData.platform, platformData.payload.device_os_version)
if(isVersionValid){
try{
await this.appsflyerInstance.init(config, platformPayload, platformLogs);
await this.appsflyerInstance.init(config, platformData, platformLogs);
resolve(true)
} catch (error){
reject(error)
Expand Down
6 changes: 3 additions & 3 deletions src/core/AppsFlyerCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class AppsFlyerCore {
}

// init API sets appsFlyerOptions, sessionCount and AppsFlyer ID
async init(config, platformPayload, platformLogs) {
async init(config, platformData, platformLogs) {
if(config != undefined && typeof config === 'object' && Object.keys(config).length !== 0){
const appId = config.appId;
const devKey = config.devKey;
Expand Down Expand Up @@ -120,8 +120,8 @@ class AppsFlyerCore {
this.appsFlyerOptions.isSandbox = isSandbox;

this.requests = new Requests(this.utils, this.logger, this.auth, this.storage, isSandbox);
this.setPayload(platformPayload.payload);
this.setPlatform(platformPayload.platform);
this.setPayload(platformData.payload);
this.setPlatform(platformData.platform);
this.setAppsFlyerID();
this.setSessionCount();
this.setRequestID();
Expand Down
12 changes: 6 additions & 6 deletions src/platforms/custom/custom.js → src/platforms/custom.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {PlatformPayload} from '../platformPayload.js';
import {Platform, DeviceIds} from '../types/types.js';
import {platformData} from './utils/platformData.js';
import {Platform, DeviceIds} from './utils/types.js';

class CustomPlatform {
constructor(platform){
this.platform = platform;
this.platformLogs = [];
}
async getPlatformPayload() {
let platformPayload = PlatformPayload(this.platform);
async getPlatformData() {
let data = platformData(this.platform);
let idType;

switch(this.platform){
Expand All @@ -21,8 +21,8 @@ class CustomPlatform {
idType = DeviceIds.Custom;
}

platformPayload.payload.device_ids.push({type: idType, value: ""});
return platformPayload;
data.payload.device_ids.push({type: idType, value: ""});
return data;
}

getPlatformLogs() {
Expand Down
22 changes: 11 additions & 11 deletions src/platforms/lg/lg.js → src/platforms/lg.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import {PlatformPayload} from '../platformPayload.js';
import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from '../types/constants.js';
import {DeviceIds, Platform} from '../types/types.js';
import {platformData} from './utils/platformData.js';
import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from './utils/constants.js';
import {DeviceIds, Platform} from './utils/types.js';

class LG {
constructor(){
this.platformLogs = [];
}
async getPlatformPayload() {
let lgPlatformPayload = PlatformPayload(Platform.Webos);
async getPlatformData() {
let data = platformData(Platform.Webos);
try {
const lgUdid = await this.getLGUDID()
lgPlatformPayload.payload.device_ids.push({type: DeviceIds.Lgudid, value: lgUdid});
data.payload.device_ids.push({type: DeviceIds.Lgudid, value: lgUdid});
} catch (error) {
this.platformLogs.push(error);
}

try {
let deviceData = await this.getWebosData();
lgPlatformPayload.payload.device_model = deviceData.device_model;
lgPlatformPayload.payload.device_os_version = deviceData.device_os_version;
data.payload.device_model = deviceData.device_model;
data.payload.device_os_version = deviceData.device_os_version;
} catch (error) {
this.platformLogs.push(error);
}

try {
lgPlatformPayload.payload.app_version = await this.getAppVersion();
data.payload.app_version = await this.getAppVersion();
} catch (error) {
lgPlatformPayload.payload.app_version = DEFAULT_APP_VERSION;
data.payload.app_version = DEFAULT_APP_VERSION;
this.platformLogs.push(error);
}

return lgPlatformPayload;
return data;

}
getPlatformLogs() {
Expand Down
22 changes: 11 additions & 11 deletions src/platforms/samsung/samsung.js → src/platforms/samsung.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import {PlatformPayload} from '../platformPayload.js';
import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from '../types/constants.js';
import {DeviceIds, Platform} from '../types/types.js';
import {platformData} from './utils/platformData.js';
import {DEFAULT_DEVICE_ID, DEFAULT_APP_VERSION} from './utils/constants.js';
import {DeviceIds, Platform} from './utils/types.js';

class Samsung {
constructor(){
this.platformLogs = [];
}
async getPlatformPayload() {
let samsungPlatformPayload = PlatformPayload(Platform.Tizen);
async getPlatformData() {
let data = platformData(Platform.Tizen);

samsungPlatformPayload.payload.app_version = await this.getAppVersion();
data.payload.app_version = await this.getAppVersion();
const limitAdTracking = await this.getIsLATEnabled();
samsungPlatformPayload.payload.limit_ad_tracking = limitAdTracking
data.payload.limit_ad_tracking = limitAdTracking

if(!limitAdTracking){
const tifa = await this.getTIFA();
if(tifa !== undefined){
samsungPlatformPayload.payload.device_ids.push({type: DeviceIds.Tifa, value: tifa});
data.payload.device_ids.push({type: DeviceIds.Tifa, value: tifa});
}
}

samsungPlatformPayload.payload.device_model = await this.getModel();
samsungPlatformPayload.payload.device_os_version = await this.getDeviceOsVersion();
data.payload.device_model = await this.getModel();
data.payload.device_os_version = await this.getDeviceOsVersion();

return samsungPlatformPayload;
return data;
}

getPlatformLogs() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export let PlatformPayload = function PlatformPayload(platform) {
export let platformData = (platform) => {
return {
platform: platform,
payload: {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/platforms/custom/vidaa.js → src/platforms/vidaa.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Platform} from '../types/types.js';
import {Platform} from './utils/types.js';
import CustomPlatform from './custom.js';

class Vidaa extends CustomPlatform {
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/custom/vizio.js → src/platforms/vizio.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Platform} from '../types/types.js';
import {Platform} from './utils/types.js';
import CustomPlatform from './custom.js';

class Vizio extends CustomPlatform {
Expand Down

0 comments on commit 580eae7

Please sign in to comment.