Open amiryselim opened 1 year ago
amir@tradeblock.us
Python
Data Processing and Enrichment
Sample traits and values:
{ "address": { "city": "Pingborough", "coordinates": { "lat": 34.44156113333605, "lng": -32.88293380213045 }, "country": "United States", "state": "California", "street_address": "543 Aline Knolls", "street_name": "Harris View", "zip_code": "79707-6178" }, "avatar": "https://robohash.org/sintexercitationemdoloremque.png?size=300x300&set=set1", "credit_card": { "cc_number": "6771-8922-3495-5759" }, "date_of_birth": "2002-11-11", "email": "marhta.tromp@email.com", "employment": { "key_skill": "Work under pressure", "title": "IT Technician" }, "first_name": "Marhta", "gender": "Female", "last_name": "Tromp", "password": "m7QP6RA95k", "phone_number": "+213 (219) 334-1834 x19756", "social_insurance_number": "658058847", "subscription": { "payment_method": "Cheque", "plan": "Gold", "status": "Blocked", "term": "Annual" }, "username": "marhta.tromp" }
import requests import json def transformEvent(event, metadata): sample_user_json = json.loads(requests.request(method="GET", url="https://random-data-api.com/api/v2/users").content) event["userId"] = sample_user_json["uid"] del sample_user_json["uid"] del sample_user_json["id"] event["context"]["traits"] = sample_user_json return event
[ { "anonymousId": "8d872292709c6fbe", "channel": "mobile", "context": { "app": { "build": "1", "name": "AMTestProject", "namespace": "com.rudderstack.android.rudderstack.sampleAndroidApp", "version": "1.0" }, "device": { "id": "8d872292709c6fbe", "manufacturer": "Google", "model": "AOSPonIAEmulator", "name": "generic_x86_arm", "type": "android" }, "library": { "name": "com.rudderstack.android.sdk.core", "version": "1.0.2" }, "locale": "en-US", "network": { "carrier": "Android", "bluetooth": false, "cellular": true, "wifi": true }, "os": { "name": "Android", "version": "9" }, "screen": { "density": 420, "height": 1794, "width": 1080 }, "timezone": "Asia/Kolkata", "traits": { "name": "Name Surname", "email": "sample@example.com" }, "userAgent": "Dalvik/2.1.0 (Linux; U; Android 9; AOSP on IA Emulator Build/PSR1.180720.117)" }, "event": "Product Clicked", "integrations": { "All": true }, "messageId": "1590431830915-73bed370-5889-436d-9a9e-0c0e0c809d06", "properties": { "revenue": "30", "currency": "USD", "quantity": "5", "test_key_2": { "test_child_key_1": "test_child_value_1" }, "price": "58.0" }, "originalTimestamp": "2020-05-25T18:37:10.917Z", "type": "track", "userId": "sample_user_id" } ]
Thank you for contributing to RudderStack Transformations. Your submission will be reviewed soon. Do follow the transformations-challenge channel on RudderStack slack community for updates on the challenge.
Contact Details
amir@tradeblock.us
Language
Python
Category
Data Processing and Enrichment
Description
Sample traits and values:
Code Block
Input Payload for testing
License