1.7.1 • Published 10 months ago

sveltick v1.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

āš”ļø Sveltick

Welcome to Sveltick! This is a super lightweight šŸ¦‹ and fun performance&traffic-tracking library for your Svelte apps.

āœ… v5 Svelte support

šŸ“¦ Latest Version 1.7.1

  • Adding tracking of Web traffic - šŸ‘ļø pageViews, šŸ§‘ā€šŸ¤ā€šŸ§‘ uniqueUsers, šŸ›£ļø visitedRoutes and šŸ”— trafficSources
  • Also possible to get each of them only
  • For the best experience we need to use onMount but also afterUpdate and use this code in our src/+layout.svelte for tracking traffic.
  • Fixing documentation

šŸ“„ Installation

Install Sveltick via npm:

npm install sveltick

Install Sveltick via yarn:

yarn add sveltick

šŸ”„ Quick Start

Import Sveltick into your Svelte app and start tracking your app's performance!

šŸ“ˆ Track everything you need and configure what metrics you want to see

  import { onMount } from 'svelte';
  import { runPerformanceTracker } from 'sveltick';

  onMount(() => {
    // Run the performance tracker with custom options
    runPerformanceTracker({
      trackMetrics: true,     // Track all metrics
      showAlerts: true,       // Enable alerts
      enableGamification: true, // Enable gamification
      thresholds:  {
        fcp: 1800,  // Custom threshold for FCP
        lcp: 2300,  // Custom threshold for LCP
        tti: 2800,  // Custom threshold for TTI
        cls: 0.15,  // Custom threshold for CLS
        fid: 100, // Custom threshold for FID
        inp: 200, // Custom threshold for INP
        ttfb: 800, // Custom threshold for TTFB
        componentRenderTime: 400 // Custom threshold for component render time
      }
    });
  });

šŸ“Œ Note: The thresholds object is optional, and each metric has a default value. If you don't provide a custom threshold for a particular metric, the following default values will be used:

  • First Contentful Paint (FCP): 2000ms
  • Largest Contentful Paint (LCP): 2500ms
  • Time to Interactive (TTI): 3000ms
  • Cumulative Layout Shift (CLS): 0.1
  • First Input Delay (FID): 100ms (User must interact with the page to track this metric)
  • Interaction to Next Paint (INP): 200ms (User must interact with the page to track this metric)
  • Time to First Byte (TTFB): 800ms
  • Component Render Time: 500ms

Tracking āš”ļø First Contentful Paint, šŸ•’Time to Interactive, šŸ“Largest Contentful Paint & šŸ“Š Cumulative Layout Shift, šŸ–±ļø First Input Delay, šŸ–Œļø Interaction to Next Paint, šŸ“” Time to First Byte

<script>
  import { onMount } from 'svelte';
  import { trackFirstContentfulPaint, trackTimeToInteractive, trackLargestContentfulPaint, trackCumulativeLayoutShift, trackFirstInputDelay, trackInteractionToNextPaint, trackTimeToFirstByte } from 'sveltick';

  onMount(async () => {
    const ftp = await trackFirstContentfulPaint()
    const tti = await trackTimeToInteractive()
    const lcp = await trackLargestContentfulPaint();
    const cls = await trackCumulativeLayoutShift();
    const fid = await trackFirstInputDelay();
    const inp = await trackInteractionToNextPaint();
    const ttfb = await trackTimeToFirstByte();

    console.log(ftp, tti, lcp, cls, fid, inp, ttfb)
  });

</script>

šŸ”§ Tracking Component Render Times

  import { onMount } from 'svelte';
  import { trackComponentRender } from 'sveltick';

	onMount(() => {
		const now = performance.now();  // Measure render time
		const { name, renderTime } = trackComponentRender('YourComponent', now);  // Get the name and render time
		console.log(name, renderTime);
	});

šŸ›  Performance Report

You can access all performance metrics (including components one) at any point using:

  import { onMount } from 'svelte';
  import { trackComponentRender, getPerformanceMetrics } from 'sveltick';

  onMount(async () => {
    const now = performance.now();  // Measure render time
    trackComponentRender('YourComponent', now);  // Get the name and render time
    const metrics = await getPerformanceMetrics();
    console.log(metrics)
  });

āš ļø Checking for all performance with custom threshold alerts

  import { onMount } from 'svelte';
  import { getPerformanceMetrics, checkPerformanceAlerts } from 'sveltick';

  onMount(async () => {
    const metrics = await getPerformanceMetrics();
    console.log('Updated Performance Metrics:', metrics);

    // Check for any performance alerts with custom thresholds
    checkPerformanceAlerts({
      fcp: 1800,  // Custom threshold for FCP
      lcp: 2300,  // Custom threshold for LCP
      tti: 2800,  // Custom threshold for TTI
      cls: 0.15,  // Custom threshold for CLS
      fid: 100, // Custom threshold for FID
      inp: 200, // Custom threshold for INP
      ttfb: 800, // Custom threshold for TTFB
      componentRenderTime: 400 // Custom threshold for component render time
    });
  });

šŸŽÆ Checking the score of your web based by the performance

  import { onMount } from 'svelte';
  import { runGamification } from 'sveltick';

  onMount(() => {
    // Run the gamification logic
    runGamification();
  });

Checking all traffic metrics

For the best experience we need to use onMount but also afterUpdate and use this code in our src/+layout.svelte.

  import { onMount, afterUpdate } from 'svelte';
  import { trackAllActivities } from 'sveltick';

	// Track all activities on component mount and update
	let trackedData = {};

	// This function will track and log activities when the component is mounted
	onMount(() => {
		trackedData = trackAllActivities();
		console.log('Tracked Data on Mount:', trackedData);
	});

	// This function will track and log activities every time the component is updated
	afterUpdate(() => {
		trackedData = trackAllActivities();
		console.log('Tracked Data after Update:', trackedData);
	});

Track Page Views

  import { onMount, afterUpdate } from 'svelte';
  import { trackAllActivities, getPageViews } from 'sveltick';

	let pageViews = 0;
  let trackedData = {};

	// This function will track and log activities when the component is mounted
	onMount(() => {
		trackedData = trackAllActivities();
		pageViews = getPageViews();
		console.log(pageViews)
	});

	// This function will track and log activities every time the component is updated
	afterUpdate(() => {
		trackedData = trackAllActivities();
		pageViews = getPageViews();
		console.log(pageViews)
	});

Track Unique Users

  import { onMount, afterUpdate } from 'svelte';
  import { trackAllActivities, getUniqueVisitors } from 'sveltick';

	let uniqueVisitors = 0;
  let trackedData = {};

	// This function will track and log activities when the component is mounted
	onMount(() => {
		trackedData = trackAllActivities();
		uniqueVisitors = getUniqueVisitors();
		console.log(uniqueVisitors)
	});

	// This function will track and log activities every time the component is updated
	afterUpdate(() => {
		trackedData = trackAllActivities();
		uniqueVisitors = getUniqueVisitors();
		console.log(uniqueVisitors)
	});

Track Route Visited

  import { onMount, afterUpdate } from 'svelte';
  import { trackAllActivities, getRouteViews } from 'sveltick';

  let routeViews = [];
  let trackedData = {};

	// This function will track and log activities when the component is mounted
	onMount(() => {
		trackedData = trackAllActivities();
		routeViews = getRouteViews();
		console.log(routeViews)
	});

	// This function will track and log activities every time the component is updated
	afterUpdate(() => {
		trackedData = trackAllActivities();
		routeViews = getRouteViews();
		console.log(routeViews)
	});

Track Traffic Sources

  • We have for now 4 sources from user comes and we differ it out - Direct, Facebook, Google and Others
  import { onMount, afterUpdate } from 'svelte';
  import { trackAllActivities, getTrafficSources} from 'sveltick';

  let trafficSources = {};
  let trackedData = {};

	// This function will track and log activities when the component is mounted
	onMount(() => {
		trackedData = trackAllActivities();
		trafficSources = getTrafficSources();
		console.log(trafficSources)
	});

	// This function will track and log activities every time the component is updated
	afterUpdate(() => {
		trackedData = trackAllActivities();
    trafficSources = getTrafficSources();
		console.log(trafficSources)
	});

šŸ“Š Metrics to check:

Performance

  • First Contentful Paint āš”ļø
  • Time to Interactive šŸ•’
  • Component Render Time šŸ”§
  • Largest Contentful Paint šŸ“
  • Cumulative Layout Shift šŸ“Š
  • First Input Delay šŸ–±ļø (Click-based)
  • Interaction to Next Paint šŸ–Œļø (Click-based)
  • Time to First Byte šŸ“”

🚦 Traffic

  • Page Views šŸ‘ļø
  • Unique Users šŸ§‘ā€šŸ¤ā€šŸ§‘
  • Visited Routes šŸ›£ļø
  • Traffic Sources šŸ”—

šŸ–±ļø First Input Delay (FID) & šŸ–Œļø Interaction to Next Paint (INP)

šŸ“Œ Note:

  • FID and INP metrics are triggered by user interactions like clicks. These metrics depend on actual user interaction events.
  • If no interaction occurs within 5 seconds, the FID and INP values will be set to null and won't impact the performance alerts or gamification score.

ā³ Coming up in next releases:

  1. Any events in page as page views, clicks per view etc...
  2. Plugin system - users can integrate other performance functions from other providers like Web Vitals or Lighthouse
  3. Integration with analytics platforms, like Google Analytics, Sentry or DataDog - data can be send to these providers
  4. Dashboard perfomance-tracker (docs website + dashboard)
  5. Visual showcase of the metrics (graphs)(probably on the dashboard web dont know yet)

Output example screenshot:

Sveltick Example

For now it is just this simple console info about the project (of course you could implement it into something bigger!). But in the upcoming days I will create a dashboard performance-tracking webapp for this library, where you could use Sveltick from anywhere around the globe! So stay tuned guys!

šŸ“œ License

MIT Ā©ļø Adam Stadnik

1.7.1

10 months ago

1.7.0

10 months ago

1.6.2

10 months ago

1.6.1

10 months ago

1.6.0

10 months ago

1.5.4

10 months ago

1.5.3

10 months ago

1.5.2

10 months ago

1.5.1

10 months ago

1.5.0

10 months ago

1.4.4

10 months ago

1.4.3

10 months ago

1.4.2

10 months ago

1.4.1

10 months ago

1.3.9

10 months ago

1.3.8

10 months ago

1.3.7

10 months ago

1.3.5

10 months ago

1.3.4

10 months ago

1.3.3

10 months ago

1.3.2

10 months ago

1.2.1

10 months ago

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.16

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago