Skip to content

Commit

Permalink
Merge pull request #502 from rudderlabs/AM_allow_mobile_empty_devicekey
Browse files Browse the repository at this point in the history
use get lib
  • Loading branch information
arnab-p authored Mar 5, 2021
2 parents 6e73bad + 62241ee commit 5c3e8ec
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 14 deletions.
63 changes: 59 additions & 4 deletions __tests__/data/am_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,7 @@
"CHILD_KEY_102": "value_103"
},
"name_trait": "Company",
"value_trait": [
"Comapny-ABC"
]
"value_trait": ["Comapny-ABC"]
},
"sentAt": "2020-10-20T07:54:58.983Z"
},
Expand Down Expand Up @@ -664,6 +662,63 @@
}
}
},
{
"message": {
"type": "track",
"event": "Sample track event BEFORE IDENTIFY1**",
"sentAt": "2020-09-17T15:07:13.171Z",
"userId": "0572f78fa49c648e",
"channel": "mobile",
"context": {
"os": {
"name": "Android",
"version": "9"
},
"app": {
"name": "AMTestProject",
"build": "1",
"version": "1.0",
"namespace": "com.rudderstack.android.rudderstack.sampleAndroidApp"
},
"locale": "en-US",
"screen": {
"width": 1080,
"height": 2088,
"density": 440
},
"traits": {
"id": "0572f78fa49c648e",
"userId": "0572f78fa49c648e",
"address": {},
"company": {},
"anonymousId": "0572f78fa49c648e"
},
"library": {
"name": "com.rudderstack.android.sdk.core",
"version": "1.0.4"
},
"network": {
"wifi": true,
"carrier": "Android",
"cellular": true,
"bluetooth": false
},
"timezone": "Asia/Kolkata",
"userAgent": "Dalvik/2.1.0 (Linux; U; Android 9; AOSP on IA Emulator Build/PSR1.180720.117)"
},
"messageId": "1600355223510-93e866a7-dc74-4256-a5f4-a41f54532466",
"anonymousId": "0572f78fa49c648e",
"integrations": {
"All": true
},
"originalTimestamp": "2020-09-17T15:07:03.515Z"
},
"destination": {
"Config": {
"apiKey": "abcde"
}
}
},
{
"message": {
"type": "track",
Expand Down Expand Up @@ -1579,4 +1634,4 @@
}
}
}
]
]
55 changes: 50 additions & 5 deletions __tests__/data/am_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
"time": 1571051718299,
"user_id": "12345",
"user_properties": {
"anonymousId" : "12345",
"email" : "[email protected]"
"anonymousId": "12345",
"email": "[email protected]"
}
}
],
Expand Down Expand Up @@ -142,8 +142,8 @@
"time": 1571051718299,
"user_id": "12345",
"user_properties": {
"anonymousId" : "12345",
"email" : "[email protected]"
"anonymousId": "12345",
"email": "[email protected]"
}
}
],
Expand Down Expand Up @@ -524,6 +524,51 @@
"files": {},
"userId": "my-anonymous-id-new"
},
{
"version": "1",
"type": "REST",
"method": "POST",
"endpoint": "https://api.amplitude.com/2/httpapi",
"headers": {
"Content-Type": "application/json"
},
"params": {},
"body": {
"JSON": {
"api_key": "abcde",
"events": [
{
"os_name": "Android",
"os_version": "9",
"device_id": "0572f78fa49c648e",
"insert_id": "1600355223510-93e866a7-dc74-4256-a5f4-a41f54532466",
"carrier": "Android",
"app_name": "AMTestProject",
"app_version": "1.0",
"language": "en-US",
"event_type": "Sample track event BEFORE IDENTIFY1**",
"time": 1600355223515,
"user_id": "0572f78fa49c648e",
"user_properties": {
"id": "0572f78fa49c648e",
"userId": "0572f78fa49c648e",
"address": {},
"company": {},
"anonymousId": "0572f78fa49c648e"
},
"session_id": -1
}
],
"options": {
"min_id_length": 1
}
},
"XML": {},
"FORM": {}
},
"files": {},
"userId": "0572f78fa49c648e"
},
{
"version": "1",
"type": "REST",
Expand Down Expand Up @@ -1598,4 +1643,4 @@
"files": {},
"userId": "2f8b0ba7-d76e-4b91-9577-d1b6ebd68946"
}
]
]
14 changes: 9 additions & 5 deletions v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ function responseBuilderSimple(
break;
default:
if (message.channel === "mobile") {
set(payload, "device_brand", message.context.device.manufacturer);
set(
payload,
"device_brand",
get(message, "context.device.manufacturer")
);
}

payload.time = new Date(
Expand Down Expand Up @@ -406,21 +410,21 @@ function processSingleMessage(message, destination) {
break;
case EventType.PAGE:
evType = `Viewed ${message.name ||
get(message.properties.category) ||
get(message, "properties.category") ||
""} Page`;
message.properties = {
...message.properties,
name: message.name || get(message.properties.category)
name: message.name || get(message, "properties.category")
};
category = ConfigCategory.PAGE;
break;
case EventType.SCREEN:
evType = `Viewed ${message.name ||
get(message.properties.category) ||
get(message, "properties.category") ||
""} Screen`;
message.properties = {
...message.properties,
name: message.name || get(message.properties.category)
name: message.name || get(message, "properties.category")
};
category = ConfigCategory.SCREEN;
break;
Expand Down

0 comments on commit 5c3e8ec

Please sign in to comment.