Skip to content

Commit

Permalink
Merge pull request #5102 from HSLdevcom/DT-6400
Browse files Browse the repository at this point in the history
DT-6400 analytics for scooters
  • Loading branch information
vesameskanen authored Sep 30, 2024
2 parents defbbb0 + e14a6c7 commit aade6c4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/component/itinerary/BicycleLeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ export default function BicycleLeg(
<div
role="button"
tabIndex="0"
onClick={() => openSettings(true)}
onClick={() => openSettings(true, true)}
onKeyPress={e =>
isKeyboardSelectionEvent(e) && openSettings(true)
isKeyboardSelectionEvent(e) && openSettings(true, true)
}
className="itinerary-transit-leg-route-bike"
>
Expand Down
15 changes: 14 additions & 1 deletion app/component/itinerary/ItineraryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ export default function ItineraryPage(props, context) {
router.replace(newLocationState);
};

const showSettingsPanel = open => {
const showSettingsPanel = (open, changeScooterSettings) => {
addAnalyticsEvent({
event: 'sendMatomoEvent',
category: 'ItinerarySettings',
Expand All @@ -885,6 +885,7 @@ export default function ItineraryPage(props, context) {
...settingsState,
settingsOpen: true,
settingsOnOpen: getSettings(config),
changeScooterSettings,
});
if (breakpoint !== 'large') {
router.push({
Expand All @@ -897,6 +898,17 @@ export default function ItineraryPage(props, context) {
}
return;
}
if (
settingsState.changeScooterSettings &&
settingsState.settingsOnOpen.scooterNetworks.length <
getSettings(config).scooterNetworks.length
) {
addAnalyticsEvent({
category: 'ItinerarySettings',
action: 'SettingsEnableScooterNetwork',
name: 'AfterOnlyScooterRoutesFound',
});
}

const settingsChanged = !isEqual(
settingsState.settingsOnOpen,
Expand All @@ -908,6 +920,7 @@ export default function ItineraryPage(props, context) {
...settingsState,
settingsOpen: false,
settingsChanged,
changeScooterSettings: false,
});

if (settingsChanged && detailView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const RentalNetworkSelector = (
const newNetworks = updateVehicleNetworks(
getCitybikeNetworks(config),
network.networkName,
network.type,
);
const newSettings = { allowedBikeRentalNetworks: newNetworks };
executeAction(saveRoutingSettings, newSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const ScooterNetworkSelector = (
const newNetworks = updateVehicleNetworks(
getScooterNetworks(config),
network.networkName,
network.type,
);
const newSettings = { scooterNetworks: newNetworks };
executeAction(saveRoutingSettings, newSettings);
Expand Down
37 changes: 17 additions & 20 deletions app/util/vehicleRentalUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,30 @@ const addAnalytics = (action, name) => {
* Updates the list of allowed networks either by removing or adding.
* Note: legacy settings had network names always in uppercase letters.
*
* @param currentSettings the current settings
* @param newValue the network to be added/removed
* @param config The configuration for the software installation
* @param isUsingCitybike if citybike is enabled
* @param networks the previously selected networks
* @param networkName the network to be added/removed
* @param type the type of the network
* @returns the updated citybike networks
*/

export const updateVehicleNetworks = (currentSettings, newValue) => {
let chosenNetworks;
export const updateVehicleNetworks = (networks, networkName, type) => {
let updatedNetworks;
let toggleAction;

if (currentSettings) {
chosenNetworks = currentSettings.find(
o => o.toLowerCase() === newValue.toLowerCase(),
)
? without(currentSettings, newValue, newValue.toUpperCase())
: currentSettings.concat([newValue]);
if (networks.find(o => o.toLowerCase() === networkName.toLowerCase())) {
updatedNetworks = without(networks, networkName, networkName.toUpperCase());
toggleAction = 'Disable';
} else {
chosenNetworks = [newValue];
updatedNetworks = networks.concat([networkName]);
toggleAction = 'Enable';
}

if (Array.isArray(currentSettings) && Array.isArray(chosenNetworks)) {
const action = `Settings${
currentSettings.length > chosenNetworks.length ? 'Disable' : 'Enable'
}CityBikeNetwork`;
addAnalytics(action, newValue);
}
return chosenNetworks;
const action = `Settings${toggleAction}${
type === 'citybike' ? 'CityBikeNetwork' : 'ScooterNetwork'
}`;
addAnalytics(action, networkName);

return updatedNetworks;
};

export const getVehicleMinZoomOnStopsNearYou = (config, override) => {
Expand Down

0 comments on commit aade6c4

Please sign in to comment.