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

Batch Cordova 6.0 #37

Merged
merged 25 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fde2cf3
all: bump cordova version
Aug 1, 2024
1758b9c
plugin: bump batch sdk to 2.0
Aug 2, 2024
5da0200
bridge: migrate apis to batch sdk v2
Aug 6, 2024
afb0a4d
ios: add profile bridge class
Aug 6, 2024
831240e
ios: fix bridge nilable values
Aug 6, 2024
400c82c
profile: rename user data editor into profile attribute editor
Aug 6, 2024
69ab6e6
profile: trackEvent returns promise with potential validation errors
Aug 6, 2024
04f843e
ios: remove legacy handleUrl
Aug 7, 2024
8d3382b
profile: renamed user data operation into profile attribute operation
Aug 7, 2024
67a9dd1
bridge: add identify api
Aug 7, 2024
fac8e5f
ios: add helper method to get nullable string
Aug 7, 2024
813eee1
bridge: add isOptedOut api
Aug 7, 2024
34393ee
bridge: add setFindMyInstallation api
Aug 8, 2024
47d9a73
bridge: add clearInstallationData api
Aug 8, 2024
1de3eb7
bridge: add updateAutomaticDataCollection api
Aug 8, 2024
d17c6c8
bridge: add profile migration configuration setup
Aug 9, 2024
e437d17
all: eslint fix
Aug 9, 2024
970b9a7
all: update changelog
Aug 14, 2024
064e0e6
android: avoid trying to start batch from onNewIntent
Aug 14, 2024
aec76ed
tests: update plugin tests
Aug 14, 2024
aaa18d4
android: fix direct opens not tracked in cold start
arnaud-roland Sep 4, 2024
4e13daf
all: update changelog
arnaud-roland Sep 4, 2024
f2cad91
profile: prevent undefined identifier on identify
arnaud-roland Sep 4, 2024
af9bb81
profile: rename eventData to eventAttributes
arnaud-roland Sep 4, 2024
dcb72e9
all: bump version
arnaud-roland Sep 6, 2024
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
40 changes: 40 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
Batch Cordova Plugin

## 6.0.0

This is a major release, please see our [migration guide](https://doc.batch.com/cordova/advanced/5x-migration/) for more info on how to update your current Batch implementation.

**Plugin**
* Updated Batch to 2.0. For more information see the [ios](https://doc.batch.com/ios/sdk-changelog/#2_0_0) and [android](https://doc.batch.com/android/sdk-changelog/#2_0_0) changelog .
* Batch requires iOS 13.0 or higher.
* Batch requires a `minSdk` level of 21 or higher.

**Core**
- Added method `isOptedOut` to checks whether Batch has been opted out from or not.
- Added method `setFindMyInstallationEnabled` to set whether Batch should enable the FindMyInstallation feature or not.
- Added method `updateAutomaticDataCollection` to fine-tune the data you authorize to be tracked by Batch.
- Removed `canUseAdvertisingIdentifier` property from `Config`.
- Added `migrations` property to `Config` to update the profile migrations related configuration. See our documentation for info.

**User**
- Removed method `trackTransaction` with no equivalent.
- Removed method `batch.user.editor` and the related class `BatchUserDataEditor`, you should now use `batch.profile.editor` which return an instance of `BatchProfileAttributeEditor`.
- Added method `clearInstallationData` which allows you to remove the installation data without modifying the current profile.

**Event**

This version introduced two new types of attribute that can be attached to an event : Array and Object.

- Removed `trackEvent` APIs from the user module. You should now use `batch.profile.trackEvent`.
- `BatchEventData` has been renamed into `BatchEventAttributes`.
- Removed `addTag` API from `BatchEventData` You should now use the `$tags` key with `put` method.
- Removed parameter `label` from `trackEvent` API. You should now use the `$label` key in `BatchEventAttributes` with the `put` method.
- Added support for values of type: Array and Object to the `put` method.

**Profile**

Introduced `batch.profile`, a new module that enables interacting with profiles. Its functionality replaces most of BatchUser used to do.

- Added `identify` API as replacement of `batch.user.getEditor().setIdentifier`.
- Added `getEditor` method to get a new instance of a `BatchProfileAttributeEditor` as replacement of `BatchUserEditor`.
- Added `trackEvent` API as replacement of the `batch.user.trackEvent` methods.
- Added `trackLocation` API as replacement of the `batch.user.trackLocation` method.

## 5.4.0

**Plugin**
Expand Down
148 changes: 148 additions & 0 deletions __tests__/profileAttributeTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import {ProfileAttributeOperation, Profile} from "../src/actions";

const mockSendToBridge = jest.fn();

jest.doMock("../src/helpers", () => {
const helpers = jest.requireActual("../src/helpers");
// tslint:disable-next-line:only-arrow-functions
return {
...helpers,
sendToBridge: mockSendToBridge,
};
});

import { BatchProfileAttributeEditor } from "../src/modules/profile/profileAttributeEditor";

beforeAll(() => {
mockSendToBridge.mockClear();
});

describe("it enqueues operations correctly", () => {
const editor = new BatchProfileAttributeEditor(true);
const enqueueMock = jest.fn();
(editor as any)._enqueueOperation = enqueueMock;

const oldConsoleLog = console.log;

beforeAll(() => {
console.log = jest.fn();
});

afterAll(() => {
console.log = oldConsoleLog;
});

beforeEach(() => {
enqueueMock.mockClear();
});

it("can set language", () => {
editor.setLanguage("en");
(editor as any).setLanguage(2);
editor.setLanguage(null);

expect(enqueueMock.mock.calls.length).toBe(2);
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetLanguage, {
value: "en",
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetLanguage, {
value: null,
});
});

it("can set region", () => {
editor.setRegion("en");
(editor as any).setRegion(2);
editor.setRegion(null);

expect(enqueueMock.mock.calls.length).toBe(2);
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetRegion, {
value: "en",
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetRegion, {
value: null,
});
});

it("can set attribute", () => {
editor.setAttribute("foo", "bar");
editor.setAttribute("foo", 2);
editor.setAttribute("foo", 2.5);
editor.setAttribute("foo", true);
editor.setAttribute("foo", new Date(1520352788000));
editor.setAttribute("foo", new URL("https://batch.com"));
editor.setAttribute("foo", ["bar", "baz"]);
editor.setAttribute("foo", NaN);
(editor as any).setAttribute(null, null);
(editor as any).setAttribute("foo", null);

expect(enqueueMock.mock.calls.length).toBe(7);
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetAttribute, {
key: "foo",
type: "string",
value: "bar",
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetAttribute, {
key: "foo",
type: "integer",
value: 2,
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetAttribute, {
key: "foo",
type: "float",
value: 2.5,
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetAttribute, {
key: "foo",
type: "boolean",
value: true,
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetAttribute, {
key: "foo",
type: "date",
value: 1520352788000,
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetAttribute, {
key: "foo",
type: "url",
value: "https://batch.com/",
});
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.SetAttribute, {
key: "foo",
type: "array",
value: ["bar", "baz"],
});
});

it("can remove attribute", () => {
editor.removeAttribute("foo");
(editor as any).removeAttribute(null);

expect(enqueueMock.mock.calls.length).toBe(1);
expect(enqueueMock).toBeCalledWith(ProfileAttributeOperation.RemoveAttribute, {
key: "foo",
});
});
});

test("can save operations", () => {
new BatchProfileAttributeEditor(true)
.setAttribute("foo", "bar")
.setAttribute("foo2", ["bar"])
.save();

expect(mockSendToBridge.mock.calls.length).toBe(1);
expect(mockSendToBridge).toBeCalledWith(null, Profile.Edit, [
{
operations: [
{
key: "foo",
operation: ProfileAttributeOperation.SetAttribute,
type: "string",
value: "bar",
},
{ operation: ProfileAttributeOperation.SetAttribute, type: "array", key: "foo2", value: ["bar"] },
],
},
]);
});
Loading
Loading