0.4.0 • Published 2 years ago

@d-gs/google-analytics-js v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

google-analytics-js

This package is available for Google Analytics V4 (gtag).

Install

npm i @d-gs/google-analytics-js

or

pnpm add @d-gs/google-analytics-js

Usage

In some.js(ts)

import { googleAnalyticsJs } from '@d-gs/google-analytics-js'
const ga = googleAnalyticsJs(
  ['G-XXXXXXXXXX', 'G-XXXXXXXXXX'],  // Your measurement ids (required)
  {  // Options
    forceEnabled: boolean,  // (default: false)
    stateKey: string,  // localStorage key (default: `enabledGa`)
    scriptId: string  // gtag script id (default: `GoogleTagManagerScript`)
  }
)

// If you agree, you will be initialized and Google Analytics will be activated.
ga.agree()

// If you disagree, Google Analytics will not work.
ga.disagree()

// Return 'agree' | 'disagree' | 'pending'
ga.getApprovalStatus()

// Return to 'pending' status
ga.reset()

// Send event
ga.sendEvent(
  'contact_complete',
  {
    category: 'Contact'
  }
)

Warning

When forceEnabled is true, "page_view" will be sent to Google Analytics without the user's permission

0.4.0-beta.0

2 years ago

0.4.0

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago