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

Add Basic Visitor Tracking #1462

Closed

Conversation

MarcusSorealheis
Copy link
Collaborator

@MarcusSorealheis MarcusSorealheis commented Nov 5, 2024

Description

Adds basic visitor tracking. It does lead to a weird server side React warning about useEffect that I could use a tip on. I'm not sure if it was there already. First commit to the rewritten website.


This change is Reviewable

@MarcusSorealheis
Copy link
Collaborator Author

I've found a bug in a closure, one moment.

Copy link
Contributor

@SchahinRohani SchahinRohani left a comment

Choose a reason for hiding this comment

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

We are mainly using the Qwik Framework. We have also enabled react, but we only have one react component on the website.
Qwik might look similar to react with the tsx syntax, but it has another approach than react (resumability vs hydration).
So you need to be aware of....

Reviewed 2 of 2 files at r1, all commit messages.
Reviewable status: 0 of 1 LGTMs obtained, and all files reviewed, and 2 discussions need to be resolved


web/platform/src/components/qwik/components/visitors.tsx line 42 at r1 (raw file):

        }
      }
      ce(`https://sc.lfeeder.com/lftracker_v1_${ss}.js`);

For thirdparty scripts we should use Partytown, since it won't slow down the website performance.
It will use web worker under the hood, so the main thread doesn't get blocked.
For that we don't need a qwik component, since we also use astro as the meta framework for routing.

To integrate partytown in astro you'll need to add the dependency with bun i -D @astrojs/partytown.

Then you need to import it inthe astro.config.ts:

...
import tailwindcss from "@tailwindcss/vite";                                 
import partytown from "@astrojs/partytown";     //  <--- import the dependency                

...
 integrations: [                                        
   ...
   partytown()  // <-- add the dependency as an integration
 ],
...   

web/platform/src/layouts/Layout.astro line 26 at r1 (raw file):

		<title>{title}</title>
    	<ViewTransitions />
		<Visitors />

Let's create a directory for third-party scripts something like src/thirdParty, and inside you can create alfeeder.astro file.

An example for google tag manager would be:

---
type Props = { measurementId: string }
const props = Astro.props as Props
const measurementId = props.measurementId
---
<script
  type='text/partytown'
  src={`https://www.googletagmanager.com/gtag/js?id=${measurementId}`}></script>
<script

Then you could include it in the layout.astro - head like this:

---
import GoogleAnalytics from './GoogleAnalytics.astro'
---
<html lang='en'>
  <head>
    <meta charset='utf-8' />
    <GoogleAnalytics measurementId={'G-XXXXXXXXXX'} />
    <title>My page</title>
    ·

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.

2 participants