Skip to content

Commit

Permalink
Fix server side tracking for Remix actions (#124)
Browse files Browse the repository at this point in the history
* Move env variables reading into track

This fixes remix bundling issues leaking process into the client

* Upgrade dependencies

* Add analytics component

* Update package.json
  • Loading branch information
tobiaslins committed Jan 18, 2024
1 parent ab1213b commit c07d4b2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 53 deletions.
2 changes: 2 additions & 0 deletions apps/remix/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { Analytics } from "@vercel/analytics/react";

export default function App() {
return (
Expand All @@ -15,6 +16,7 @@ export default function App() {
<Links />
</head>
<body>
<Analytics />
<Outlet />
<ScrollRestoration />
<Scripts />
Expand Down
10 changes: 5 additions & 5 deletions apps/remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
},
"prettier": {},
"dependencies": {
"@remix-run/node": "^2.0.1",
"@remix-run/react": "^2.0.1",
"@remix-run/serve": "^2.0.1",
"@remix-run/server-runtime": "^2.0.1",
"@remix-run/node": "^2.5.0",
"@remix-run/react": "^2.5.0",
"@remix-run/serve": "^2.5.0",
"@remix-run/server-runtime": "^2.5.0",
"@vercel/analytics": "workspace:*",
"@vercel/remix": "2.0.1",
"@vercel/remix": "2.5.0",
"isbot": "^3.6.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vercel/analytics",
"version": "1.1.1",
"version": "1.1.2",
"description": "Gain real-time traffic insights with Vercel Web Analytics",
"keywords": [
"analytics",
Expand Down
5 changes: 2 additions & 3 deletions packages/web/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import type { AllowedPropertyValues } from '../types';
import { isProduction, parseProperties } from '../utils';

const ENDPOINT = process.env.VERCEL_URL || process.env.VERCEL_ANALYTICS_URL;
const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);

type HeadersObject = Record<string, string | string[] | undefined>;
type AllowedHeaders = Headers | HeadersObject;

Expand Down Expand Up @@ -38,6 +35,8 @@ export async function track(
properties?: Record<string, AllowedPropertyValues>,
context?: Context
): Promise<void> {
const ENDPOINT = process.env.VERCEL_URL || process.env.VERCEL_ANALYTICS_URL;
const DISABLE_LOGS = Boolean(process.env.VERCEL_WEB_ANALYTICS_DISABLE_LOGS);
if (typeof window !== 'undefined') {
if (!isProduction()) {
throw new Error(
Expand Down

1 comment on commit c07d4b2

@vercel
Copy link

@vercel vercel bot commented on c07d4b2 Jan 18, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

analytics-remix – ./apps/remix

analytics-remix-vercel-analytics.vercel.app
analytics-remix-git-main-vercel-analytics.vercel.app
analytics-remix.vercel.app

Please sign in to comment.