-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters