Skip to content

Conversation

@byteakp
Copy link

@byteakp byteakp commented Jun 12, 2025

✨ Centralize CPC and Metrics Calculation Logic

This PR introduces a new utility function, computeCPCMetrics, in @adobe/spacecat-shared-utils to centralize the logic for calculating CPC (Cost Per Click) and related metrics using organic traffic and RUM data. This logic was previously duplicated across multiple services.


🔧 Key Changes

  • New Utility Function

    • computeCPCMetrics is now available in @adobe/spacecat-shared-utils.
    • Accepts current and total RUM metrics and an array of organicTraffic metrics.
    • Returns:
      • cpc
      • pageViewsChange
      • ctrChange
      • projectedTrafficValue
  • Documentation

    • Updated API.md and README.md to include usage examples.
    • Updated index.d.ts with full type annotations for clarity.

💡 Motivation

  • 🚫 Removes duplicated CPC computation logic from:
    • spacecat-api-service
    • spacecat-import-worker
  • ✅ Provides a single, reusable, and testable utility for computing CPC-related metrics.

🧩 Usage

import { computeCPCMetrics } from '@adobe/spacecat-shared-utils';

const { cpc, pageViewsChange, ctrChange, projectedTrafficValue } = computeCPCMetrics({
  current: { totalPageViews, totalClicks, totalCTR },
  total: { totalPageViews, totalClicks, totalCTR },
  organicTraffic: [{ cost, value }],
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant