Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions google-analytics-admin/.eslintrc.json

This file was deleted.

40 changes: 40 additions & 0 deletions google-analytics-admin/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {defineConfig} from 'eslint/config';
import globals from 'globals';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import js from '@eslint/js';
import {FlatCompat} from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

const googleConfig = compat.extends('google');
for (const config of googleConfig) {
if (config.rules) {
delete config.rules['valid-jsdoc'];
delete config.rules['require-jsdoc'];
}
}

export default defineConfig([
...googleConfig,
{
files: ['*.js'],
languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
},

ecmaVersion: 'latest',
sourceType: 'script',
},

rules: {},
},
]);
7 changes: 5 additions & 2 deletions google-analytics-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=18.0.0"
"node": ">=20.0.0"
},
"files": [
"*.js"
Expand All @@ -25,10 +25,13 @@
"url": "^0.11.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.3.3",
"@eslint/js": "^9.39.2",
"c8": "^10.0.0",
"chai": "^4.2.0",
"eslint": "^8.53.0",
"eslint": "^10.0.0",
"eslint-config-google": "^0.14.0",
"globals": "^17.3.0",
"mocha": "^11.0.0"
}
}
2 changes: 1 addition & 1 deletion google-analytics-admin/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function main() {
// [END analytics_admin_quickstart]
}

process.on('unhandledRejection', err => {
process.on('unhandledRejection', (err) => {
console.error(err.message);
process.exitCode = 1;
});
Expand Down
13 changes: 0 additions & 13 deletions google-analytics-data/.eslintrc.json

This file was deleted.

40 changes: 40 additions & 0 deletions google-analytics-data/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {defineConfig} from 'eslint/config';
import globals from 'globals';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import js from '@eslint/js';
import {FlatCompat} from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

const googleConfig = compat.extends('google');
for (const config of googleConfig) {
if (config.rules) {
delete config.rules['valid-jsdoc'];
delete config.rules['require-jsdoc'];
}
}

export default defineConfig([
...googleConfig,
{
files: ['*.js', 'test/*.js'],
languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
},

ecmaVersion: 'latest',
sourceType: 'script',
},

rules: {},
},
]);
44 changes: 24 additions & 20 deletions google-analytics-data/get_common_metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@

'use strict';

/** Google Analytics Data API sample application retrieving dimension and metrics
metadata.

See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
for more information.

Before you start the application, please review the comments starting with
"TODO(developer)" and update the code to use correct values.

Usage:
npm install
node getCommonMetadata.js
/**
* Google Analytics Data API sample application retrieving dimension and metrics
* metadata.
*
* See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
* for more information.
*
* Before you start the application, please review the comments starting with
* "TODO(developer)" and update the code to use correct values.
*
* Usage:
* npm install
* node getCommonMetadata.js
*/

function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
Expand All @@ -43,13 +44,15 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
// needs to be created once, and can be reused for multiple requests.
const analyticsDataClient = new BetaAnalyticsDataClient();

// Retrieves dimensions and metrics available for all Google Analytics 4 properties.
// Retrieves dimensions and metrics available for all Google Analytics 4
// properties.
async function getCommonMetadata() {
const [response] = await analyticsDataClient.getMetadata({
name: `properties/${propertyId}/metadata`,
});
console.log(
'Dimensions and metrics available for all Google Analytics 4 properties:'
'Dimensions and metrics available for all ' +
'Google Analytics 4 properties:',
);
printGetMetadataResponse(response);
}
Expand All @@ -58,11 +61,12 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {

// Prints results of the getMetadata call.
function printGetMetadataResponse(response) {
//[START analyticsdata_print_get_metadata_response]
response.dimensions.forEach(dimension => {
// [START analyticsdata_print_get_metadata_response]
response.dimensions.forEach((dimension) => {
console.log('DIMENSION');
console.log(
`${dimension.apiName} (${dimension.uiName}): ${dimension.description}`
`${dimension.apiName} (${dimension.uiName}): ` +
`${dimension.description}`,
);
console.log(`custom definition: ${dimension.customDefinition}`);
if (
Expand All @@ -74,10 +78,10 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
console.log();
});

response.metrics.forEach(metric => {
response.metrics.forEach((metric) => {
console.log('METRIC');
console.log(
`${metric.apiName} (${metric.uiName}): ${metric.description}`
`${metric.apiName} (${metric.uiName}): ${metric.description}`,
);
console.log(`custom definition: ${metric.customDefinition}`);
if (metric.expression) {
Expand All @@ -94,7 +98,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
// [END analyticsdata_get_common_metadata]
}

process.on('unhandledRejection', err => {
process.on('unhandledRejection', (err) => {
console.error(err.message);
process.exitCode = 1;
});
Expand Down
41 changes: 22 additions & 19 deletions google-analytics-data/get_metadata_by_property_id.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@

'use strict';

/** Google Analytics Data API sample application retrieving dimension and metrics
metadata.

See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
for more information.

Before you start the application, please review the comments starting with
"TODO(developer)" and update the code to use correct values.

Usage:
npm install
node getMetadataByPropertyId.js
/**
* Google Analytics Data API sample application retrieving dimension and metrics
* metadata.
*
* See https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/getMetadata
* for more information.
*
* Before you start the application, please review the comments starting with
* "TODO(developer)" and update the code to use correct values.
*
* Usage:
* npm install
* node getMetadataByPropertyId.js
*/

function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
Expand All @@ -49,7 +50,8 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
name: `properties/${propertyId}/metadata`,
});
console.log(
`Dimensions and metrics available for a Google Analytics 4 property ${propertyId} (including custom fields):`
'Dimensions and metrics available for a Google Analytics 4 ' +
`property ${propertyId} (including custom fields):`,
);
printGetMetadataResponse(response);
}
Expand All @@ -58,11 +60,12 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {

// Prints results of the getMetadata call.
function printGetMetadataResponse(response) {
//[START analyticsdata_print_get_metadata_response]
response.dimensions.forEach(dimension => {
// [START analyticsdata_print_get_metadata_response]
response.dimensions.forEach((dimension) => {
console.log('DIMENSION');
console.log(
`${dimension.apiName} (${dimension.uiName}): ${dimension.description}`
`${dimension.apiName} (${dimension.uiName}): ` +
`${dimension.description}`,
);
console.log(`custom definition: ${dimension.customDefinition}`);
if (
Expand All @@ -74,10 +77,10 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
console.log();
});

response.metrics.forEach(metric => {
response.metrics.forEach((metric) => {
console.log('METRIC');
console.log(
`${metric.apiName} (${metric.uiName}): ${metric.description}`
`${metric.apiName} (${metric.uiName}): ${metric.description}`,
);
console.log(`custom definition: ${metric.customDefinition}`);
if (metric.expression) {
Expand All @@ -94,7 +97,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
// [END analyticsdata_get_metadata_by_property_id]
}

process.on('unhandledRejection', err => {
process.on('unhandledRejection', (err) => {
console.error(err.message);
process.exitCode = 1;
});
Expand Down
7 changes: 5 additions & 2 deletions google-analytics-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=18.0.0"
"node": ">=20.0.0"
},
"files": [
"*.js"
Expand All @@ -25,10 +25,13 @@
"url": "^0.11.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.3.3",
"@eslint/js": "^9.39.2",
"c8": "^10.0.0",
"chai": "^4.2.0",
"eslint": "^8.53.0",
"eslint": "^10.0.0",
"eslint-config-google": "^0.14.0",
"globals": "^17.3.0",
"mocha": "^11.0.0"
}
}
4 changes: 2 additions & 2 deletions google-analytics-data/quickstart_json_credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID', credentialsJsonPath = '') {
// [END analyticsdata_json_credentials_run_report]

console.log('Report result:');
response.rows.forEach(row => {
response.rows.forEach((row) => {
console.log(row.dimensionValues[0], row.metricValues[0]);
});
}
Expand All @@ -87,7 +87,7 @@ function main(propertyId = 'YOUR-GA4-PROPERTY-ID', credentialsJsonPath = '') {
// [END analyticsdata_json_credentials_quickstart]
}

process.on('unhandledRejection', err => {
process.on('unhandledRejection', (err) => {
console.error(err.message);
process.exitCode = 1;
});
Expand Down
8 changes: 4 additions & 4 deletions google-analytics-data/quickstart_oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const destroyer = require('server-destroy');

// TODO(developer): Download the OAuth 2.0 client ID JSON from
// https://console.cloud.google.com/apis/credentials for a Desktop or Web
// client, and save it in the nodejs-docs-samples/google-analytics-data directory
// in a file named oauth2.keys.json. If using a Web client, register
// client, and save it in the nodejs-docs-samples/google-analytics-data
// directory in a file named oauth2.keys.json. If using a Web client, register
// http://127.0.0.1 as an authorized redirect URI.
const keys = require('./oauth2.keys.json');

Expand All @@ -49,8 +49,8 @@ async function main(propertyId = 'YOUR-GA4-PROPERTY-ID') {
// Constructs a BetaAnalyticsDataClient using the credentials obtained above
// instead of the Application Default Credentials.
const credentials = grpc.credentials.combineChannelCredentials(
grpc.credentials.createSsl(),
grpc.credentials.createFromGoogleCredential(oAuth2Client)
grpc.credentials.createSsl(),
grpc.credentials.createFromGoogleCredential(oAuth2Client),
);
const analyticsDataClient = new BetaAnalyticsDataClient({
sslCreds: credentials,
Expand Down
Loading