Loading page
escF1F2F3F4F5F6F7F8F9F10F11F12
~`!1@2#3$4%5^6&7*8(9)0_-+=delete
tabQWERTYUIOP{[}]|\
caps lockASDFGHJKL:;"'return
shiftZXCVBNM<,>.?/shift
fn⌃control⌥option⌘command⌘command⌥option◀▲▼▶
“Bounce it, sleep on it, listen again tomorrow.”
Learn how we built a sophisticated pixel tracking system that allows music artists to configure Facebook Pixel, Google Analytics, and TikTok Pixel at team, track, and album levels for precise conversion tracking
Music artists need to track conversions and user behavior across their digital presence, but existing solutions are often too generic or don't account for the hierarchical nature of music content. We needed a system that could track pixels at multiple levels: team-wide, per-album, and per-track, with intelligent fallbacks and precise event tracking.
We built a sophisticated pixel tracking system that allows artists to configure Facebook Pixel, Google Analytics, and TikTok Pixel IDs at different levels. The system automatically detects the most specific pixel ID available and tracks relevant events based on the content type being viewed.
// Priority System: Track > Album > Team
const activePixelId = trackPixelId || albumPixelId || teamPixelId
// Event Tracking Based on URL Patterns
if (pathname.includes('/tracks/')) {
// Track-specific events
trackEvent('ViewContent', { content_type: 'track' })
} else if (pathname.includes('/albums/')) {
// Album-specific events
trackEvent('ViewContent', { content_type: 'album' })
} else if (pathname.includes('/@')) {
// Artist profile events
trackEvent('ViewContent', { content_type: 'artist_profile' })
}
We extended our existing database schema to support pixel IDs at multiple levels. Each table (teams, tracks, albums) now includes fields for Facebook Pixel, Google Analytics, and TikTok Pixel IDs, allowing artists to configure tracking at the most appropriate level.
-- Add pixel tracking fields to teams table
ALTER TABLE teams
ADD COLUMN facebook_pixel_id TEXT,
ADD COLUMN google_analytics_id TEXT,
ADD COLUMN tiktok_pixel_id TEXT;
-- Add pixel tracking fields to tracks table
ALTER TABLE tracks
ADD COLUMN facebook_pixel_id TEXT,
ADD COLUMN google_analytics_id TEXT,
ADD COLUMN tiktok_pixel_id TEXT;
-- Add pixel tracking fields to albums table
ALTER TABLE albums
ADD COLUMN facebook_pixel_id TEXT,
ADD COLUMN google_analytics_id TEXT,
ADD COLUMN tiktok_pixel_id TEXT;
We updated our TypeScript database types to include the new pixel fields, ensuring type safety across the application. This prevents runtime errors and provides excellent developer experience with autocomplete and type checking.
interface TeamsTable {
id: number
name: string
// ... existing fields
facebook_pixel_id: string | null
google_analytics_id: string | null
tiktok_pixel_id: string | null
}
interface TracksTable {
id: number
title: string
// ... existing fields
facebook_pixel_id: string | null
google_analytics_id: string | null
tiktok_pixel_id: string | null
}
interface AlbumsTable {
id: number
title: string
// ... existing fields
facebook_pixel_id: string | null
google_analytics_id: string | null
tiktok_pixel_id: string | null
}
We built a modular component system that handles each pixel type independently. The main PixelTracking component orchestrates the loading of individual pixel components, each responsible for their specific tracking implementation.
// Main orchestrator component
export function PixelTracking({
teamFacebookPixelId,
trackFacebookPixelId,
albumFacebookPixelId,
// ... other pixel IDs
}) {
return (
<Suspense fallback={null}>
<FacebookPixel
teamPixelId={teamFacebookPixelId}
trackPixelId={trackFacebookPixelId}
albumPixelId={albumFacebookPixelId}
/>
<GoogleAnalytics
teamTrackingId={teamGoogleAnalyticsId}
trackTrackingId={trackGoogleAnalyticsId}
albumTrackingId={albumGoogleAnalyticsId}
/>
<TikTokPixel
teamPixelId={teamTikTokPixelId}
trackPixelId={trackTikTokPixelId}
albumPixelId={albumTikTokPixelId}
/>
</Suspense>
);
}
We implemented Facebook Pixel tracking using the react-facebook-pixel package. The component automatically initializes the pixel with the appropriate ID and tracks PageView and ViewContent events based on the current page context.
export function FacebookPixel({ teamPixelId, trackPixelId, albumPixelId }) {
const pathname = usePathname()
// Priority: track > album > team
const activePixelId = trackPixelId || albumPixelId || teamPixelId
useEffect(() => {
if (!activePixelId) return
const initPixel = async () => {
const { default: ReactPixel } = await import('react-facebook-pixel')
ReactPixel.init(activePixelId)
ReactPixel.pageView()
// Track custom events based on page type
if (pathname.includes('/tracks/')) {
ReactPixel.track('ViewContent', {
content_type: 'track',
content_ids: [pathname.split('/').pop()],
content_category: 'music',
})
}
}
initPixel()
}, [activePixelId, pathname])
return null
}
For Google Analytics, we implemented GA4 tracking using the global gtag function. The component tracks page views and custom events, providing detailed analytics about user behavior across different content types.
export function GoogleAnalytics({
teamTrackingId,
trackTrackingId,
albumTrackingId,
}) {
const pathname = usePathname()
const activeTrackingId =
trackTrackingId || albumTrackingId || teamTrackingId
useEffect(() => {
if (!activeTrackingId) return
if (typeof window !== 'undefined' && (window as any).gtag) {
// Initialize GA4
;(window as any).gtag('config', activeTrackingId, {
page_path: pathname,
})
// Track custom events
if (pathname.includes('/tracks/')) {
;(window as any).gtag('event', 'view_item', {
item_id: pathname.split('/').pop(),
item_category: 'track',
content_type: 'music',
})
}
}
}, [activeTrackingId, pathname])
return null
}
TikTok Pixel tracking was implemented using the tiktok-pixel package. This provides comprehensive tracking for TikTok advertising campaigns, allowing artists to measure the effectiveness of their TikTok marketing efforts.
export function TikTokPixel({ teamPixelId, trackPixelId, albumPixelId }) {
const pathname = usePathname()
const activePixelId = trackPixelId || albumPixelId || teamPixelId
useEffect(() => {
if (!activePixelId) return
const initPixel = async () => {
const { default: TikTokPixel } = await import('tiktok-pixel')
TikTokPixel.init(activePixelId)
TikTokPixel.pageView()
// Track custom events
if (pathname.includes('/tracks/')) {
TikTokPixel.track('ViewContent', {
content_id: pathname.split('/').pop(),
content_type: 'track',
content_category: 'music',
})
}
}
initPixel()
}, [activePixelId, pathname])
return null
}
We implemented several performance optimizations to ensure pixel tracking doesn't impact page load times. Components are loaded asynchronously, pixel initialization is deferred until needed, and we use Suspense boundaries for smooth loading.
// Async pixel loading
const initPixel = async () => {
try {
const { default: ReactPixel } = await import('react-facebook-pixel');
ReactPixel.init(activePixelId);
ReactPixel.pageView();
} catch (error) {
console.error('Failed to initialize pixel:', error);
}
};
// Suspense boundaries for smooth loading
<Suspense fallback={null}>
<PixelTracking
teamFacebookPixelId={team.facebook_pixel_id}
// ... other props
/>
</Suspense>
// Conditional loading
useEffect(() => {
if (!activePixelId) return; // Only load if pixel ID exists
initPixel();
}, [activePixelId]);
Artists can now set a pixel at team, track or album level. The system resolves which ID wins, records the events, and runs inside the existing platform rather than beside it.
Building a multi-level pixel tracking system for music artists required careful consideration of database design, component architecture, and performance optimization. The result holds up as catalogues grow, and it answers the question artists actually ask: did that campaign sell anything.
The key to success was creating a system that's both powerful and easy to use, with intelligent defaults and clear configuration options.