Skip to content

Commit

Permalink
📈 Decouple tracking from share button
Browse files Browse the repository at this point in the history
  • Loading branch information
homostellaris committed Apr 26, 2024
1 parent 2de8847 commit a676315
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/lib/Inviter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import {page} from '$app/stores'
import ShareButton from '$lib/ShareButton.svelte'
import {Toast} from 'spaper'
import {getContext} from 'svelte'
const {getAnalytics} = getContext('analytics')
const inviteUrl = new URL('invite', $page.url).href
</script>
Expand All @@ -20,6 +23,9 @@
})
document.getElementById('invite-url').select()
}}
on:click={() => {
getAnalytics().trackEvent()('Share invite link')
}}
/>
</form>

Expand Down
17 changes: 3 additions & 14 deletions src/lib/ShareButton.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<script>
import {Button, Modal, Toast} from 'spaper'
import {getContext} from 'svelte'
import ShareIcon from '$lib/ShareIcon.svelte'
const {getAnalytics} = getContext('analytics')
export let url
export let shareText
export let fallback = () => {
Expand All @@ -21,7 +18,7 @@
text: shareText,
url,
})
trackShareInviteLink('native')
console.debug('native')
} catch (error) {
console.warn('Unable to use native sharing', error)
if (error.name === 'AbortError') return // If we try to fallback to 'copy' after this it results in a NotAllowedErorr. I'm guesing this is because when the user aborts share it resets Safari's concept of if is a valid and safe clipboard operation triggered by a user interaction (see https://webkit.org/blog/10247/new-webkit-features-in-safari-13-1/).
Expand All @@ -33,11 +30,11 @@
type: 'success',
position: 'top',
})
trackShareInviteLink('auto copy with dialog')
console.debug('auto copy with dialog')
} catch (error) {
// One example of when this would happen is in some Android Webviews that don't provide copy permissions.
console.warn('Unable to copy to clipboard', error)
trackShareInviteLink('manual copy with dialog')
console.debug('manual copy with dialog')
fallback()
}
}
Expand All @@ -48,14 +45,6 @@
throw new Error('Navigator clipboard not available')
await navigator.clipboard.writeText(url)
}
function trackShareInviteLink(method) {
getAnalytics().trackEvent('Share invite link', {
props: {
method,
},
})
}
</script>

<Button on:click={share} type="success">
Expand Down
5 changes: 4 additions & 1 deletion src/routes/[socialId=socialId]/decision/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
<Retreat back="everyone" />
<Button
on:click={() => {
getAnalytics().trackEvent('Tapped buy me a beer button')
getAnalytics().trackEvent('Buy me a beer')
}}
href="https://buymeacoffee.com/homostellaris"
isLink
external>Buy the creator a beer 🍻*</Button
>
<ShareButton
on:click={() => {
getAnalytics().trackEvent('Spread the word')
}}
url="https://scheduleyour.social?ref=decision-share"
shareText="The fastest way to find out when your friends are free"
>Spread the word</ShareButton
Expand Down

0 comments on commit a676315

Please sign in to comment.