-
Notifications
You must be signed in to change notification settings - Fork 11
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
7 changed files
with
68 additions
and
94 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,17 @@ | ||
// create a pixel Component that will be used to track page views | ||
// /api/public/weaverse-pixel?projectId=xxx&pageId=xxx | ||
// The pixel will be removed from the DOM after it is loaded | ||
|
||
import { memo } from 'react' | ||
|
||
import type { WeaverseHydrogen } from './index' | ||
import { useStudio } from '~/hooks/use-studio' | ||
import { usePixel } from '~/hooks/use-pixel' | ||
|
||
export let WeaverseEffect = memo( | ||
({ context }: { context: WeaverseHydrogen }) => { | ||
useStudio(context) | ||
usePixel(context) | ||
return null | ||
}, | ||
) |
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,21 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
import type {WeaverseHydrogen} from '~/index' | ||
import {useEffect} from 'react' | ||
import {useLocation} from '@remix-run/react' | ||
let fetchingKey = '' | ||
export let usePixel = (context: WeaverseHydrogen) => { | ||
// TODO: create a post xhr request to the pixel endpoint | ||
let { projectId, pageId, weaverseHost, isDesignMode } = context | ||
const location = useLocation(); | ||
useEffect(() => { | ||
if (isDesignMode || !projectId || !pageId || !weaverseHost) return | ||
let currentKey = `${projectId}-${pageId}-${location.pathname}` | ||
if (fetchingKey === currentKey) return | ||
fetchingKey = currentKey | ||
let url = `${weaverseHost}/api/public/px` | ||
let xhr = new XMLHttpRequest() | ||
xhr.open('POST', url, true) | ||
xhr.setRequestHeader('Content-Type', 'application/json') | ||
xhr.send(JSON.stringify({ projectId, pageId })) | ||
}, [location]) | ||
} |
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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.