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

fix(adjust-plugin): update for compatibility with Adjust SDK v5 #1048

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
3 changes: 0 additions & 3 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,8 @@ type SegmentAmplitudeIntegration = {
export type SegmentAdjustSettings = {
appToken: string;
setEnvironmentProduction?: boolean;
setEventBufferingEnabled?: boolean;
trackAttributionData?: boolean;
setDelay?: boolean;
customEvents?: { [key: string]: string };
delayTime?: number;
};

export type SegmentBrazeSettings = {
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/plugin-adjust/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
},
"homepage": "https://github.com/segmentio/analytics-react-native/tree/master/packages/plugins/plugin-adjust#readme",
"peerDependencies": {
"@segment/analytics-react-native": "^2.18.0",
"react-native-adjust": "^4.33.0"
"@segment/analytics-react-native": "^2.20.3",
"react-native-adjust": "^5.0.4"
},
"devDependencies": {
"@segment/analytics-react-native": "^2.18.0",
"@segment/analytics-react-native": "^2.20.3",
"@segment/analytics-rn-shared": "workspace:^",
"@segment/sovran-react-native": "^1.1.0",
"jest": "^29.7.0",
"react-native-adjust": "^4.33.0",
"react-native-adjust": "^5.0.4",
"react-native-builder-bob": "^0.23.1",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
Expand Down
17 changes: 2 additions & 15 deletions packages/plugins/plugin-adjust/src/AdjustPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AdjustPlugin extends DestinationPlugin {
const adjustConfig = new AdjustConfig(this.settings.appToken, environment);

if (this.hasRegisteredCallback === false) {
adjustConfig.setAttributionCallbackListener((attribution) => {
adjustConfig.setAttributionCallback((attribution) => {
const trackPayload = {
provider: 'Adjust',
trackerToken: attribution.trackerToken,
Expand All @@ -56,20 +56,7 @@ export class AdjustPlugin extends DestinationPlugin {
this.hasRegisteredCallback = true;
}

const bufferingEnabled = this.settings.setEventBufferingEnabled;
if (bufferingEnabled === true) {
adjustConfig.setEventBufferingEnabled(bufferingEnabled);
}

const useDelay = this.settings.setDelay;
if (useDelay === true) {
const delayTime = this.settings.delayTime;
if (delayTime !== null && delayTime !== undefined) {
adjustConfig.setDelayStart(delayTime);
}
}

Adjust.create(adjustConfig);
Adjust.initSdk(adjustConfig);
}
identify(event: IdentifyEventType) {
identify(event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export const resetSessionPartnerParameters = jest.fn();
export const addSessionPartnerParameter = jest.fn();
export const removeGlobalPartnerParameters = jest.fn();
export const addGlobalPartnerParameter = jest.fn();
export const trackEvent = jest.fn();

export const Adjust = {
resetSessionPartnerParameters,
addSessionPartnerParameter,
removeGlobalPartnerParameters,
addGlobalPartnerParameter,
trackEvent,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import identify from '../identify';
import type { IdentifyEventType } from '@segment/analytics-react-native';
import { addSessionPartnerParameter } from '../__mocks__/react-native-adjust';
import { addGlobalPartnerParameter } from '../__mocks__/react-native-adjust';

describe('#identify', () => {
beforeEach(() => {
Expand All @@ -15,7 +15,7 @@ describe('#identify', () => {

identify(payload as IdentifyEventType);

expect(addSessionPartnerParameter).toHaveBeenCalledWith('user_id', 'user');
expect(addGlobalPartnerParameter).toHaveBeenCalledWith('user_id', 'user');
});

it('sets the anonymous_id', () => {
Expand All @@ -26,7 +26,7 @@ describe('#identify', () => {

identify(payload as IdentifyEventType);

expect(addSessionPartnerParameter).toHaveBeenCalledWith(
expect(addGlobalPartnerParameter).toHaveBeenCalledWith(
'anonymous_id',
'anon'
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import reset from '../reset';
import { resetSessionPartnerParameters } from '../__mocks__/react-native-adjust';
import { removeGlobalPartnerParameters } from '../__mocks__/react-native-adjust';

describe('#reset', () => {
beforeEach(() => {
Expand All @@ -9,7 +9,7 @@ describe('#reset', () => {
it('calls resetSessionPartnerParameters', () => {
reset();

expect(resetSessionPartnerParameters).toHaveBeenCalledTimes(1);
expect(resetSessionPartnerParameters).toHaveBeenCalledWith();
expect(removeGlobalPartnerParameters).toHaveBeenCalledTimes(1);
expect(removeGlobalPartnerParameters).toHaveBeenCalledWith();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('#track', () => {

track(event as TrackEventType, settings);

expect(Adjust.addSessionPartnerParameter).toHaveBeenCalledWith(
expect(Adjust.addGlobalPartnerParameter).toHaveBeenCalledWith(
'anonymous_id',
'anon'
);
Expand All @@ -54,7 +54,7 @@ describe('#track', () => {

track(event as TrackEventType, settings);

expect(Adjust.addSessionPartnerParameter).toHaveBeenCalledWith(
expect(Adjust.addGlobalPartnerParameter).toHaveBeenCalledWith(
'anonymous_id',
'anon'
);
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('#track', () => {

track(event as TrackEventType, settings);

expect(Adjust.addSessionPartnerParameter).toHaveBeenCalledWith(
expect(Adjust.addGlobalPartnerParameter).toHaveBeenCalledWith(
'anonymous_id',
'anon'
);
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('#track', () => {

track(event as TrackEventType, settings);

expect(Adjust.addSessionPartnerParameter).toHaveBeenCalledWith(
expect(Adjust.addGlobalPartnerParameter).toHaveBeenCalledWith(
'anonymous_id',
'anon'
);
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/plugin-adjust/src/methods/identify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { IdentifyEventType } from '@segment/analytics-react-native';
export default (event: IdentifyEventType) => {
const userId = event.userId;
if (userId !== undefined && userId !== null && userId.length > 0) {
Adjust.addSessionPartnerParameter('user_id', userId);
Adjust.addGlobalPartnerParameter('user_id', userId);
}

const anonId = event.anonymousId;
if (anonId !== undefined && anonId !== null && anonId.length > 0) {
Adjust.addSessionPartnerParameter('anonymous_id', anonId);
Adjust.addGlobalPartnerParameter('anonymous_id', anonId);
}
};
2 changes: 1 addition & 1 deletion packages/plugins/plugin-adjust/src/methods/reset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Adjust } from 'react-native-adjust';

export default () => {
Adjust.resetSessionPartnerParameters();
Adjust.removeGlobalPartnerParameters();
};
2 changes: 1 addition & 1 deletion packages/plugins/plugin-adjust/src/methods/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { extract, mappedCustomEventToken } from '../util';
export default (event: TrackEventType, settings: SegmentAdjustSettings) => {
const anonId = event.anonymousId;
if (anonId !== undefined && anonId !== null && anonId.length > 0) {
Adjust.addSessionPartnerParameter('anonymous_id', anonId);
Adjust.addGlobalPartnerParameter('anonymous_id', anonId);
}

const token = mappedCustomEventToken(event.event, settings);
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3346,17 +3346,17 @@ __metadata:
version: 0.0.0-use.local
resolution: "@segment/analytics-react-native-plugin-adjust@workspace:packages/plugins/plugin-adjust"
dependencies:
"@segment/analytics-react-native": "npm:^2.18.0"
"@segment/analytics-react-native": "npm:^2.20.3"
"@segment/analytics-rn-shared": "workspace:^"
"@segment/sovran-react-native": "npm:^1.1.0"
jest: "npm:^29.7.0"
react-native-adjust: "npm:^4.33.0"
react-native-adjust: "npm:^5.0.4"
react-native-builder-bob: "npm:^0.23.1"
rimraf: "npm:^5.0.5"
typescript: "npm:^5.2.2"
peerDependencies:
"@segment/analytics-react-native": ^2.18.0
react-native-adjust: ^4.33.0
"@segment/analytics-react-native": ^2.20.3
react-native-adjust: ^5.0.4
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -3615,7 +3615,7 @@ __metadata:
languageName: unknown
linkType: soft

"@segment/analytics-react-native@npm:^2.18.0, @segment/analytics-react-native@workspace:packages/core":
"@segment/analytics-react-native@npm:^2.18.0, @segment/analytics-react-native@npm:^2.20.3, @segment/analytics-react-native@workspace:packages/core":
version: 0.0.0-use.local
resolution: "@segment/analytics-react-native@workspace:packages/core"
dependencies:
Expand Down Expand Up @@ -13096,10 +13096,10 @@ __metadata:
languageName: node
linkType: hard

"react-native-adjust@npm:^4.33.0":
version: 4.37.1
resolution: "react-native-adjust@npm:4.37.1"
checksum: 10c0/463ddb7284bebe7a88d969e0a2dc4a84e039216f016d764ad916078b0fac060ba4cf275ac84d7e32c0b020632c2d9755791603118ee9cee84cba8336e94ca18b
"react-native-adjust@npm:^5.0.4":
version: 5.0.4
resolution: "react-native-adjust@npm:5.0.4"
checksum: 10c0/8df9e475e48c11b493b873d585407e7747c8858923d808108e98080b77afd3b6502496875bc98f9eaadf86004d93001df67a7d75394bae870bcd219f3ef2d3e3
languageName: node
linkType: hard

Expand Down