Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing event from V0 #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 RudderStack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## User Transformations for RudderStack
# User Transformations in RudderStack

RudderStack gives you the ability to code custom user transformation functions to implement use-cases based on your requirements. As these transformations are written in JavaScript, it is very easy for you to integrate them into the RudderStack data pipeline. Some common use cases for these transformations include PII detection and masking, event removal and aggregation, and event enrichment.

Expand All @@ -12,9 +12,11 @@ A user transformation does the following:
- Emits the modified payload

## Get Started

The sample user transformations included in this repository can be added via the RudderStack Configuration Plane.

Adding a new user-defined transformation function is quite simple:

- Log into the [RudderStack dashboard](https://app.rudderstack.com/)
- Click on the [Transformations](https://app.rudderstack.com/transformations) link
- Click on **CREATE NEW**
Expand Down Expand Up @@ -74,12 +76,14 @@ The following user transformations are included in this repository, which you ca
**Note**: For a detailed description of each of the user transformations included in this repository, please refer to our [wiki](https://github.com/rudderlabs/sample-user-transformers/wiki/Sample-User-Transformations) page.

## License
The RudderStack Server is released under the [AGPLv3 license](https://www.gnu.org/licenses/agpl-3.0-standalone.html).

## What is RudderStack
The transformations contained in this repository are released under the [MIT license](https://github.com/rudderlabs/sample-user-transformers/blob/master/LICENSE.md).

# What is RudderStack
RudderStack is an open-source customer data infrastructure platform for collecting, storing and routing customer event data to the destinations as specified by you. RudderStack runs on your cloud environment or even your data center and provides a powerful framework to process and route your event data on the fly.

To know more about RudderStack, please visit our [website](https://rudderstack.com/) or check our [GitHub](https://github.com/rudderlabs) repository. You can also [contact us](https://rudderstack.com/contact/) or join our [Discord](https://discordapp.com/invite/xNEdEGw) channel to know more about the platform, and what we do. Make sure you also check out the [HackerNews discussion](https://news.ycombinator.com/item?id=21081756) around RudderStack!
To know more about RudderStack, please visit our [website](https://rudderstack.com/) or check our [GitHub](https://github.com/rudderlabs) repository. You can also [contact us](https://rudderstack.com/contact/) or join our [Slack](https://resources.rudderstack.com/join-rudderstack-slack) channel to know more about the platform, and what we do. Make sure you also check out the [HackerNews discussion](https://news.ycombinator.com/item?id=21081756) around RudderStack!

## Contribute
Please see the [contributing guide](https://github.com/rudderlabs/rudder-server/blob/master/CONTRIBUTING.md) to get more information on how you can contribute to this project. If you have any ideas on developing your own custom transformation functions and want some more inputs or thoughts on them, you can talk to us on our [Discord](https://discordapp.com/invite/xNEdEGw) channel.

Please see the [contributing guide](https://github.com/rudderlabs/rudder-server/blob/master/CONTRIBUTING.md) to get more information on how you can contribute to this project. If you have any ideas on developing your own custom transformation functions and want some more inputs or thoughts on them, you can talk to us on our [Slack](https://resources.rudderstack.com/join-rudderstack-slack) channel.
86 changes: 86 additions & 0 deletions SalesforceObjectTrackConversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// In the below example, we'll be transforming a standard track event to a correct identify event
// to be working with Salesforce Object implementation
export function transformEvent(event) {
// map of events to object types
// create - if there is no valid value for the field "Id" (case sensitive)
// update - if a valid value is passed to the "Id" field
const eventActionMap = {
"Contact Created": {
object: "Contact",
properties: {
firstName: "FirstName",
lastName: "LastName",
email: "Email",
phone: "Phone",
homePhone: "HomePhone"
}
},
"Contact Updated": {
object: "Contact",
properties: { // will call update operation if contactId is valid
contactId: "Id",
firstName: "FirstName",
lastName: "LastName",
email: "Email",
phone: "Phone",
homePhone: "HomePhone"
}
}
};
const transformedEvents = [];
const ev = event;

if (ev.type !== "track") {
// add all events except track
transformedEvents.push(ev);
}

const eventTransformationMap = eventActionMap[ev.event];
if (!eventTransformationMap) {
// add all non-mapped events
transformedEvents.push(ev);
}

const { object, properties } = eventTransformationMap;
if (!object || !properties) {
// Salesforce object or mapping is not correct
transformedEvents.push(ev);
}

if (!ev.properties) {
// add the event if there is no property in the event
transformedEvents.push(ev);
}

const eventProperties = ev.properties;
const traits = {};
let objectId;
// iterate over defined properties and extract the values from event.properties and
// set them to traits and context.traits
Object.keys(properties).forEach(key => {
if (properties[key] === "Id") {
// take the Id separately and
objectId = eventProperties[key];
} else {
traits[properties[key]] = eventProperties[key];
}
});

// finally contruct the event back
const finalEvent = ev;
finalEvent.type = "identify";
finalEvent.traits = traits;
finalEvent.context.traits = traits;
finalEvent.context.externalId = [
{
type: `Salesforce-${object}`,
id: objectId
}
];
finalEvent.integrations = { Salesforce: true };

transformedEvents.push(finalEvent);

// return the final array
return transformedEvents;
}