New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

google-analytics-pageviews-api

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-analytics-pageviews-api

Can fetch view count for any path name on your GA property

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
1
Created
Source

Google Analytics API

An API for running core Google Analytics Report from Google Analytics Data API for GA4

Purpose

This project is created to remove needs of creating Google Analytics API for each individual project.

Prerequisites

  • Node.js

Features

  • Connect to Google Analytics Data API using Property ID and Service Account file path provided upon the instantiation of GoogleAnalyticsClient class

Installation

  • Run the following commands according to your project's npm manager
// npm
npm add google-analytics-pageviews-api
// yarn
yarn add google-analytics-pageviews-api
// pnpm
pnpm add google-analytics-pageviews-api

How to use

  • Input GA Property ID and Google Service Account File Path as params when instantiating the GoogleAnalyticsClient. (It is advised to set both parameters as ENV variables)
  • Access the class method to use the client
import { GoogleAnalyticsClient, PageviewsDto } from 'google-analytics-pageviews-api'

const gaPropertyID = '123456789'
const gaCredentialsPath = '/path/to/file'

const gaClient = new GoogleAnalyticsClient(gaPropertyID, gaCredentialsPath)

export async function getPageViews(articleSlug) {
  const pageViewsCount: PageviewsDto = await gaClient.getPageviews(`/articles/${articleSlug}`)
  return pageViewsCount?.viewCount || 0
}
// returned value: {pagePath: provided page path, viewCount: number of page views}

License

Copyright (c) 2023 MeCode

Keywords

google-analytics

FAQs

Package last updated on 12 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts