1

I'm using window.navigator.share({url}) . This makes it share the same url to all apps in the device.

Is it possible to add specific query parameter(I want to add utm parameters) for each app?

For example, if the user selected WhatsApp to share, then I can add the parameter ?utm_source=Whatsapp to the URL.

Mahesh Bansod
  • 1,493
  • 2
  • 24
  • 42

1 Answers1

0

You can use the URLSearchParams interface.

let url = new URL('https://example.com/some/path?foo=1&bar=2');
let params = new URLSearchParams(url.search.slice(1));

params.set('utm', 'whatsapp')

// params.toString() : "foo=1&bar=2&utm=whatsapp"
url.search = params.toString()

console.log(url.href)
// "https://example.com/some/path?foo=1&bar=2&utm=whatsapp"
Dan Nagle
  • 4,384
  • 1
  • 16
  • 28
  • Adding the parameter to the URL isn't the problem here. What I want is a way to identify whether I should add the parameter value `whatsapp` or whether I want to add the parameter value `telegram` for the key `utm` . So, essentially, I want to know which app a user selects in the drawer that opens on `window.navigator.share({url})` – Mahesh Bansod Sep 06 '21 at 10:07
  • The `navigator.share()` method returns an empty promise if it's successful or an exception on failure. – Dan Nagle Sep 06 '21 at 15:25