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

Track download clicks #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions app/components/InstallExtensionButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ const BrowserIcons = {
const DefaultLink = "https://github.com/getAlby/lightning-browser-extension";

function Install({ style }) {

function trackDownload() {
plausible('Download');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not defined here because of the remix context. need to see how to define a window.plausible function.

Copy link
Contributor

Choose a reason for hiding this comment

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

here's an example where they detect whether they're on the server and set an empty function as a fallback:
https://remix.run/docs/en/v1/guides/constraints#uselayouteffect

Copy link
Contributor

Choose a reason for hiding this comment

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

This example also looks relevant, they fix a localstorage call (which has the same problem as window on the server): https://remix.run/docs/en/v1/guides/constraints#rendering-with-browser-only-apis

}

var parser = new UAParser();
const browser = parser.getBrowser();
function renderIcon() {
Expand All @@ -43,6 +48,7 @@ function Install({ style }) {
<a
href={link}
className="border border-black rounded-full w-32 text-center py-2"
onClick={trackDownload}
>
Install Alby
</a>
Expand All @@ -69,6 +75,7 @@ function Install({ style }) {
return (
<a
href={link}
onClick={trackDownload}
className="bg-white text-black border-[3px] border-solid border-[#333333] font-secondary inline-block text-lg lg:leading-[1.875rem] font-semibold py-2 px-5 rounded-full mt-6"
>
{renderIcon()}
Expand All @@ -80,6 +87,7 @@ function Install({ style }) {
<a
href={DefaultLink}
onClick={() => {
trackDownload();
alert(
`We currently do not yet support ${browser.name}. But maybe you can install it from source.`
);
Expand Down
1 change: 1 addition & 0 deletions app/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function App() {
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<script defer data-domain="getalby.com" src="https://squirrel.getalby.com/js/plausible.js"></script>
<script>window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can not use window here because of remix (rendering things on the server)
I don't know yet how this would be done in the remix context

<Meta />
<Links />
</head>
Expand Down