Comparing version 1.0.1 to 1.0.2
@@ -5,7 +5,7 @@ "use strict"; | ||
const axios = require('axios'); | ||
var API_SECRET; | ||
var MEASUREMENT_ID; | ||
var CLIENT_ID; | ||
var API_SECRET; // GA > Admin > Data Streams > choose your stream > Measurement Protocol > Create | ||
var MEASUREMENT_ID; // GA Admin > Data Streams > choose your stream > Measurement ID | ||
var CLIENT_ID; // https://developers.google.com/identity/one-tap/web/guides/get-google-api-clientid | ||
var GA_ENDPOINT; | ||
var TEST_ENDPOINT; | ||
var DEBUG_ENDPOINT; | ||
function setClient(apiSecret, measurementId, clientId) { | ||
@@ -16,3 +16,3 @@ API_SECRET = apiSecret; | ||
GA_ENDPOINT = `https://www.google-analytics.com/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`; | ||
TEST_ENDPOINT = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`; | ||
DEBUG_ENDPOINT = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`; | ||
} | ||
@@ -25,3 +25,3 @@ exports.setClient = setClient; | ||
console.log("GA_ENDPOINT: " + GA_ENDPOINT); | ||
console.log("TEST_ENDPOINT: " + TEST_ENDPOINT); | ||
console.log("DEBUG_ENDPOINT: " + DEBUG_ENDPOINT); | ||
} | ||
@@ -32,6 +32,6 @@ exports.readClient = readClient; | ||
// [{ | ||
name: 'tutorial_begin', | ||
name: <event_name>, | ||
params: {}, | ||
},{ | ||
name: 'tutorial_complete', | ||
name: <event_name>, | ||
params: {}, | ||
@@ -41,2 +41,4 @@ }] | ||
Can send up to 25 events at once | ||
Verify event and params here: | ||
https://developers.google.com/analytics/devguides/collection/ga4/events | ||
*/ | ||
@@ -48,3 +50,2 @@ function sendHit(events) { | ||
}).then(res => { | ||
console.log(`statusCode: ${res.statusCode}`); | ||
console.log(res); | ||
@@ -57,3 +58,3 @@ }).catch(error => { | ||
function testSendHit(events) { | ||
axios.post(TEST_ENDPOINT, { | ||
axios.post(DEBUG_ENDPOINT, { | ||
client_id: CLIENT_ID, | ||
@@ -60,0 +61,0 @@ events: events |
{ | ||
"name": "ga4-mp", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Send data to Google Analytics 4 using Measurement Protocol", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,7 +0,17 @@ | ||
Compatible with | ||
- node.js version 8+ | ||
# Google Analytics GA4 Measurement Protocol Library | ||
## Compatible with | ||
- Node.js version 8+ | ||
- es2015 | ||
//To use | ||
import {sayHello} from 'ga4-mp' | ||
sayHello(); | ||
## To use | ||
### Setup | ||
ga4mp = require('ga4-mp') | ||
ga4mp.setClient(apiSecret, measurementId, clientId); | ||
### Send Hits to GA4 Account | ||
ga4mp.sendHit(<events>) | ||
### Test Hits on GA4 MP debug endpoint | ||
ga4mp.testSendHit(<events>) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5552
79
18