Skip to content

feat: Get user's geolocation data through Web API's Geolocation - #2728

Merged
lucasfp13 merged 5 commits into
feat/delivery-promisefrom
feat/geolocation-data
Mar 21, 2025
Merged

lucasfp13 merged 5 commits into
feat/delivery-promisefrom
feat/geolocation-data

Conversation

@lucasfp13

@lucasfp13 lucasfp13 commented Mar 17, 2025 •

Copy link
Copy Markdown
Contributor

What's the purpose of this pull request?

This PR adds logic to ask for user's geolocation data consent (by using the getCurrentPosition function), then if granted save it on current session.

It also ensures getting geo coordinates from postal code and country data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

How it works?

First we verify if there is any geoCoordinates data on the current session. If not, we ask for geolocation data consent then, if granted, we update the current session.

How to test it?

  1. Using the RegionModal:
  • Click on Set my location and it will open the RegionModal.
  • Set any USA zip code (the starter store is using the USA locale);
  • After the store reload, check the IndexedDB for geoCoordinates data, it should be there both longitude and latitude.
  1. Through Geolocation consent:
  • Navigate through the main pages (home, PDP and PLP). It should ask for geolocation consent;
  • After granted check the ValidateSession requests (Network tab) or inside the IndexedDB for the session data, geoCoordinates should have latitude and longitude data.

Starters Deploy Preview

vtex-sites/starter.store#720

References

Geolocation Web API: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation

@lucasfp13
lucasfp13 requested a review from hellofanny March 17, 2025 23:19
@lucasfp13 lucasfp13 self-assigned this Mar 17, 2025
@lucasfp13
lucasfp13 requested a review from a team as a code owner March 17, 2025 23:19
@lucasfp13
lucasfp13 requested review from pedromtec and removed request for a team March 17, 2025 23:19
@codesandbox-ci

codesandbox-ci Bot commented Mar 17, 2025 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@eduardoformiga eduardoformiga left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

I left some comments along with the review.

  • Should we wrap some logic under the deliveryPromise -> enabled flag?
  • I imagine we don't have a VTEX API to set the postal code if we have geoCoordinates, right? It would be good to update the postal code in this case.

Comment thread packages/core/src/pages/[...slug].tsx Resolved
@lucasfp13

Copy link
Copy Markdown
Contributor Author
  • I imagine we don't have a VTEX API to set the postal code if we have geoCoordinates, right? It would be good to update the postal code in this case.

Yeah, we don't have it internally. Maybe we look into it on another task

reference?: string
/**
* Address geoCoordinates
* Address geoCoordinates. [longitude, latitude]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Comment thread packages/core/src/pages/index.tsx Resolved
@hellofanny

hellofanny commented Mar 20, 2025 •

Copy link
Copy Markdown
Contributor
  1. Tried using the 07008 the postalCode and worked fine! 🚀
image
  1. Even though I already had the postalCode and geoCordination set the geolocation consent popped up 🤔
image

And I think we might be missing a scenario, can we have the geoCoordinates without setting the postalCode?
image

I think this is the case: If we remove the postalCode, we need to update/reset the geoCoordinates, so we have a consistent postalCode <-> geoCoordinates.

}
)
}
}, [])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This array should not have some dependencies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this consent is called just once because we should not ignore users' deny/dismiss and ask again for consent.
In fact, the Geolocation API itself warns us for that:
Screenshot 2025-03-21 at 11 18 11

@lucasfp13
lucasfp13 merged commit ad9b81c into feat/delivery-promise Mar 21, 2025
@lucasfp13
lucasfp13 deleted the feat/geolocation-data branch March 21, 2025 15:08
hellofanny pushed a commit that referenced this pull request Mar 26, 2025
## What's the purpose of this pull request?

This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

## How it works?

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

## How to test it?

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

### Starters Deploy Preview

vtex-sites/starter.store#720

## References

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota pushed a commit that referenced this pull request Mar 27, 2025
## What's the purpose of this pull request?

This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

## How it works?

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

## How to test it?

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

### Starters Deploy Preview

vtex-sites/starter.store#720

## References

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota pushed a commit that referenced this pull request Mar 28, 2025
## What's the purpose of this pull request?

This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

## How it works?

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

## How to test it?

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

### Starters Deploy Preview

vtex-sites/starter.store#720

## References

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota pushed a commit that referenced this pull request Apr 8, 2025
## What's the purpose of this pull request?

This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

## How it works?

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

## How to test it?

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

### Starters Deploy Preview

vtex-sites/starter.store#720

## References

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota pushed a commit that referenced this pull request Apr 11, 2025
## What's the purpose of this pull request?

This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

## How it works?

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

## How to test it?

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

### Starters Deploy Preview

vtex-sites/starter.store#720

## References

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota pushed a commit that referenced this pull request Apr 22, 2025
This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

vtex-sites/starter.store#720

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota pushed a commit that referenced this pull request May 8, 2025
This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

vtex-sites/starter.store#720

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota pushed a commit that referenced this pull request May 12, 2025
This PR adds logic to ask for user's geolocation data consent (by using
the `getCurrentPosition` function), then if granted save it on current
session.

It also ensures getting geo coordinates from postal code and country
data when validating the current session.

The geo coordinates data will be used by the Delivery Zones API.

First we verify if there is any `geoCoordinates` data on the current
session. If not, we ask for geolocation data consent then, if granted,
we update the current session.

1. Using the `RegionModal`:
  - Click on `Set my location` and it will open the `RegionModal`.
  - Set any USA zip code (the starter store is using the USA locale);
- After the store reload, check the IndexedDB for `geoCoordinates` data,
it should be there both longitude and latitude.

2. Through Geolocation consent:
- Navigate through the main pages (home, PDP and PLP). It should ask for
geolocation consent;
- After granted check the `ValidateSession` requests (Network tab) or
inside the IndexedDB for the `session` data, `geoCoordinates` should
have latitude and longitude data.

vtex-sites/starter.store#720

Geolocation Web API:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
lariciamota added a commit that referenced this pull request May 13, 2025
## What's the purpose of this pull request?

Feature branch for the Delivery Promise feature - phase 1 (navigation
based on shopper location).

- #2708 
- #2728
- #2739 
- #2745 
- #2749
- #2750
- #2768
- #2772 
- #2775
- #2809
- #2817 
- #2824 
- #2835

## How it works?


## How to test it?


### Starters Deploy Preview


## References
- [Jira epic](https://vtex-dev.atlassian.net/browse/SFS-1696)


## Checklist

- [ ] For documentation changes, ping `@Mariana-Caetano` to review and
update (Or submit a doc request)
- [ ] TODO: Request Doc for PopOver
- [ ] TODO: Remind to run cms sync in the default account when the
feature branch is merged since new section was added. (And add the new
section in the admin!)

---------

Co-authored-by: Lucas Feijó <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants