Skip to content

ServerTrack-Official/Express.js-Server-Side-Tracking-with-ServerTrack.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Express.js Server-Side Tracking with ServerTrack.io

A complete e-commerce demo application built with Express.js and Node.js, showcasing server-side tracking integration with ServerTrack.io.

Features

  • πŸ›οΈ Product listing and detail pages
  • πŸ›’ Shopping cart functionality
  • πŸ’³ Checkout flow
  • πŸ“Š Complete e-commerce event tracking:
    • ViewContent - Product view tracking
    • AddToCart - Add to cart events
    • InitiateCheckout - Checkout initiation
    • Purchase - Transaction completion

Tech Stack

  • Express.js - Node.js web framework
  • Node.js - JavaScript runtime
  • Vanilla JS - Frontend (no framework)
  • LocalStorage - Client-side cart management
  • ServerTrack.io - Server-side tracking

Installation

  1. Clone this repository
  2. Install dependencies:
npm install
  1. Configure ServerTrack in public/js/servertrack.js:
const AUTH_KEY = 'YOUR_AUTH_KEY'
const SERVER_DOMAIN = 'some.website.com'

Usage

Development

npm run dev

Production

npm start

Project Structure

Express.js-ServerTrack-Demo/
β”œβ”€β”€ views/
β”‚   β”œβ”€β”€ index.html       # Product listing page
β”‚   β”œβ”€β”€ product.html     # Product detail page
β”‚   β”œβ”€β”€ checkout.html    # Checkout page
β”‚   └── success.html     # Order confirmation
β”œβ”€β”€ public/
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css    # Global styles
β”‚   └── js/
β”‚       β”œβ”€β”€ servertrack.js   # ServerTrack integration
β”‚       β”œβ”€β”€ products.js      # Product listing logic
β”‚       └── checkout.js      # Checkout logic
└── server.js            # Express server

ServerTrack Integration

The demo uses the ServerTrack.io SDK and tracks the following e-commerce events:

SDK Initialization

The SDK is initialized in public/js/servertrack.js and included in every page:

const AUTH_KEY = 'YOUR_AUTH_KEY'
const SERVER_DOMAIN = 'some.website.com'

ViewContent

Triggered when a user clicks on a product image:

window.st('track', 'ViewContent', {
  content_ids: [product.id],
  content_type: 'product',
  content_name: product.name,
  value: product.price,
  currency: 'USD'
})

AddToCart

Triggered when a user adds a product to cart:

window.st('track', 'AddToCart', {
  content_ids: [product.id],
  content_type: 'product',
  content_name: product.name,
  value: product.price,
  currency: 'USD'
})

InitiateCheckout

Triggered automatically when the checkout page loads:

window.st('track', 'InitiateCheckout', {
  value: total,
  currency: 'USD',
  content_type: 'product',
  num_items: cart.length,
  content_ids: cart.map(item => item.id),
  contents: cart.map(item => ({
    id: item.id,
    quantity: 1,
    item_price: item.price
  }))
})

Purchase (with Advanced Matching)

Triggered on form submit with user data for advanced matching:

const userData = {
  em: email,       // Email
  ph: phone,       // Phone
  fn: firstName,   // First Name
  ln: lastName     // Last Name
}

window.st('track', 'Purchase', {
  transaction_id: 'ORD-' + Date.now(),
  value: total,
  currency: 'USD',
  content_type: 'product',
  num_items: cart.length,
  content_ids: cart.map(item => item.id),
  contents: cart.map(item => ({
    id: item.id,
    quantity: 1,
    item_price: item.price
  }))
}, userData)

Customization

  • Modify products in public/js/products.js
  • Adjust styling in public/css/style.css
  • Add more tracking events in public/js/servertrack.js

License

MIT

About

A complete e-commerce demo application built with Express.js and Node.js, showcasing server-side tracking integration with ServerTrack.io.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors