Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d0a94d288 | |||
| 3568c13941 | |||
| d538d7b9ec | |||
| 8c08b552cf | |||
| 1dd74a3861 | |||
| 8d77ca45f7 | |||
| c646815a3a |
@@ -10,17 +10,31 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
run_install: false
|
run_install: false
|
||||||
|
|
||||||
|
- name: Get pnpm store directory
|
||||||
|
id: pnpm-cache
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Setup pnpm cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
||||||
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pnpm-store-
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
|
|
||||||
- name: 🔐 Configure Private Registry
|
- name: 🔐 Configure Private Registry
|
||||||
run: |
|
run: |
|
||||||
REGISTRY="${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}"
|
REGISTRY="${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}"
|
||||||
|
|||||||
@@ -154,14 +154,26 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
|
- name: Get pnpm store directory
|
||||||
|
id: pnpm-cache
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
|
||||||
|
- name: Setup pnpm cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
||||||
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pnpm-store-
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
- name: 🔐 Registry Auth
|
- name: 🔐 Registry Auth
|
||||||
run: |
|
run: |
|
||||||
echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
|
echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
|
||||||
@@ -180,7 +192,7 @@ jobs:
|
|||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
build:
|
build:
|
||||||
name: 🏗️ Build
|
name: 🏗️ Build
|
||||||
needs: [prepare, qa]
|
needs: prepare
|
||||||
if: needs.prepare.outputs.target != 'skip'
|
if: needs.prepare.outputs.target != 'skip'
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
@@ -206,8 +218,8 @@ jobs:
|
|||||||
UMAMI_API_ENDPOINT=${{ secrets.UMAMI_API_ENDPOINT || vars.UMAMI_API_ENDPOINT || 'https://analytics.infra.mintel.me' }}
|
UMAMI_API_ENDPOINT=${{ secrets.UMAMI_API_ENDPOINT || vars.UMAMI_API_ENDPOINT || 'https://analytics.infra.mintel.me' }}
|
||||||
NPM_TOKEN=${{ secrets.REGISTRY_PASS }}
|
NPM_TOKEN=${{ secrets.REGISTRY_PASS }}
|
||||||
tags: registry.infra.mintel.me/mintel/klz-cables.com:${{ needs.prepare.outputs.image_tag }}
|
tags: registry.infra.mintel.me/mintel/klz-cables.com:${{ needs.prepare.outputs.image_tag }}
|
||||||
cache-from: type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache
|
cache-from: type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache-v2
|
||||||
cache-to: type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache,mode=max
|
cache-to: type=registry,ref=registry.infra.mintel.me/mintel/klz-cables.com:buildcache-v2,mode=max
|
||||||
secrets: |
|
secrets: |
|
||||||
"NPM_TOKEN=${{ secrets.REGISTRY_PASS }}"
|
"NPM_TOKEN=${{ secrets.REGISTRY_PASS }}"
|
||||||
|
|
||||||
@@ -386,14 +398,26 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
|
- name: Get pnpm store directory
|
||||||
|
id: pnpm-cache
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
|
||||||
|
- name: Setup pnpm cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
||||||
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pnpm-store-
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
- name: 🔐 Registry Auth
|
- name: 🔐 Registry Auth
|
||||||
run: |
|
run: |
|
||||||
echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
|
echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
|
||||||
@@ -418,14 +442,26 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v3
|
uses: pnpm/action-setup@v3
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 10
|
||||||
|
- name: Get pnpm store directory
|
||||||
|
id: pnpm-cache
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
|
||||||
|
- name: Setup pnpm cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
|
||||||
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pnpm-store-
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 20
|
||||||
- name: 🔐 Registry Auth
|
- name: 🔐 Registry Auth
|
||||||
run: |
|
run: |
|
||||||
echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
|
echo "@mintel:registry=https://${{ vars.REGISTRY_HOST || 'npm.infra.mintel.me' }}" > .npmrc
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ ARG NEXT_PUBLIC_TARGET
|
|||||||
ARG DIRECTUS_URL
|
ARG DIRECTUS_URL
|
||||||
ARG UMAMI_WEBSITE_ID
|
ARG UMAMI_WEBSITE_ID
|
||||||
ARG UMAMI_API_ENDPOINT
|
ARG UMAMI_API_ENDPOINT
|
||||||
ARG NPM_TOKEN
|
|
||||||
|
|
||||||
# Environment variables for Next.js build
|
# Environment variables for Next.js build
|
||||||
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
|
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
|
||||||
@@ -25,7 +24,7 @@ COPY pnpm-lock.yaml package.json .npmrc* ./
|
|||||||
# Configure private registry and install dependencies
|
# Configure private registry and install dependencies
|
||||||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
|
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
|
||||||
--mount=type=secret,id=NPM_TOKEN \
|
--mount=type=secret,id=NPM_TOKEN \
|
||||||
export NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN 2>/dev/null || echo $NPM_TOKEN) && \
|
export NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN) && \
|
||||||
echo "@mintel:registry=https://npm.infra.mintel.me" > .npmrc && \
|
echo "@mintel:registry=https://npm.infra.mintel.me" > .npmrc && \
|
||||||
echo "//npm.infra.mintel.me/:_authToken=\${NPM_TOKEN}" >> .npmrc && \
|
echo "//npm.infra.mintel.me/:_authToken=\${NPM_TOKEN}" >> .npmrc && \
|
||||||
pnpm install --frozen-lockfile && \
|
pnpm install --frozen-lockfile && \
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { MDXRemote } from 'next-mdx-remote/rsc';
|
|||||||
import { getPostBySlug, getAdjacentPosts, getReadingTime, getHeadings } from '@/lib/blog';
|
import { getPostBySlug, getAdjacentPosts, getReadingTime, getHeadings } from '@/lib/blog';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import Image from 'next/image';
|
||||||
import PostNavigation from '@/components/blog/PostNavigation';
|
import PostNavigation from '@/components/blog/PostNavigation';
|
||||||
import PowerCTA from '@/components/blog/PowerCTA';
|
import PowerCTA from '@/components/blog/PowerCTA';
|
||||||
import TableOfContents from '@/components/blog/TableOfContents';
|
import TableOfContents from '@/components/blog/TableOfContents';
|
||||||
@@ -69,13 +70,24 @@ export default async function BlogPost({ params }: BlogPostProps) {
|
|||||||
category={post.frontmatter.category}
|
category={post.frontmatter.category}
|
||||||
readingTime={getReadingTime(post.content)}
|
readingTime={getReadingTime(post.content)}
|
||||||
/>
|
/>
|
||||||
|
{(new Date(post.frontmatter.date) > new Date() || post.frontmatter.public === false) && (
|
||||||
|
<div className="bg-orange-500 text-white text-center py-2 px-4 font-bold text-sm tracking-wider uppercase relative z-50">
|
||||||
|
Preview (Not visible in production)
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{/* Featured Image Header */}
|
{/* Featured Image Header */}
|
||||||
{post.frontmatter.featuredImage ? (
|
{post.frontmatter.featuredImage ? (
|
||||||
<div className="relative w-full h-[70vh] min-h-[500px] overflow-hidden group">
|
<div className="relative w-full h-[70vh] min-h-[500px] overflow-hidden group">
|
||||||
<div
|
<div className="absolute inset-0 transition-transform duration-[3s] ease-out scale-110 group-hover:scale-100">
|
||||||
className="absolute inset-0 bg-cover bg-center transition-transform duration-[3s] ease-out scale-110 group-hover:scale-100"
|
<Image
|
||||||
style={{ backgroundImage: `url(${post.frontmatter.featuredImage})` }}
|
src={`${post.frontmatter.featuredImage}?gravity=obj:face`}
|
||||||
/>
|
alt={post.frontmatter.title}
|
||||||
|
fill
|
||||||
|
priority
|
||||||
|
className="object-cover"
|
||||||
|
sizes="100vw"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="absolute inset-0 bg-gradient-to-t from-neutral-dark via-neutral-dark/40 to-transparent" />
|
<div className="absolute inset-0 bg-gradient-to-t from-neutral-dark via-neutral-dark/40 to-transparent" />
|
||||||
|
|
||||||
{/* Title overlay on image */}
|
{/* Title overlay on image */}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
{featuredPost && featuredPost.frontmatter.featuredImage && (
|
{featuredPost && featuredPost.frontmatter.featuredImage && (
|
||||||
<>
|
<>
|
||||||
<Image
|
<Image
|
||||||
src={featuredPost.frontmatter.featuredImage}
|
src={`${featuredPost.frontmatter.featuredImage}?gravity=obj:face`}
|
||||||
alt={featuredPost.frontmatter.title}
|
alt={featuredPost.frontmatter.title}
|
||||||
fill
|
fill
|
||||||
className="absolute inset-0 w-full h-full object-cover scale-105 animate-slow-zoom opacity-40 md:opacity-60"
|
className="absolute inset-0 w-full h-full object-cover scale-105 animate-slow-zoom opacity-40 md:opacity-60"
|
||||||
@@ -75,9 +75,16 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
|
|
||||||
<Container className="relative z-10">
|
<Container className="relative z-10">
|
||||||
<div className="max-w-4xl animate-slide-up">
|
<div className="max-w-4xl animate-slide-up">
|
||||||
<Badge variant="saturated" className="mb-4 md:mb-6">
|
<div className="flex flex-wrap items-center gap-3 mb-4 md:mb-6">
|
||||||
{t('featuredPost')}
|
<Badge variant="saturated">{t('featuredPost')}</Badge>
|
||||||
</Badge>
|
{featuredPost &&
|
||||||
|
(new Date(featuredPost.frontmatter.date) > new Date() ||
|
||||||
|
featuredPost.frontmatter.public === false) && (
|
||||||
|
<Badge variant="accent" className="bg-orange-500 text-white border-none">
|
||||||
|
Preview
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
{featuredPost && (
|
{featuredPost && (
|
||||||
<>
|
<>
|
||||||
<Heading level={1} className="text-white mb-4 md:mb-8">
|
<Heading level={1} className="text-white mb-4 md:mb-8">
|
||||||
@@ -153,7 +160,7 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
{post.frontmatter.featuredImage && (
|
{post.frontmatter.featuredImage && (
|
||||||
<div className="relative h-48 md:h-72 overflow-hidden">
|
<div className="relative h-48 md:h-72 overflow-hidden">
|
||||||
<Image
|
<Image
|
||||||
src={post.frontmatter.featuredImage}
|
src={`${post.frontmatter.featuredImage}?gravity=obj:face`}
|
||||||
alt={post.frontmatter.title}
|
alt={post.frontmatter.title}
|
||||||
fill
|
fill
|
||||||
className="w-full h-full object-cover transition-transform duration-1000 group-hover:scale-110"
|
className="w-full h-full object-cover transition-transform duration-1000 group-hover:scale-110"
|
||||||
@@ -168,6 +175,15 @@ export default async function BlogIndex({ params }: BlogIndexProps) {
|
|||||||
{post.frontmatter.category}
|
{post.frontmatter.category}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
|
{(new Date(post.frontmatter.date) > new Date() ||
|
||||||
|
post.frontmatter.public === false) && (
|
||||||
|
<Badge
|
||||||
|
variant="accent"
|
||||||
|
className="absolute top-3 right-3 md:top-6 md:right-6 shadow-lg bg-orange-500 text-white border-none"
|
||||||
|
>
|
||||||
|
Preview
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="p-5 md:p-10 flex flex-col flex-1">
|
<div className="p-5 md:p-10 flex flex-col flex-1">
|
||||||
|
|||||||
@@ -136,18 +136,14 @@ function AddToCartButton({ product, quantity = 1 }) {
|
|||||||
product_category: product.category,
|
product_category: product.category,
|
||||||
price: product.price,
|
price: product.price,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
cart_total: 150.00, // Current cart total
|
cart_total: 150.0, // Current cart total
|
||||||
});
|
});
|
||||||
|
|
||||||
// Actual add to cart logic
|
// Actual add to cart logic
|
||||||
// addToCart(product, quantity);
|
// addToCart(product, quantity);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <button onClick={handleAddToCart}>Add to Cart</button>;
|
||||||
<button onClick={handleAddToCart}>
|
|
||||||
Add to Cart
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -171,7 +167,7 @@ function CheckoutComplete({ order }) {
|
|||||||
transaction_tax: order.tax,
|
transaction_tax: order.tax,
|
||||||
transaction_shipping: order.shipping,
|
transaction_shipping: order.shipping,
|
||||||
product_count: order.items.length,
|
product_count: order.items.length,
|
||||||
products: order.items.map(item => ({
|
products: order.items.map((item) => ({
|
||||||
product_id: item.product.id,
|
product_id: item.product.id,
|
||||||
product_name: item.product.name,
|
product_name: item.product.name,
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
@@ -198,27 +194,21 @@ function WishlistButton({ product }) {
|
|||||||
|
|
||||||
const toggleWishlist = () => {
|
const toggleWishlist = () => {
|
||||||
const newState = !isInWishlist;
|
const newState = !isInWishlist;
|
||||||
|
|
||||||
trackEvent(
|
trackEvent(
|
||||||
newState
|
newState ? AnalyticsEvents.PRODUCT_WISHLIST_ADD : AnalyticsEvents.PRODUCT_WISHLIST_REMOVE,
|
||||||
? AnalyticsEvents.PRODUCT_WISHLIST_ADD
|
|
||||||
: AnalyticsEvents.PRODUCT_WISHLIST_REMOVE,
|
|
||||||
{
|
{
|
||||||
product_id: product.id,
|
product_id: product.id,
|
||||||
product_name: product.name,
|
product_name: product.name,
|
||||||
product_category: product.category,
|
product_category: product.category,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
setIsInWishlist(newState);
|
setIsInWishlist(newState);
|
||||||
// Update wishlist in backend
|
// Update wishlist in backend
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <button onClick={toggleWishlist}>{isInWishlist ? '❤️' : '🤍'}</button>;
|
||||||
<button onClick={toggleWishlist}>
|
|
||||||
{isInWishlist ? '❤️' : '🤍'}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -268,7 +258,7 @@ function ContactForm() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||||
setFormData(prev => ({
|
setFormData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[e.target.name]: e.target.value,
|
[e.target.name]: e.target.value,
|
||||||
}));
|
}));
|
||||||
@@ -310,9 +300,7 @@ function NewsletterSignup() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<input placeholder="Enter email" />
|
<input placeholder="Enter email" />
|
||||||
<button onClick={() => handleSubscribe('user@example.com')}>
|
<button onClick={() => handleSubscribe('user@example.com')}>Subscribe</button>
|
||||||
Subscribe
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -396,10 +384,12 @@ function LoginForm() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={(e) => {
|
<form
|
||||||
e.preventDefault();
|
onSubmit={(e) => {
|
||||||
handleLogin('user@example.com', 'password');
|
e.preventDefault();
|
||||||
}}>
|
handleLogin('user@example.com', 'password');
|
||||||
|
}}
|
||||||
|
>
|
||||||
{/* Form fields */}
|
{/* Form fields */}
|
||||||
<button type="submit">Login</button>
|
<button type="submit">Login</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -418,11 +408,7 @@ import { AnalyticsEvents } from '@/components/analytics/analytics-events';
|
|||||||
function SignupForm() {
|
function SignupForm() {
|
||||||
const { trackEvent } = useAnalytics();
|
const { trackEvent } = useAnalytics();
|
||||||
|
|
||||||
const handleSignup = (userData: {
|
const handleSignup = (userData: { email: string; name: string; company?: string }) => {
|
||||||
email: string;
|
|
||||||
name: string;
|
|
||||||
company?: string;
|
|
||||||
}) => {
|
|
||||||
trackEvent(AnalyticsEvents.USER_SIGNUP, {
|
trackEvent(AnalyticsEvents.USER_SIGNUP, {
|
||||||
user_email: userData.email,
|
user_email: userData.email,
|
||||||
user_name: userData.name,
|
user_name: userData.name,
|
||||||
@@ -436,14 +422,16 @@ function SignupForm() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={(e) => {
|
<form
|
||||||
e.preventDefault();
|
onSubmit={(e) => {
|
||||||
handleSignup({
|
e.preventDefault();
|
||||||
email: 'user@example.com',
|
handleSignup({
|
||||||
name: 'John Doe',
|
email: 'user@example.com',
|
||||||
company: 'ACME Corp',
|
name: 'John Doe',
|
||||||
});
|
company: 'ACME Corp',
|
||||||
}}>
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
{/* Form fields */}
|
{/* Form fields */}
|
||||||
<button type="submit">Sign Up</button>
|
<button type="submit">Sign Up</button>
|
||||||
</form>
|
</form>
|
||||||
@@ -483,7 +471,7 @@ function SearchBar() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<input
|
<input
|
||||||
value={query}
|
value={query}
|
||||||
onChange={(e) => setQuery(e.target.value)}
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
placeholder="Search products..."
|
placeholder="Search products..."
|
||||||
@@ -549,7 +537,7 @@ function ProductFilters() {
|
|||||||
<option value="cables">Cables</option>
|
<option value="cables">Cables</option>
|
||||||
<option value="connectors">Connectors</option>
|
<option value="connectors">Connectors</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<button onClick={handleClearFilters}>Clear Filters</button>
|
<button onClick={handleClearFilters}>Clear Filters</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -631,11 +619,7 @@ function VideoPlayer({ videoId, videoTitle }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<video
|
<video onPlay={handlePlay} onPause={handlePause} onEnded={handleComplete}>
|
||||||
onPlay={handlePlay}
|
|
||||||
onPause={handlePause}
|
|
||||||
onEnded={handleComplete}
|
|
||||||
>
|
|
||||||
<source src="/video.mp4" type="video/mp4" />
|
<source src="/video.mp4" type="video/mp4" />
|
||||||
</video>
|
</video>
|
||||||
);
|
);
|
||||||
@@ -665,11 +649,7 @@ function DownloadButton({ fileName, fileType, fileSize }) {
|
|||||||
// window.location.href = `/downloads/${fileName}`;
|
// window.location.href = `/downloads/${fileName}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <button onClick={handleDownload}>Download {fileName}</button>;
|
||||||
<button onClick={handleDownload}>
|
|
||||||
Download {fileName}
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -700,7 +680,7 @@ class ErrorBoundary extends Component<ErrorBoundaryProps> {
|
|||||||
|
|
||||||
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||||
const { trackEvent } = useAnalytics();
|
const { trackEvent } = useAnalytics();
|
||||||
|
|
||||||
trackEvent(AnalyticsEvents.ERROR, {
|
trackEvent(AnalyticsEvents.ERROR, {
|
||||||
error_message: error.message,
|
error_message: error.message,
|
||||||
error_stack: error.stack,
|
error_stack: error.stack,
|
||||||
@@ -742,14 +722,14 @@ function ApiClient() {
|
|||||||
const fetchData = async (endpoint: string) => {
|
const fetchData = async (endpoint: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(endpoint);
|
const response = await fetch(endpoint);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
trackEvent(AnalyticsEvents.API_ERROR, {
|
trackEvent(AnalyticsEvents.API_ERROR, {
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
status_code: response.status,
|
status_code: response.status,
|
||||||
error_message: response.statusText,
|
error_message: response.statusText,
|
||||||
});
|
});
|
||||||
|
|
||||||
throw new Error(`HTTP ${response.status}`);
|
throw new Error(`HTTP ${response.status}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -765,7 +745,7 @@ function ApiClient() {
|
|||||||
error_message: error.message,
|
error_message: error.message,
|
||||||
error_type: error.name,
|
error_type: error.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -963,15 +943,9 @@ function CableProductPage({ cable }) {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>{cable.name}</h1>
|
<h1>{cable.name}</h1>
|
||||||
<button onClick={handleTechnicalSpecDownload}>
|
<button onClick={handleTechnicalSpecDownload}>Download Technical Specs</button>
|
||||||
Download Technical Specs
|
<button onClick={handleRequestQuote}>Request Quote</button>
|
||||||
</button>
|
<button onClick={handleBrochureDownload}>Download Brochure</button>
|
||||||
<button onClick={handleRequestQuote}>
|
|
||||||
Request Quote
|
|
||||||
</button>
|
|
||||||
<button onClick={handleBrochureDownload}>
|
|
||||||
Download Brochure
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1010,12 +984,8 @@ function WindFarmProjectPage({ project }) {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>{project.name}</h1>
|
<h1>{project.name}</h1>
|
||||||
<button onClick={handleProjectInquiry}>
|
<button onClick={handleProjectInquiry}>Request Project Consultation</button>
|
||||||
Request Project Consultation
|
<button onClick={handleCableCalculation}>Calculate Cable Requirements</button>
|
||||||
</button>
|
|
||||||
<button onClick={handleCableCalculation}>
|
|
||||||
Calculate Cable Requirements
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1066,7 +1036,7 @@ test('tracks button click', () => {
|
|||||||
// [Umami] Tracked pageview: /products/123
|
// [Umami] Tracked pageview: /products/123
|
||||||
|
|
||||||
// To test without sending data to Umami:
|
// To test without sending data to Umami:
|
||||||
// 1. Remove NEXT_PUBLIC_UMAMI_WEBSITE_ID from .env
|
// 1. Remove UMAMI_WEBSITE_ID from .env
|
||||||
// 2. Or set it to an empty string
|
// 2. Or set it to an empty string
|
||||||
// 3. Check console logs to verify events are being tracked
|
// 3. Check console logs to verify events are being tracked
|
||||||
```
|
```
|
||||||
@@ -1169,7 +1139,9 @@ function WebVitalsTracker() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe({ entryTypes: ['largest-contentful-paint', 'first-input-delay', 'layout-shift'] });
|
observer.observe({
|
||||||
|
entryTypes: ['largest-contentful-paint', 'first-input-delay', 'layout-shift'],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -1194,6 +1166,7 @@ This examples file demonstrates how to implement comprehensive analytics trackin
|
|||||||
- ✅ **Business-specific events** (KLZ Cables, wind farms)
|
- ✅ **Business-specific events** (KLZ Cables, wind farms)
|
||||||
|
|
||||||
Remember to:
|
Remember to:
|
||||||
|
|
||||||
1. Use the `useAnalytics` hook for client-side tracking
|
1. Use the `useAnalytics` hook for client-side tracking
|
||||||
2. Import events from `AnalyticsEvents` for consistency
|
2. Import events from `AnalyticsEvents` for consistency
|
||||||
3. Include relevant context in your events
|
3. Include relevant context in your events
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Setup Checklist
|
## Setup Checklist
|
||||||
|
|
||||||
- [ ] Add `NEXT_PUBLIC_UMAMI_WEBSITE_ID` to `.env` file
|
- [ ] Add `UMAMI_WEBSITE_ID` to `.env` file
|
||||||
- [ ] Verify `UmamiScript` is in your layout
|
- [ ] Verify `UmamiScript` is in your layout
|
||||||
- [ ] Verify `AnalyticsProvider` is in your layout
|
- [ ] Verify `AnalyticsProvider` is in your layout
|
||||||
- [ ] Test in development mode
|
- [ ] Test in development mode
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Required
|
# Required
|
||||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
||||||
|
|
||||||
# Optional (defaults to https://analytics.infra.mintel.me/script.js)
|
# Optional (defaults to https://analytics.infra.mintel.me/script.js)
|
||||||
NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://analytics.infra.mintel.me/script.js
|
NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://analytics.infra.mintel.me/script.js
|
||||||
@@ -86,16 +86,16 @@ function ProductCard({ product }) {
|
|||||||
|
|
||||||
## Common Events
|
## Common Events
|
||||||
|
|
||||||
| Event | When to Use | Example Properties |
|
| Event | When to Use | Example Properties |
|
||||||
|-------|-------------|-------------------|
|
| --------------------- | ------------------- | ------------------------------------------------- |
|
||||||
| `pageview` | Page loads | `{ url: '/products/123' }` |
|
| `pageview` | Page loads | `{ url: '/products/123' }` |
|
||||||
| `button_click` | Button clicked | `{ button_id: 'cta', page: 'homepage' }` |
|
| `button_click` | Button clicked | `{ button_id: 'cta', page: 'homepage' }` |
|
||||||
| `form_submit` | Form submitted | `{ form_id: 'contact', form_name: 'Contact Us' }` |
|
| `form_submit` | Form submitted | `{ form_id: 'contact', form_name: 'Contact Us' }` |
|
||||||
| `product_view` | Product page viewed | `{ product_id: '123', price: 99.99 }` |
|
| `product_view` | Product page viewed | `{ product_id: '123', price: 99.99 }` |
|
||||||
| `product_add_to_cart` | Add to cart | `{ product_id: '123', quantity: 1 }` |
|
| `product_add_to_cart` | Add to cart | `{ product_id: '123', quantity: 1 }` |
|
||||||
| `search` | Search performed | `{ search_query: 'cable', results: 42 }` |
|
| `search` | Search performed | `{ search_query: 'cable', results: 42 }` |
|
||||||
| `user_login` | User logged in | `{ user_email: 'user@example.com' }` |
|
| `user_login` | User logged in | `{ user_email: 'user@example.com' }` |
|
||||||
| `error` | Error occurred | `{ error_message: 'Something went wrong' }` |
|
| `error` | Error occurred | `{ error_message: 'Something went wrong' }` |
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ In development, you'll see console logs:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# .env.local
|
# .env.local
|
||||||
# NEXT_PUBLIC_UMAMI_WEBSITE_ID=
|
# UMAMI_WEBSITE_ID=
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
@@ -120,8 +120,9 @@ In development, you'll see console logs:
|
|||||||
### Analytics Not Working?
|
### Analytics Not Working?
|
||||||
|
|
||||||
1. **Check environment variables:**
|
1. **Check environment variables:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo $NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
echo $UMAMI_WEBSITE_ID
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Verify script is loading:**
|
2. **Verify script is loading:**
|
||||||
@@ -136,12 +137,12 @@ In development, you'll see console logs:
|
|||||||
|
|
||||||
### Common Issues
|
### Common Issues
|
||||||
|
|
||||||
| Issue | Solution |
|
| Issue | Solution |
|
||||||
|-------|----------|
|
| ------------------- | ----------------------------------- |
|
||||||
| No data in Umami | Check website ID and script URL |
|
| No data in Umami | Check website ID and script URL |
|
||||||
| Events not tracking | Verify `useAnalytics` hook is used |
|
| Events not tracking | Verify `useAnalytics` hook is used |
|
||||||
| Script not loading | Check network connection, CORS |
|
| Script not loading | Check network connection, CORS |
|
||||||
| Wrong data | Verify event properties are correct |
|
| Wrong data | Verify event properties are correct |
|
||||||
|
|
||||||
## Performance Tips
|
## Performance Tips
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ Add these to your `.env` file:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Required: Your Umami website ID
|
# Required: Your Umami website ID
|
||||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
||||||
|
|
||||||
# Optional: Custom Umami script URL (defaults to https://analytics.infra.mintel.me/script.js)
|
# Optional: Custom Umami script URL (defaults to https://analytics.infra.mintel.me/script.js)
|
||||||
NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://analytics.infra.mintel.me/script.js
|
NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://analytics.infra.mintel.me/script.js
|
||||||
@@ -32,7 +32,7 @@ The `docker-compose.yml` already includes the environment variables:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
environment:
|
environment:
|
||||||
- NEXT_PUBLIC_UMAMI_WEBSITE_ID=${NEXT_PUBLIC_UMAMI_WEBSITE_ID}
|
- UMAMI_WEBSITE_ID=${UMAMI_WEBSITE_ID}
|
||||||
- NEXT_PUBLIC_UMAMI_SCRIPT_URL=${NEXT_PUBLIC_UMAMI_SCRIPT_URL:-https://analytics.infra.mintel.me/script.js}
|
- NEXT_PUBLIC_UMAMI_SCRIPT_URL=${NEXT_PUBLIC_UMAMI_SCRIPT_URL:-https://analytics.infra.mintel.me/script.js}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -75,11 +75,7 @@ function ProductCard({ product }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <button onClick={handleAddToCart}>Add to Cart</button>;
|
||||||
<button onClick={handleAddToCart}>
|
|
||||||
Add to Cart
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -96,7 +92,7 @@ function CustomNavigation() {
|
|||||||
const navigateToCustomPage = () => {
|
const navigateToCustomPage = () => {
|
||||||
// Track a custom pageview
|
// Track a custom pageview
|
||||||
trackPageview('/custom-path?param=value');
|
trackPageview('/custom-path?param=value');
|
||||||
|
|
||||||
// Then perform navigation
|
// Then perform navigation
|
||||||
window.location.href = '/custom-path?param=value';
|
window.location.href = '/custom-path?param=value';
|
||||||
};
|
};
|
||||||
@@ -277,11 +273,7 @@ function ErrorBoundary({ children }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <ErrorBoundary onError={handleError}>{children}</ErrorBoundary>;
|
||||||
<ErrorBoundary onError={handleError}>
|
|
||||||
{children}
|
|
||||||
</ErrorBoundary>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -289,20 +281,20 @@ function ErrorBoundary({ children }) {
|
|||||||
|
|
||||||
### Common Events
|
### Common Events
|
||||||
|
|
||||||
| Event Name | Description | Example Properties |
|
| Event Name | Description | Example Properties |
|
||||||
|------------|-------------|-------------------|
|
| --------------------- | --------------------- | ------------------------------------------------------------ |
|
||||||
| `pageview` | Page view | `{ url: '/products/123' }` |
|
| `pageview` | Page view | `{ url: '/products/123' }` |
|
||||||
| `button_click` | Button clicked | `{ button_id: 'cta-primary', page: 'homepage' }` |
|
| `button_click` | Button clicked | `{ button_id: 'cta-primary', page: 'homepage' }` |
|
||||||
| `link_click` | Link clicked | `{ link_url: '/products', link_text: 'View Products' }` |
|
| `link_click` | Link clicked | `{ link_url: '/products', link_text: 'View Products' }` |
|
||||||
| `form_submit` | Form submitted | `{ form_id: 'contact-form', form_name: 'Contact Us' }` |
|
| `form_submit` | Form submitted | `{ form_id: 'contact-form', form_name: 'Contact Us' }` |
|
||||||
| `product_view` | Product page viewed | `{ product_id: '123', product_name: 'Cable', price: 99.99 }` |
|
| `product_view` | Product page viewed | `{ product_id: '123', product_name: 'Cable', price: 99.99 }` |
|
||||||
| `product_add_to_cart` | Product added to cart | `{ product_id: '123', quantity: 1 }` |
|
| `product_add_to_cart` | Product added to cart | `{ product_id: '123', quantity: 1 }` |
|
||||||
| `product_purchase` | Product purchased | `{ product_id: '123', transaction_id: 'TXN-123' }` |
|
| `product_purchase` | Product purchased | `{ product_id: '123', transaction_id: 'TXN-123' }` |
|
||||||
| `search` | Search performed | `{ search_query: 'cable', search_results_count: 42 }` |
|
| `search` | Search performed | `{ search_query: 'cable', search_results_count: 42 }` |
|
||||||
| `filter_apply` | Filter applied | `{ filter_type: 'category', filter_value: 'high-voltage' }` |
|
| `filter_apply` | Filter applied | `{ filter_type: 'category', filter_value: 'high-voltage' }` |
|
||||||
| `user_login` | User logged in | `{ user_email: 'user@example.com' }` |
|
| `user_login` | User logged in | `{ user_email: 'user@example.com' }` |
|
||||||
| `user_signup` | User signed up | `{ user_email: 'user@example.com' }` |
|
| `user_signup` | User signed up | `{ user_email: 'user@example.com' }` |
|
||||||
| `error` | Error occurred | `{ error_message: 'Something went wrong' }` |
|
| `error` | Error occurred | `{ error_message: 'Something went wrong' }` |
|
||||||
|
|
||||||
### Custom Events
|
### Custom Events
|
||||||
|
|
||||||
@@ -385,8 +377,9 @@ The analytics system includes development mode logging:
|
|||||||
### Analytics Not Working
|
### Analytics Not Working
|
||||||
|
|
||||||
1. **Check environment variables:**
|
1. **Check environment variables:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo $NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
echo $UMAMI_WEBSITE_ID
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Verify the script is loading:**
|
2. **Verify the script is loading:**
|
||||||
@@ -405,11 +398,11 @@ In development mode, you'll see console logs for all tracked events. This helps
|
|||||||
|
|
||||||
### Disabling Analytics
|
### Disabling Analytics
|
||||||
|
|
||||||
To disable analytics (e.g., for local development), simply remove the `NEXT_PUBLIC_UMAMI_WEBSITE_ID` environment variable:
|
To disable analytics (e.g., for local development), simply remove the `UMAMI_WEBSITE_ID` environment variable:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# .env.local (not committed to git)
|
# .env.local (not committed to git)
|
||||||
# NEXT_PUBLIC_UMAMI_WEBSITE_ID=
|
# UMAMI_WEBSITE_ID=
|
||||||
```
|
```
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
@@ -438,6 +431,7 @@ The analytics implementation is optimized for performance:
|
|||||||
## Support
|
## Support
|
||||||
|
|
||||||
For issues or questions about the analytics implementation, check:
|
For issues or questions about the analytics implementation, check:
|
||||||
|
|
||||||
1. This README for usage examples
|
1. This README for usage examples
|
||||||
2. The component source code for implementation details
|
2. The component source code for implementation details
|
||||||
3. The Umami documentation for platform-specific questions
|
3. The Umami documentation for platform-specific questions
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ The project already had a solid foundation:
|
|||||||
## What Was Enhanced
|
## What Was Enhanced
|
||||||
|
|
||||||
### 1. **Enhanced UmamiScript** (`components/analytics/UmamiScript.tsx`)
|
### 1. **Enhanced UmamiScript** (`components/analytics/UmamiScript.tsx`)
|
||||||
|
|
||||||
- ✅ Added TypeScript props interface for customization
|
- ✅ Added TypeScript props interface for customization
|
||||||
- ✅ Added JSDoc documentation with usage examples
|
- ✅ Added JSDoc documentation with usage examples
|
||||||
- ✅ Added error handling for script loading failures
|
- ✅ Added error handling for script loading failures
|
||||||
@@ -23,11 +24,13 @@ The project already had a solid foundation:
|
|||||||
- ✅ Improved type safety and comments
|
- ✅ Improved type safety and comments
|
||||||
|
|
||||||
### 2. **Enhanced AnalyticsProvider** (`components/analytics/AnalyticsProvider.tsx`)
|
### 2. **Enhanced AnalyticsProvider** (`components/analytics/AnalyticsProvider.tsx`)
|
||||||
|
|
||||||
- ✅ Added comprehensive JSDoc documentation
|
- ✅ Added comprehensive JSDoc documentation
|
||||||
- ✅ Added development mode logging
|
- ✅ Added development mode logging
|
||||||
- ✅ Improved code comments
|
- ✅ Improved code comments
|
||||||
|
|
||||||
### 3. **New Custom Hook** (`components/analytics/useAnalytics.ts`)
|
### 3. **New Custom Hook** (`components/analytics/useAnalytics.ts`)
|
||||||
|
|
||||||
- ✅ Type-safe `useAnalytics` hook for easy event tracking
|
- ✅ Type-safe `useAnalytics` hook for easy event tracking
|
||||||
- ✅ `trackEvent()` method for custom events
|
- ✅ `trackEvent()` method for custom events
|
||||||
- ✅ `trackPageview()` method for manual pageview tracking
|
- ✅ `trackPageview()` method for manual pageview tracking
|
||||||
@@ -35,12 +38,14 @@ The project already had a solid foundation:
|
|||||||
- ✅ Development mode logging
|
- ✅ Development mode logging
|
||||||
|
|
||||||
### 4. **Event Definitions** (`components/analytics/analytics-events.ts`)
|
### 4. **Event Definitions** (`components/analytics/analytics-events.ts`)
|
||||||
|
|
||||||
- ✅ Centralized event constants for consistency
|
- ✅ Centralized event constants for consistency
|
||||||
- ✅ Type-safe event names
|
- ✅ Type-safe event names
|
||||||
- ✅ Helper functions for common event properties
|
- ✅ Helper functions for common event properties
|
||||||
- ✅ 30+ predefined events for various use cases
|
- ✅ 30+ predefined events for various use cases
|
||||||
|
|
||||||
### 5. **Comprehensive Documentation**
|
### 5. **Comprehensive Documentation**
|
||||||
|
|
||||||
- ✅ **README.md** - Full documentation with setup, usage, and best practices
|
- ✅ **README.md** - Full documentation with setup, usage, and best practices
|
||||||
- ✅ **EXAMPLES.md** - 20+ practical examples for different scenarios
|
- ✅ **EXAMPLES.md** - 20+ practical examples for different scenarios
|
||||||
- ✅ **QUICK_REFERENCE.md** - Quick start guide and troubleshooting
|
- ✅ **QUICK_REFERENCE.md** - Quick start guide and troubleshooting
|
||||||
@@ -63,12 +68,14 @@ components/analytics/
|
|||||||
## Key Features
|
## Key Features
|
||||||
|
|
||||||
### 🚀 Modern Implementation
|
### 🚀 Modern Implementation
|
||||||
|
|
||||||
- Uses Next.js `Script` component (not old-school `<script>` tags)
|
- Uses Next.js `Script` component (not old-school `<script>` tags)
|
||||||
- TypeScript for type safety
|
- TypeScript for type safety
|
||||||
- React hooks for clean API
|
- React hooks for clean API
|
||||||
- Environment variable configuration
|
- Environment variable configuration
|
||||||
|
|
||||||
### 📊 Comprehensive Tracking
|
### 📊 Comprehensive Tracking
|
||||||
|
|
||||||
- Automatic pageview tracking on route changes
|
- Automatic pageview tracking on route changes
|
||||||
- Custom event tracking with properties
|
- Custom event tracking with properties
|
||||||
- E-commerce events (products, cart, purchases)
|
- E-commerce events (products, cart, purchases)
|
||||||
@@ -77,6 +84,7 @@ components/analytics/
|
|||||||
- Error and performance tracking
|
- Error and performance tracking
|
||||||
|
|
||||||
### 🎯 Developer Experience
|
### 🎯 Developer Experience
|
||||||
|
|
||||||
- Type-safe event tracking
|
- Type-safe event tracking
|
||||||
- Centralized event definitions
|
- Centralized event definitions
|
||||||
- Development mode logging
|
- Development mode logging
|
||||||
@@ -84,6 +92,7 @@ components/analytics/
|
|||||||
- 20+ practical examples
|
- 20+ practical examples
|
||||||
|
|
||||||
### 🔒 Privacy & Performance
|
### 🔒 Privacy & Performance
|
||||||
|
|
||||||
- No PII tracking by default
|
- No PII tracking by default
|
||||||
- Script loads after page is interactive
|
- Script loads after page is interactive
|
||||||
- Minimal performance impact
|
- Minimal performance impact
|
||||||
@@ -95,7 +104,7 @@ The project is already configured in `docker-compose.yml`:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
environment:
|
environment:
|
||||||
- NEXT_PUBLIC_UMAMI_WEBSITE_ID=${NEXT_PUBLIC_UMAMI_WEBSITE_ID}
|
- UMAMI_WEBSITE_ID=${UMAMI_WEBSITE_ID}
|
||||||
- NEXT_PUBLIC_UMAMI_SCRIPT_URL=${NEXT_PUBLIC_UMAMI_SCRIPT_URL:-https://analytics.infra.mintel.me/script.js}
|
- NEXT_PUBLIC_UMAMI_SCRIPT_URL=${NEXT_PUBLIC_UMAMI_SCRIPT_URL:-https://analytics.infra.mintel.me/script.js}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -104,7 +113,7 @@ environment:
|
|||||||
Add to your `.env` file:
|
Add to your `.env` file:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage Examples
|
## Usage Examples
|
||||||
@@ -188,7 +197,7 @@ In development, you'll see console logs:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# .env.local
|
# .env.local
|
||||||
# NEXT_PUBLIC_UMAMI_WEBSITE_ID=
|
# UMAMI_WEBSITE_ID=
|
||||||
```
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
@@ -196,8 +205,9 @@ In development, you'll see console logs:
|
|||||||
### Analytics Not Working?
|
### Analytics Not Working?
|
||||||
|
|
||||||
1. **Check environment variables:**
|
1. **Check environment variables:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo $NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
echo $UMAMI_WEBSITE_ID
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Verify script is loading:**
|
2. **Verify script is loading:**
|
||||||
@@ -212,12 +222,12 @@ In development, you'll see console logs:
|
|||||||
|
|
||||||
### Common Issues
|
### Common Issues
|
||||||
|
|
||||||
| Issue | Solution |
|
| Issue | Solution |
|
||||||
|-------|----------|
|
| ------------------- | ----------------------------------- |
|
||||||
| No data in Umami | Check website ID and script URL |
|
| No data in Umami | Check website ID and script URL |
|
||||||
| Events not tracking | Verify `useAnalytics` hook is used |
|
| Events not tracking | Verify `useAnalytics` hook is used |
|
||||||
| Script not loading | Check network connection, CORS |
|
| Script not loading | Check network connection, CORS |
|
||||||
| Wrong data | Verify event properties are correct |
|
| Wrong data | Verify event properties are correct |
|
||||||
|
|
||||||
## Performance Tips
|
## Performance Tips
|
||||||
|
|
||||||
@@ -239,13 +249,13 @@ In development, you'll see console logs:
|
|||||||
1. ✅ **Setup complete** - All files are in place
|
1. ✅ **Setup complete** - All files are in place
|
||||||
2. ✅ **Documentation complete** - README, EXAMPLES, QUICK_REFERENCE
|
2. ✅ **Documentation complete** - README, EXAMPLES, QUICK_REFERENCE
|
||||||
3. ✅ **Code enhanced** - Better TypeScript, error handling, docs
|
3. ✅ **Code enhanced** - Better TypeScript, error handling, docs
|
||||||
4. 📝 **Add to .env** - Set `NEXT_PUBLIC_UMAMI_WEBSITE_ID`
|
4. 📝 **Add to .env** - Set `UMAMI_WEBSITE_ID`
|
||||||
5. 🧪 **Test in development** - Verify events are tracked
|
5. 🧪 **Test in development** - Verify events are tracked
|
||||||
6. 🚀 **Deploy** - Analytics will work in production
|
6. 🚀 **Deploy** - Analytics will work in production
|
||||||
|
|
||||||
## Quick Start Checklist
|
## Quick Start Checklist
|
||||||
|
|
||||||
- [ ] Add `NEXT_PUBLIC_UMAMI_WEBSITE_ID` to `.env` file
|
- [ ] Add `UMAMI_WEBSITE_ID` to `.env` file
|
||||||
- [ ] Verify `UmamiScript` is in `app/[locale]/layout.tsx`
|
- [ ] Verify `UmamiScript` is in `app/[locale]/layout.tsx`
|
||||||
- [ ] Verify `AnalyticsProvider` is in `app/[locale]/layout.tsx`
|
- [ ] Verify `AnalyticsProvider` is in `app/[locale]/layout.tsx`
|
||||||
- [ ] Test in development mode (check console logs)
|
- [ ] Test in development mode (check console logs)
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ export default function HeroIllustration() {
|
|||||||
const viewBox = isMobile ? '400 0 1000 1100' : '-400 -200 1800 1100';
|
const viewBox = isMobile ? '400 0 1000 1100' : '-400 -200 1800 1100';
|
||||||
const scale = isMobile ? 1.44 : 1;
|
const scale = isMobile ? 1.44 : 1;
|
||||||
const opacity = isMobile ? 0.6 : 0.85;
|
const opacity = isMobile ? 0.6 : 0.85;
|
||||||
|
const strokeMultiplier = isMobile ? 2.5 : 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="absolute inset-0 z-0 overflow-visible bg-primary w-full h-full">
|
<div className="absolute inset-0 z-0 overflow-visible bg-primary w-full h-full">
|
||||||
@@ -184,7 +185,7 @@ export default function HeroIllustration() {
|
|||||||
x2={end.x}
|
x2={end.x}
|
||||||
y2={end.y}
|
y2={end.y}
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -199,14 +200,14 @@ export default function HeroIllustration() {
|
|||||||
x2={end.x}
|
x2={end.x}
|
||||||
y2={end.y}
|
y2={end.y}
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
{/* POWER LINES */}
|
{/* POWER LINES */}
|
||||||
<g stroke="white" strokeWidth="2" strokeOpacity="0.2">
|
<g stroke="white" strokeWidth={2 * strokeMultiplier} strokeOpacity="0.2">
|
||||||
{POWER_LINES.map((line, i) => {
|
{POWER_LINES.map((line, i) => {
|
||||||
const from = gridToScreen(line.from.col, line.from.row);
|
const from = gridToScreen(line.from.col, line.from.row);
|
||||||
const to = gridToScreen(line.to.col, line.to.row);
|
const to = gridToScreen(line.to.col, line.to.row);
|
||||||
@@ -230,7 +231,7 @@ export default function HeroIllustration() {
|
|||||||
x2={to.x}
|
x2={to.x}
|
||||||
y2={to.y}
|
y2={to.y}
|
||||||
stroke="url(#energy-pulse)"
|
stroke="url(#energy-pulse)"
|
||||||
strokeWidth="3"
|
strokeWidth={3 * strokeMultiplier}
|
||||||
strokeLinecap="round"
|
strokeLinecap="round"
|
||||||
style={{
|
style={{
|
||||||
strokeDasharray: `${length * 0.2} ${length * 0.8}`,
|
strokeDasharray: `${length * 0.2} ${length * 0.8}`,
|
||||||
@@ -252,7 +253,7 @@ export default function HeroIllustration() {
|
|||||||
fill="white"
|
fill="white"
|
||||||
fillOpacity="0.05"
|
fillOpacity="0.05"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
strokeOpacity="0.2"
|
strokeOpacity="0.2"
|
||||||
/>
|
/>
|
||||||
<path
|
<path
|
||||||
@@ -260,7 +261,7 @@ export default function HeroIllustration() {
|
|||||||
fill="white"
|
fill="white"
|
||||||
fillOpacity="0.1"
|
fillOpacity="0.1"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
strokeOpacity="0.3"
|
strokeOpacity="0.3"
|
||||||
/>
|
/>
|
||||||
<circle
|
<circle
|
||||||
@@ -285,7 +286,7 @@ export default function HeroIllustration() {
|
|||||||
x2="0"
|
x2="0"
|
||||||
y2="-60"
|
y2="-60"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="2"
|
strokeWidth={2 * strokeMultiplier}
|
||||||
strokeOpacity="0.3"
|
strokeOpacity="0.3"
|
||||||
/>
|
/>
|
||||||
<g transform="translate(0, -60)">
|
<g transform="translate(0, -60)">
|
||||||
@@ -303,7 +304,7 @@ export default function HeroIllustration() {
|
|||||||
x2="0"
|
x2="0"
|
||||||
y2="-30"
|
y2="-30"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1.5"
|
strokeWidth={1.5 * strokeMultiplier}
|
||||||
strokeOpacity="0.4"
|
strokeOpacity="0.4"
|
||||||
transform={`rotate(${angle})`}
|
transform={`rotate(${angle})`}
|
||||||
/>
|
/>
|
||||||
@@ -325,7 +326,7 @@ export default function HeroIllustration() {
|
|||||||
fill="white"
|
fill="white"
|
||||||
fillOpacity="0.05"
|
fillOpacity="0.05"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
strokeOpacity="0.2"
|
strokeOpacity="0.2"
|
||||||
/>
|
/>
|
||||||
<path
|
<path
|
||||||
@@ -337,7 +338,7 @@ export default function HeroIllustration() {
|
|||||||
fill="white"
|
fill="white"
|
||||||
fillOpacity="0.08"
|
fillOpacity="0.08"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
strokeOpacity="0.3"
|
strokeOpacity="0.3"
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
@@ -352,7 +353,7 @@ export default function HeroIllustration() {
|
|||||||
<path
|
<path
|
||||||
d="M -6 0 L -3 -45 M 6 0 L 3 -45"
|
d="M -6 0 L -3 -45 M 6 0 L 3 -45"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1.5"
|
strokeWidth={1.5 * strokeMultiplier}
|
||||||
strokeOpacity="0.3"
|
strokeOpacity="0.3"
|
||||||
/>
|
/>
|
||||||
<line
|
<line
|
||||||
@@ -361,7 +362,7 @@ export default function HeroIllustration() {
|
|||||||
x2="12"
|
x2="12"
|
||||||
y2="-40"
|
y2="-40"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
strokeOpacity="0.2"
|
strokeOpacity="0.2"
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
@@ -380,7 +381,7 @@ export default function HeroIllustration() {
|
|||||||
fill="white"
|
fill="white"
|
||||||
fillOpacity="0.08"
|
fillOpacity="0.08"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
strokeOpacity="0.2"
|
strokeOpacity="0.2"
|
||||||
/>
|
/>
|
||||||
<path
|
<path
|
||||||
@@ -388,7 +389,7 @@ export default function HeroIllustration() {
|
|||||||
fill="white"
|
fill="white"
|
||||||
fillOpacity="0.05"
|
fillOpacity="0.05"
|
||||||
stroke="white"
|
stroke="white"
|
||||||
strokeWidth="1"
|
strokeWidth={1 * strokeMultiplier}
|
||||||
strokeOpacity="0.15"
|
strokeOpacity="0.15"
|
||||||
/>
|
/>
|
||||||
</g>
|
</g>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ featuredImage: /uploads/2026/01/1767353529807.jpg
|
|||||||
locale: de
|
locale: de
|
||||||
category: Kabel Technologie
|
category: Kabel Technologie
|
||||||
excerpt: 'KLZ Cables startet mit einer starken Verstärkung ins neue Jahr: Johannes Gleich übernimmt die Rolle des Senior Key Account Managers. Erfahren Sie mehr über unseren neuen Experten für Infrastruktur und Energieversorger.'
|
excerpt: 'KLZ Cables startet mit einer starken Verstärkung ins neue Jahr: Johannes Gleich übernimmt die Rolle des Senior Key Account Managers. Erfahren Sie mehr über unseren neuen Experten für Infrastruktur und Energieversorger.'
|
||||||
|
public: false
|
||||||
---
|
---
|
||||||
# Herzlich willkommen bei KLZ: Johannes Gleich startet als Senior Key Account Manager durch
|
# Herzlich willkommen bei KLZ: Johannes Gleich startet als Senior Key Account Manager durch
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ featuredImage: /uploads/2026/01/1767353529807.jpg
|
|||||||
locale: en
|
locale: en
|
||||||
category: Cable Technology
|
category: Cable Technology
|
||||||
excerpt: 'KLZ Cables kicks off the new year with a strong addition: Johannes Gleich takes on the role of Senior Key Account Manager. Learn more about our new expert for infrastructure and energy suppliers.'
|
excerpt: 'KLZ Cables kicks off the new year with a strong addition: Johannes Gleich takes on the role of Senior Key Account Manager. Learn more about our new expert for infrastructure and energy suppliers.'
|
||||||
|
public: false
|
||||||
---
|
---
|
||||||
# Welcome to KLZ: Johannes Gleich starts as Senior Key Account Manager
|
# Welcome to KLZ: Johannes Gleich starts as Senior Key Account Manager
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ NODE_ENV=production
|
|||||||
NEXT_PUBLIC_BASE_URL=https://klz-cables.com
|
NEXT_PUBLIC_BASE_URL=https://klz-cables.com
|
||||||
|
|
||||||
# Analytics (Umami)
|
# Analytics (Umami)
|
||||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID=your-umami-website-id
|
UMAMI_WEBSITE_ID=your-umami-website-id
|
||||||
NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://analytics.infra.mintel.me/script.js
|
NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://analytics.infra.mintel.me/script.js
|
||||||
|
|
||||||
# Error Tracking (GlitchTip/Sentry)
|
# Error Tracking (GlitchTip/Sentry)
|
||||||
|
|||||||
23
lib/blog.ts
23
lib/blog.ts
@@ -2,6 +2,7 @@ import fs from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import matter from 'gray-matter';
|
import matter from 'gray-matter';
|
||||||
import { mapSlugToFileSlug } from './slugs';
|
import { mapSlugToFileSlug } from './slugs';
|
||||||
|
import { config } from '@/lib/config';
|
||||||
|
|
||||||
export interface PostFrontmatter {
|
export interface PostFrontmatter {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -10,6 +11,7 @@ export interface PostFrontmatter {
|
|||||||
featuredImage?: string | null;
|
featuredImage?: string | null;
|
||||||
category?: string;
|
category?: string;
|
||||||
locale: string;
|
locale: string;
|
||||||
|
public?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PostMdx {
|
export interface PostMdx {
|
||||||
@@ -18,6 +20,17 @@ export interface PostMdx {
|
|||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isPostVisible(post: { frontmatter: { date: string; public?: boolean } }) {
|
||||||
|
// If explicitly marked as not public, hide in production
|
||||||
|
if (post.frontmatter.public === false && config.isProduction) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const postDate = new Date(post.frontmatter.date);
|
||||||
|
const now = new Date();
|
||||||
|
return !(postDate > now && config.isProduction);
|
||||||
|
}
|
||||||
|
|
||||||
export async function getPostBySlug(slug: string, locale: string): Promise<PostMdx | null> {
|
export async function getPostBySlug(slug: string, locale: string): Promise<PostMdx | null> {
|
||||||
// Map translated slug to file slug
|
// Map translated slug to file slug
|
||||||
const fileSlug = await mapSlugToFileSlug(slug, locale);
|
const fileSlug = await mapSlugToFileSlug(slug, locale);
|
||||||
@@ -31,11 +44,17 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostM
|
|||||||
const fileContent = fs.readFileSync(filePath, 'utf8');
|
const fileContent = fs.readFileSync(filePath, 'utf8');
|
||||||
const { data, content } = matter(fileContent);
|
const { data, content } = matter(fileContent);
|
||||||
|
|
||||||
return {
|
const postInfo = {
|
||||||
slug: fileSlug,
|
slug: fileSlug,
|
||||||
frontmatter: data as PostFrontmatter,
|
frontmatter: data as PostFrontmatter,
|
||||||
content,
|
content,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!isPostVisible(postInfo)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return postInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
||||||
@@ -55,6 +74,7 @@ export async function getAllPosts(locale: string): Promise<PostMdx[]> {
|
|||||||
content,
|
content,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
.filter(isPostVisible)
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) => new Date(b.frontmatter.date).getTime() - new Date(a.frontmatter.date).getTime(),
|
(a, b) => new Date(b.frontmatter.date).getTime() - new Date(a.frontmatter.date).getTime(),
|
||||||
);
|
);
|
||||||
@@ -78,6 +98,7 @@ export async function getAllPostsMetadata(locale: string): Promise<Partial<PostM
|
|||||||
frontmatter: data as PostFrontmatter,
|
frontmatter: data as PostFrontmatter,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
.filter(isPostVisible)
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
new Date(b.frontmatter.date as string).getTime() -
|
new Date(b.frontmatter.date as string).getTime() -
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function createConfig() {
|
|||||||
|
|
||||||
analytics: {
|
analytics: {
|
||||||
umami: {
|
umami: {
|
||||||
websiteId: env.NEXT_PUBLIC_UMAMI_WEBSITE_ID || env.UMAMI_WEBSITE_ID,
|
websiteId: env.UMAMI_WEBSITE_ID,
|
||||||
apiEndpoint: env.UMAMI_API_ENDPOINT || 'https://analytics.infra.mintel.me',
|
apiEndpoint: env.UMAMI_API_ENDPOINT || 'https://analytics.infra.mintel.me',
|
||||||
enabled: typeof window !== 'undefined' || Boolean(env.UMAMI_WEBSITE_ID),
|
enabled: typeof window !== 'undefined' || Boolean(env.UMAMI_WEBSITE_ID),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ const booleanSchema = z.preprocess((val) => {
|
|||||||
const envExtension = {
|
const envExtension = {
|
||||||
// Project specific overrides or additions
|
// Project specific overrides or additions
|
||||||
AUTH_COOKIE_NAME: z.string().default('klz_gatekeeper_session'),
|
AUTH_COOKIE_NAME: z.string().default('klz_gatekeeper_session'),
|
||||||
|
TARGET: z.string().optional(),
|
||||||
|
NEXT_PUBLIC_TARGET: z.string().optional(),
|
||||||
|
|
||||||
// Gatekeeper specifics not in base
|
// Gatekeeper specifics not in base
|
||||||
GATEKEEPER_URL: z.string().url().default('http://gatekeeper:3000'),
|
GATEKEEPER_URL: z.string().url().default('http://gatekeeper:3000'),
|
||||||
@@ -31,7 +33,7 @@ const envExtension = {
|
|||||||
INFRA_DIRECTUS_TOKEN: z.string().optional(),
|
INFRA_DIRECTUS_TOKEN: z.string().optional(),
|
||||||
|
|
||||||
// Analytics
|
// Analytics
|
||||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string().optional(),
|
UMAMI_WEBSITE_ID: z.string().optional(),
|
||||||
UMAMI_API_ENDPOINT: z.string().optional(),
|
UMAMI_API_ENDPOINT: z.string().optional(),
|
||||||
|
|
||||||
// Mail Configuration
|
// Mail Configuration
|
||||||
|
|||||||
@@ -23,11 +23,28 @@ export default function imgproxyLoader({
|
|||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if src contains custom gravity query parameter
|
||||||
|
let gravity = 'sm'; // Use smart gravity (content-aware) by default
|
||||||
|
let cleanSrc = src;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Dummy base needed for relative URLs
|
||||||
|
const url = new URL(src, 'http://localhost');
|
||||||
|
const customGravity = url.searchParams.get('gravity');
|
||||||
|
if (customGravity) {
|
||||||
|
gravity = customGravity;
|
||||||
|
url.searchParams.delete('gravity');
|
||||||
|
cleanSrc = src.startsWith('http') ? url.href : url.pathname + url.search;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback if parsing fails
|
||||||
|
}
|
||||||
|
|
||||||
// We use the width provided by Next.js for responsive images
|
// We use the width provided by Next.js for responsive images
|
||||||
// Height is set to 0 to maintain aspect ratio
|
// Height is set to 0 to maintain aspect ratio
|
||||||
return getImgproxyUrl(src, {
|
return getImgproxyUrl(cleanSrc, {
|
||||||
width,
|
width,
|
||||||
resizing_type: 'fit',
|
resizing_type: 'fit',
|
||||||
gravity: 'sm', // Use smart gravity (content-aware) instead of face detection (requires ML)
|
gravity,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export interface AnalyticsService {
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Key Features:**
|
**Key Features:**
|
||||||
|
|
||||||
- Type-safe event properties
|
- Type-safe event properties
|
||||||
- Consistent API across implementations
|
- Consistent API across implementations
|
||||||
- Well-documented with JSDoc comments
|
- Well-documented with JSDoc comments
|
||||||
@@ -39,6 +40,7 @@ export interface AnalyticsService {
|
|||||||
Implements the `AnalyticsService` interface for Umami analytics.
|
Implements the `AnalyticsService` interface for Umami analytics.
|
||||||
|
|
||||||
**Features:**
|
**Features:**
|
||||||
|
|
||||||
- Type-safe event tracking
|
- Type-safe event tracking
|
||||||
- Automatic pageview tracking
|
- Automatic pageview tracking
|
||||||
- Browser environment detection
|
- Browser environment detection
|
||||||
@@ -46,6 +48,7 @@ Implements the `AnalyticsService` interface for Umami analytics.
|
|||||||
- Comprehensive JSDoc documentation
|
- Comprehensive JSDoc documentation
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { UmamiAnalyticsService } from '@/lib/services/analytics/umami-analytics-service';
|
import { UmamiAnalyticsService } from '@/lib/services/analytics/umami-analytics-service';
|
||||||
|
|
||||||
@@ -59,12 +62,14 @@ service.trackPageview('/products/123');
|
|||||||
A no-op implementation used as a fallback when analytics are disabled.
|
A no-op implementation used as a fallback when analytics are disabled.
|
||||||
|
|
||||||
**Features:**
|
**Features:**
|
||||||
|
|
||||||
- Maintains the same API as other services
|
- Maintains the same API as other services
|
||||||
- Safe to call even when analytics are disabled
|
- Safe to call even when analytics are disabled
|
||||||
- No performance impact
|
- No performance impact
|
||||||
- Comprehensive JSDoc documentation
|
- Comprehensive JSDoc documentation
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { NoopAnalyticsService } from '@/lib/services/analytics/noop-analytics-service';
|
import { NoopAnalyticsService } from '@/lib/services/analytics/noop-analytics-service';
|
||||||
|
|
||||||
@@ -79,7 +84,7 @@ The service layer automatically selects the appropriate implementation based on
|
|||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// In lib/services/create-services.ts
|
// In lib/services/create-services.ts
|
||||||
const umamiEnabled = Boolean(process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID);
|
const umamiEnabled = Boolean(process.env.UMAMI_WEBSITE_ID);
|
||||||
|
|
||||||
const analytics = umamiEnabled
|
const analytics = umamiEnabled
|
||||||
? new UmamiAnalyticsService({ enabled: true })
|
? new UmamiAnalyticsService({ enabled: true })
|
||||||
@@ -91,7 +96,7 @@ const analytics = umamiEnabled
|
|||||||
### Required for Umami
|
### Required for Umami
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
NEXT_PUBLIC_UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
UMAMI_WEBSITE_ID=59a7db94-0100-4c7e-98ef-99f45b17f9c3
|
||||||
```
|
```
|
||||||
|
|
||||||
### Optional (defaults provided)
|
### Optional (defaults provided)
|
||||||
@@ -109,10 +114,12 @@ NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://analytics.infra.mintel.me/script.js
|
|||||||
Track a custom event with optional properties.
|
Track a custom event with optional properties.
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
|
|
||||||
- `eventName` - The name of the event to track
|
- `eventName` - The name of the event to track
|
||||||
- `props` - Optional event properties (metadata)
|
- `props` - Optional event properties (metadata)
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
service.track('product_add_to_cart', {
|
service.track('product_add_to_cart', {
|
||||||
product_id: '123',
|
product_id: '123',
|
||||||
@@ -127,9 +134,11 @@ service.track('product_add_to_cart', {
|
|||||||
Track a pageview.
|
Track a pageview.
|
||||||
|
|
||||||
**Parameters:**
|
**Parameters:**
|
||||||
|
|
||||||
- `url` - The URL to track (defaults to current location)
|
- `url` - The URL to track (defaults to current location)
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// Track current page
|
// Track current page
|
||||||
service.trackPageview();
|
service.trackPageview();
|
||||||
@@ -147,9 +156,11 @@ new UmamiAnalyticsService(options: UmamiAnalyticsServiceOptions)
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Options:**
|
**Options:**
|
||||||
|
|
||||||
- `enabled: boolean` - Whether analytics are enabled
|
- `enabled: boolean` - Whether analytics are enabled
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const service = new UmamiAnalyticsService({ enabled: true });
|
const service = new UmamiAnalyticsService({ enabled: true });
|
||||||
```
|
```
|
||||||
@@ -159,10 +170,11 @@ const service = new UmamiAnalyticsService({ enabled: true });
|
|||||||
#### Constructor
|
#### Constructor
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
new NoopAnalyticsService()
|
new NoopAnalyticsService();
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const service = new NoopAnalyticsService();
|
const service = new NoopAnalyticsService();
|
||||||
```
|
```
|
||||||
@@ -172,13 +184,11 @@ const service = new NoopAnalyticsService();
|
|||||||
### AnalyticsEventProperties
|
### AnalyticsEventProperties
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
type AnalyticsEventProperties = Record<
|
type AnalyticsEventProperties = Record<string, string | number | boolean | null | undefined>;
|
||||||
string,
|
|
||||||
string | number | boolean | null | undefined
|
|
||||||
>;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
const properties: AnalyticsEventProperties = {
|
const properties: AnalyticsEventProperties = {
|
||||||
product_id: '123',
|
product_id: '123',
|
||||||
@@ -253,7 +263,7 @@ services.analytics.track('button_click', {
|
|||||||
The service layer gracefully handles disabled analytics:
|
The service layer gracefully handles disabled analytics:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
// When NEXT_PUBLIC_UMAMI_WEBSITE_ID is not set:
|
// When UMAMI_WEBSITE_ID is not set:
|
||||||
// - NoopAnalyticsService is used
|
// - NoopAnalyticsService is used
|
||||||
// - All calls are safe (no-op)
|
// - All calls are safe (no-op)
|
||||||
// - No errors are thrown
|
// - No errors are thrown
|
||||||
@@ -366,13 +376,13 @@ import { getAppServices } from '@/lib/services/create-services';
|
|||||||
|
|
||||||
async function MyServerComponent() {
|
async function MyServerComponent() {
|
||||||
const services = getAppServices();
|
const services = getAppServices();
|
||||||
|
|
||||||
// Note: Analytics won't work in server components
|
// Note: Analytics won't work in server components
|
||||||
// Use client components for analytics tracking
|
// Use client components for analytics tracking
|
||||||
// But you can still access other services like cache
|
// But you can still access other services like cache
|
||||||
|
|
||||||
const data = await services.cache.get('key');
|
const data = await services.cache.get('key');
|
||||||
|
|
||||||
return <div>{data}</div>;
|
return <div>{data}</div>;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -382,14 +392,16 @@ async function MyServerComponent() {
|
|||||||
### Analytics Not Working
|
### Analytics Not Working
|
||||||
|
|
||||||
1. **Check environment variables:**
|
1. **Check environment variables:**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo $NEXT_PUBLIC_UMAMI_WEBSITE_ID
|
echo $UMAMI_WEBSITE_ID
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Verify service selection:**
|
2. **Verify service selection:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { getAppServices } from '@/lib/services/create-services';
|
import { getAppServices } from '@/lib/services/create-services';
|
||||||
|
|
||||||
const services = getAppServices();
|
const services = getAppServices();
|
||||||
console.log(services.analytics); // Should be UmamiAnalyticsService
|
console.log(services.analytics); // Should be UmamiAnalyticsService
|
||||||
```
|
```
|
||||||
@@ -401,12 +413,12 @@ async function MyServerComponent() {
|
|||||||
|
|
||||||
### Common Issues
|
### Common Issues
|
||||||
|
|
||||||
| Issue | Solution |
|
| Issue | Solution |
|
||||||
|-------|----------|
|
| ------------------- | ----------------------------------- |
|
||||||
| No data in Umami | Check website ID and script URL |
|
| No data in Umami | Check website ID and script URL |
|
||||||
| Events not tracking | Verify service is being used |
|
| Events not tracking | Verify service is being used |
|
||||||
| Script not loading | Check network connection, CORS |
|
| Script not loading | Check network connection, CORS |
|
||||||
| Wrong data | Verify event properties are correct |
|
| Wrong data | Verify event properties are correct |
|
||||||
|
|
||||||
## Related Files
|
## Related Files
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import type { AnalyticsEventProperties, AnalyticsService } from './analytics-ser
|
|||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* // Automatic fallback in create-services.ts
|
* // Automatic fallback in create-services.ts
|
||||||
* const umamiEnabled = Boolean(process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID);
|
* const umamiEnabled = Boolean(process.env.UMAMI_WEBSITE_ID);
|
||||||
* const analytics = umamiEnabled
|
* const analytics = umamiEnabled
|
||||||
* ? new UmamiAnalyticsService({ enabled: true })
|
* ? new UmamiAnalyticsService({ enabled: true })
|
||||||
* : new NoopAnalyticsService(); // Fallback when no website ID
|
* : new NoopAnalyticsService(); // Fallback when no website ID
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ let singleton: AppServices | undefined;
|
|||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
* // Automatic service selection based on environment
|
* // Automatic service selection based on environment
|
||||||
* // If NEXT_PUBLIC_UMAMI_WEBSITE_ID is set:
|
* // If UMAMI_WEBSITE_ID is set:
|
||||||
* // services.analytics = UmamiAnalyticsService
|
* // services.analytics = UmamiAnalyticsService
|
||||||
* // If not set:
|
* // If not set:
|
||||||
* // services.analytics = NoopAnalyticsService (safe no-op)
|
* // services.analytics = NoopAnalyticsService (safe no-op)
|
||||||
|
|||||||
Reference in New Issue
Block a user