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

feat: customising and configuring segment #1

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

ami-aman
Copy link
Collaborator

Refers: [CDP] RN iOS: Fork & Integrate Segment React Native SDK #11653
closes: [CDP] RN iOS: Update CIO SDK to utilize Segment#11654

PR Includes :

  • Creating a fork out of segment's react-native package
  • Integrating forked package in customerio-reactnative
  • Adding a CustomerIO dedicated plugin
  • Updating defaults
  • Creating and configuring analytics object
  • Routing all API calls to Segment analytics instead of using native modules

@ami-aman ami-aman requested a review from a team November 21, 2023 12:15
@@ -0,0 +1,120 @@
import { DestinationPlugin } from '../plugin';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the plan to test this file? I don't see automated tests anywhere for it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I do not plan to add test cases as they are out of scope for this ticket. We can create another ticket that takes care of all the test cases.

Copy link

@levibostian levibostian Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a ticket is a good option. Besides creating a ticket, Matt shared an idea with me recently on creating skeleton test functions with // TODO inserted inside of those failing tests.

You decide how you prefer to document this. Whatever method works best for you.

@@ -538,6 +538,24 @@ export class SegmentClient {
await this.process(event);
this.logger.info('TRACK event saved', event);
}
async registerDevice(attributes: JsonMap) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting this logic of register/delete device being implemented as a segment sdk plugin instead of a modification to the code. At first, I like that idea because that would perform less modification to the fork source code. But, open to ideas if this is needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic inside of this function looks to me like it's only creating a tracked event on the segment SDK.

Instead of adding these 2 functions to the segment code, would we do this from the CIO RN SDK code?

class CustomerIO
  registerDevice() {
    segmentClient.trackEvent("Device Created or Updated")
  }
}

Would this also work? I would prefer not having to add code to the Segmet SDK if we dont have to.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with Levi and Shahroz here, I think we should add these method to CIO RN SDK instead of adding to fork.

Comment on lines +542 to +544
const context = this.store.context.get()
const updatedContext = Object.assign({}, context?.device, attributes)
this.store.context.set({ device: updatedContext })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking over this code, it looks like it exists so our SDK can keep track of the device in the SDK's storage.

Assuming this is true, I would prefer if we stored the registered device inside of the CIO SDK code instead of Segment code. Is there a reason that we have to do it in the segment code?

@@ -538,6 +538,24 @@ export class SegmentClient {
await this.process(event);
this.logger.info('TRACK event saved', event);
}
async registerDevice(attributes: JsonMap) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add this in our package rather than Segments

@@ -142,7 +142,7 @@ export type Config = {
maxBatchSize?: number;
trackDeepLinks?: boolean;
defaultSettings?: SegmentAPISettings;
autoAddSegmentDestination?: boolean;
autoAddCustomerIODestination?: boolean;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we didn't plan to expose types directly from segment in our initial proposal, keeping this in mind, I think we don't need to refactor this and can add autoAddCustomerIODestination in our config object if needed.

@@ -538,6 +538,24 @@ export class SegmentClient {
await this.process(event);
this.logger.info('TRACK event saved', event);
}
async registerDevice(attributes: JsonMap) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with Levi and Shahroz here, I think we should add these method to CIO RN SDK instead of adding to fork.

const MAX_PAYLOAD_SIZE_IN_KB = 500;
export const CUSTOMERIO_DESTINATION_KEY = 'Customer.io Data Pipelines';

export class CustomerioDestination extends DestinationPlugin {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we utilize SegmentDestination here directly? Something like:

export class CustomerioDestination extends SegmentDestination

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we can extend SegmentDestination directly here but it does not help with the the main property that's changed which is SEGMENT_DESTINATION_KEY. The property key of the class SegmentDestination can be changed that's consuming the global property SEGMENT_DESTINATION_KEY but the other instance where SEGMENT_DESTINATION_KEY is being used will continue using it. Does this make sense? We can hop on a quick call to talk in detail if that helps.

this.add({ plugin: segmentDestination });
if (this.config.autoAddCustomerIODestination === true) {
const customerioDestination = new CustomerioDestination();
this.add({ plugin: customerioDestination });
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea. When setting up analytics object in our RN SDK, we can set autoAddSegmentDestination to false and add our destination like this:

analytics.add({ plugin: new CustomerioDestination() });

This can help us minimize the changes required in fork.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/core/src/constants.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants