Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions dist/types/src/kitBlocking.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default class KitBlocker {
LaunchReferral?: string;
ExpandedEventCount: number;
ActiveTimeOnSite: number;
PageUrl?: string;
Comment thread
alexs-mparticle marked this conversation as resolved.
Outdated
IsBackgroundAST?: boolean;
AlreadySentToForwarders?: boolean;
};
Expand Down Expand Up @@ -110,6 +111,7 @@ export default class KitBlocker {
LaunchReferral?: string;
ExpandedEventCount: number;
ActiveTimeOnSite: number;
PageUrl?: string;
IsBackgroundAST?: boolean;
AlreadySentToForwarders?: boolean;
};
Expand Down
1 change: 1 addition & 0 deletions dist/types/src/sdkRuntimeModels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface SDKEvent {
LaunchReferral?: string;
ExpandedEventCount: number;
ActiveTimeOnSite: number;
PageUrl?: string;
IsBackgroundAST?: boolean;
AlreadySentToForwarders?: boolean;
}
Expand Down
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@babel/preset-env": "^7.6.0",
"@babel/preset-typescript": "^7.6.0",
"@mparticle/data-planning-models": "^0.1.0",
"@mparticle/event-models": "^1.1.9",
"@mparticle/event-models": "^1.3.0",
Comment thread
alexs-mparticle marked this conversation as resolved.
"@rollup/plugin-babel": "6.0.3",
"@rollup/plugin-commonjs": "25.0.4",
"@rollup/plugin-json": "^5.0.2",
Expand Down Expand Up @@ -159,7 +159,7 @@
"webpack-cli": "^5.0.2"
},
"peerDependencies": {
"@mparticle/event-models": "^1.1.9"
"@mparticle/event-models": "^1.3.0"
},
"dependencies": {
"@babel/runtime": "^7.23.2"
Expand Down
1 change: 1 addition & 0 deletions src/sdkRuntimeModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface SDKEvent {
LaunchReferral?: string;
ExpandedEventCount: number;
ActiveTimeOnSite: number;
PageUrl?: string;
IsBackgroundAST?: boolean;
AlreadySentToForwarders?: boolean;
}
Expand Down
3 changes: 2 additions & 1 deletion src/sdkToEventsApiConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,8 @@ export function convertBaseEventData(
custom_attributes: sdkEvent.EventAttributes,
location: convertSDKLocation(sdkEvent.Location),
source_message_id: sdkEvent.SourceMessageId,
active_time_on_site_ms: sdkEvent.ActiveTimeOnSite
active_time_on_site_ms: sdkEvent.ActiveTimeOnSite,
page_url: sdkEvent.PageUrl,
};

return commonEventData;
Expand Down
1 change: 1 addition & 0 deletions src/serverModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
event.name
),
ActiveTimeOnSite: mpInstance._timeOnSiteTimer?.getTimeInForeground(),
PageUrl: window.location.href || null,

Check warning on line 313 in src/serverModel.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZ6DW7K49ids8AwLfwuO&open=AZ6DW7K49ids8AwLfwuO&pullRequest=1276
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
Comment thread
khushi1033 marked this conversation as resolved.
Outdated
Comment thread
alexs-mparticle marked this conversation as resolved.
Outdated
SourceMessageId:
event.sourceMessageId ||
mpInstance._Helpers.generateUniqueId(),
Expand Down
80 changes: 80 additions & 0 deletions test/src/tests-runtimeToBatchEventsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,84 @@
// set screen back on
window.screen = originalScreen;
});

it('propagates PageUrl to page_url on the converted event', () => {
const sdkEvent: SDKEvent = {
EventName: 'Page View',
EventCategory: Types.EventType.Navigation,
ExpandedEventCount: 0,
EventDataType: Types.MessageType.PageEvent,
EventAttributes: null,
ConsentState: null,
CurrencyCode: null,
CustomFlags: {},
DataPlan: {},
Debug: true,
DeviceId: '0edd580e-d887-44e4-89ae-cd65aa0ee933',
Location: null,
MPID: '-8433569646818451201',
OptOut: null,
SDKVersion: '2.11.15',
SourceMessageId: 'testSMID',
SessionId: '64102C03-592F-440D-8BCC-1D27AAA6B188',
SessionStartDate: 1603211322698,
Timestamp: 1603212299414,
ActiveTimeOnSite: 10,
PageUrl: 'https://example.com/checkout?utm=should-be-stripped-server-side',
UserAttributes: {},
UserIdentities: [],
IsFirstRun: true,
};

const batch = Converter.convertEvents(
'-8433569646818451201',
[sdkEvent],
window.mParticle.getInstance()

Check warning on line 545 in test/src/tests-runtimeToBatchEventsDTO.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZ6DW7Xm9ids8AwLfwuQ&open=AZ6DW7Xm9ids8AwLfwuQ&pullRequest=1276
);

expect(batch).to.be.ok;
expect(batch.events.length).to.equal(1);
const event = batch.events[0] as EventsApi.CustomEvent;
expect(event.data.page_url).to.equal(
'https://example.com/checkout?utm=should-be-stripped-server-side'
);
});

it('omits page_url when PageUrl is not set on the SDK event', () => {
const sdkEvent: SDKEvent = {
EventName: 'Page View',
EventCategory: Types.EventType.Navigation,
ExpandedEventCount: 0,
EventDataType: Types.MessageType.PageEvent,
EventAttributes: null,
ConsentState: null,
CurrencyCode: null,
CustomFlags: {},
DataPlan: {},
Debug: true,
DeviceId: '0edd580e-d887-44e4-89ae-cd65aa0ee933',
Location: null,
MPID: '-8433569646818451201',
OptOut: null,
SDKVersion: '2.11.15',
SourceMessageId: 'testSMID',
SessionId: '64102C03-592F-440D-8BCC-1D27AAA6B188',
SessionStartDate: 1603211322698,
Timestamp: 1603212299414,
ActiveTimeOnSite: 10,
UserAttributes: {},
UserIdentities: [],
IsFirstRun: true,
};

const batch = Converter.convertEvents(
'-8433569646818451201',
[sdkEvent],
window.mParticle.getInstance()

Check warning on line 586 in test/src/tests-runtimeToBatchEventsDTO.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZ6DW7Xm9ids8AwLfwuR&open=AZ6DW7Xm9ids8AwLfwuR&pullRequest=1276
);

expect(batch).to.be.ok;
const event = batch.events[0] as EventsApi.CustomEvent;
expect(event.data.page_url).to.equal(undefined);
});
});
19 changes: 19 additions & 0 deletions test/src/tests-serverModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,25 @@
);
});

it('should capture window.location.href as PageUrl', () => {
const event: BaseEvent = {
name: 'Test Event',
messageType: Types.MessageType.PageEvent,
eventType: Types.EventType.Navigation,
data: { foo: 'bar' },
sourceMessageId: 'test-source-message-id',
customFlags: {},
};

const actualEventObject = mParticle
.getInstance()
._ServerModel.createEventObject(event) as IUploadObject;

expect(actualEventObject.PageUrl, 'PageUrl').to.equal(
window.location.href

Check warning on line 315 in test/src/tests-serverModel.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer `globalThis` over `window`.

See more on https://sonarcloud.io/project/issues?id=mParticle_mparticle-web-sdk&issues=AZ6DW7V_9ids8AwLfwuP&open=AZ6DW7V_9ids8AwLfwuP&pullRequest=1276
);
});

it('should create an event object with a user', () => {
const event: BaseEvent = {
name: 'Test Event',
Expand Down
Loading