Skip to content

ServerTrack-Official/Angular-Server-Side-Tracking-with-ServerTrack.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

Angular ServerTrack Demo

A complete e-commerce demo application built with Angular 17, 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

  • Angular 17 - Frontend framework
  • TypeScript - Strongly typed JavaScript
  • Standalone Components - No NgModule required
  • ServerTrack.io - Server-side tracking

Installation

  1. Clone this repository
  2. Install dependencies:
npm install
  1. Configure ServerTrack in src/index.html:
const AUTH_KEY = 'YOUR_AUTH_KEY'        // Replace with your authentication key
const SERVER_DOMAIN = 'some.website.com' // Replace with your ServerTrack endpoint

Usage

Development

npm start

Build for Production

npm run build

Project Structure

Angular-ServerTrack-Demo/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ product-list/
β”‚   β”‚   β”‚   β”‚   └── product-list.component.ts    # Product grid display
β”‚   β”‚   β”‚   β”œβ”€β”€ product-view/
β”‚   β”‚   β”‚   β”‚   └── product-view.component.ts    # Single product detail
β”‚   β”‚   β”‚   β”œβ”€β”€ checkout/
β”‚   β”‚   β”‚   β”‚   └── checkout.component.ts        # Checkout page
β”‚   β”‚   β”‚   └── success/
β”‚   β”‚   β”‚       └── success.component.ts         # Order confirmation
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   └── product.model.ts                 # Product interface
β”‚   β”‚   └── app.component.ts                     # Root component
β”‚   β”œβ”€β”€ index.html                               # ServerTrack SDK init
β”‚   β”œβ”€β”€ main.ts                                  # App entry point
β”‚   └── styles.css                               # Global styles
β”œβ”€β”€ angular.json
β”œβ”€β”€ tsconfig.json
└── package.json

ServerTrack Integration

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

SDK Initialization

The SDK is initialized in src/index.html before the app loads:

const AUTH_KEY = 'YOUR_AUTH_KEY'        // Replace with your authentication key
const SERVER_DOMAIN = 'some.website.com' // Replace with your ServerTrack endpoint

ViewContent

Triggered when a user clicks on a product:

(window as any).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 as any).st('track', 'AddToCart', {
  content_ids: [product.id],
  content_type: 'product',
  value: product.price,
  currency: 'USD'
});

InitiateCheckout

Triggered automatically when the checkout component initializes using ngOnInit:

ngOnInit(): void {
  (window as any).st('track', 'InitiateCheckout', {
    value: this.getTotal(),
    currency: 'USD',
    content_type: 'product',
    num_items: this.cart.length,
    content_ids: this.cart.map(item => item.id),
    contents: this.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: this.formData.email,       // Email
  ph: this.formData.phone,       // Phone
  fn: this.formData.firstName,   // First Name
  ln: this.formData.lastName     // Last Name
};

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

Customization

  • Modify products in src/app/components/product-list/product-list.component.ts
  • Adjust styling in src/styles.css
  • Add more tracking events directly via (window as any).st('track', ...)

License

MIT

About

A complete e-commerce demo application built with Angular 17, showcasing server-side tracking integration with ServerTrack.io.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors