rudderlabs / community-user-transformations

MIT License
1 stars 1 forks source link

Discard Testing Events #20

Open maanpatel2492 opened 1 year ago

maanpatel2492 commented 1 year ago

Contact Details

maanpatel2492@gmail.com

Language

Javascript

Category

Data Processing and Enrichment

Description

Allow only customer events to reach a destination by discarding testing data.

  1. Checks if the given domain is blacklisted or not?
  2. If Yes, Returns null

Code Block

export function transformEvent(event, metadata) {
       const blacklistedDomains = ["test.com"]; 
       const email = event.context.email || event.context.traits.email;
       const domain = email ? email.split("@").pop() : null;
       if (blacklistedDomains.includes(domain)) return null;
       return event; 
}

Input Payload for testing

[
  {
    "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": "AOSP on IA Emulator",
        "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": {
        "address": {
          "city": "Kolkata",
          "country": "India",
          "postalcode": "700096",
          "state": "West bengal",
          "street": "Park Street"
        },
        "age": "30",
        "anonymousId": "8d872292709c6fbe",
        "birthday": "2020-05-26",
        "createdat": "18th March 2020",
        "description": "Premium User for 3 years",
        "email": "identify@test.com",
        "firstname": "John",
        "userId": "sample_user_id",
        "lastname": "Sparrow",
        "name": "John Sparrow",
        "id": "sample_user_id",
        "phone": "9876543210",
        "username": "john_sparrow",
        "quantity": "5",
        "price": "56.0"
      },
      "userAgent": "Dalvik/2.1.0 (Linux; U; Android 9; AOSP on IA Emulator Build/PSR1.180720.117)"
    },
    "event": "identify",
    "integrations": {
      "All": true
    },
    "messageId": "1590431830865-3be680d6-7dcd-4b05-8460-f3acc30046d9",
    "originalTimestamp": "2020-05-25T18:37:10.865Z",
    "type": "identify",
    "userId": "sample_user_id"
  }
]

License