Skip to content

Commit

Permalink
feat: add tracking pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
zeim839 committed Sep 9, 2024
1 parent d0ef6d3 commit e518e98
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import "../global.css"
import React from "react"
import Navbar from './Navbar/Navbar'
import Footer from './Footer/Footer'
import TrackingPixel from './TrackingPixel'

const Layout = (props: { children: any }) => (
<>
<Navbar />
{ props.children }
<Footer />
<TrackingPixel />
</>
)

Expand Down
41 changes: 41 additions & 0 deletions src/components/TrackingPixel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState, useEffect } from "react"
import "../global.css"

const TrackingPixel = () => {
const [trackURI, setTrackURI] = useState<string>("")

// Wraps window.location when available. Window is not defined
// during server rendering/building.
const getWindowLocation = () => {
if (typeof window !== "undefined") {
return window.location.href
}
return null
}

// Initializes pixel tracking URL. It passes the user's screen
// width/height, device memory, and CPU cores to the analytics
// service.
useEffect(() => {
const newURI = "https://tracker-750768004266.us-central1.run.app/track/ufosc.png/" +
`?width=${window.screen.width}` +
`&height=${window.screen.height}` +
`&mem=${navigator.deviceMemory}` +
`&cores=${navigator.hardwareConcurrency}` +
`&src=${window.location}`

if (newURI !== trackURI) {
setTrackURI(newURI)
console.log("changed")
}
}, [getWindowLocation()])

return trackURI !== "" ? (
<img id="trk-pixel"
height={1} width={1}
alt="tracking pixel"
src={trackURI} />
) : null
}

export default TrackingPixel
8 changes: 8 additions & 0 deletions src/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ a, a:link, a:visited {
margin: 20px 0px;
}

#trk-pixel {
position: fixed;
width: 1px;
height: 1px;
top: 0px;
left: 0px;
}

@media only screen and (max-width: 500px) {
.Typewriter__cursor, .Typewriter__wrapper, h1 {
font-size: var(--fontSize-6);
Expand Down

0 comments on commit e518e98

Please sign in to comment.