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(2184): modify dapp visited event in terms of isFirstVisited #23659

Merged
merged 1 commit into from
Mar 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,20 @@ async function requestEthereumAccountsHandler(
res.result = accounts;
const numberOfConnectedAccounts =
getPermissionsForOrigin(origin).eth_accounts.caveats[0].value.length;
// first time connection to dapp will lead to no log in the permissionHistory
// and if user has connected to dapp before, the dapp origin will be included in the permissionHistory state
// we will leverage that to identify `is_first_visit` for metrics
const isFirstVisit = !Object.keys(metamaskState.permissionHistory).includes(
origin,
);
sendMetrics({
event: MetaMetricsEventName.DappViewed,
category: MetaMetricsEventCategory.InpageProvider,
referrer: {
url: origin,
},
properties: {
is_first_visit: true,
is_first_visit: isFirstVisit,
number_of_accounts: Object.keys(metamaskState.accounts).length,
number_of_accounts_connected: numberOfConnectedAccounts,
},
Expand Down
71 changes: 71 additions & 0 deletions test/e2e/tests/metrics/dapp-viewed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
openDapp,
waitForAccountRendered,
WINDOW_TITLES,
DAPP_URL,
} = require('../../helpers');
const FixtureBuilder = require('../../fixture-builder');
const {
Expand Down Expand Up @@ -271,4 +272,74 @@ describe('Dapp viewed Event @no-mmi', function () {
},
);
});

it('is sent when reconnect to a dapp that has been connected before', async function () {
async function mockSegment(mockServer) {
return [
await mockedDappViewedEndpoint(mockServer),
await mockedDappViewedEndpoint(mockServer),
];
}

await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
participateInMetaMetrics: true,
})
.build(),
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await driver.navigate();
await unlockWallet(driver);
await waitForAccountRendered(driver);
await connectToDapp(driver);
await waitForDappConnected(driver);

// close test dapp window to avoid future confusion
const windowHandles = await driver.getAllWindowHandles();
await driver.closeWindowHandle(windowHandles[1]);
// disconnect dapp in fullscreen view
await driver.switchToWindowWithTitle(
WINDOW_TITLES.ExtensionInFullScreenView,
);
await driver.clickElement(
'[data-testid ="account-options-menu-button"]',
);
await driver.clickElement({ text: 'Connected sites', tag: 'div' });
await driver.findElement({
text: DAPP_URL,
tag: 'bdi',
});
await driver.clickElement({ text: 'Disconnect', tag: 'a' });
await driver.clickElement({
text: `Disconnect ${DAPP_URL}`,
tag: 'h2',
});
await driver.clickElement({ text: 'Disconnect', tag: 'button' });
// validate dapp is not connected
await driver.clickElement(
'[data-testid ="account-options-menu-button"]',
);
await driver.clickElement({ text: 'Connected sites', tag: 'div' });
await driver.findElement({
text: 'Account 1 is not connected to any sites.',
tag: 'p',
});
// reconnect again
await connectToDapp(driver);
const events = await getEventPayloads(driver, mockedEndpoints);
assert.equal(events.length, 2);
// events are original dapp viewed, new dapp viewed when reconnected
const dappViewedEventProperties = events[1].properties;
assert.equal(dappViewedEventProperties.is_first_visit, false);
assert.equal(dappViewedEventProperties.number_of_accounts, 1);
assert.equal(dappViewedEventProperties.number_of_accounts_connected, 1);
},
);
});
});
Loading