Socket
Socket
Sign inDemoInstall

@firebase/analytics

Package Overview
Dependencies
Maintainers
4
Versions
2447
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@firebase/analytics - npm Package Compare versions

Comparing version 0.10.6-canary.e542f1dbd to 0.10.6-dataconnect-preview.d986d4bf2

139

dist/esm/index.esm2017.js
import { _getProvider, getApp, _registerComponent, registerVersion } from '@firebase/app';
import { Logger } from '@firebase/logger';
import { trustedResourceUrl } from 'safevalues';
import { safeScriptEl } from 'safevalues/dom';
import { ErrorFactory, calculateBackoffMillis, FirebaseError, isIndexedDBAvailable, validateIndexedDBOpenable, isBrowserExtension, areCookiesEnabled, getModularInstance, deepEqual } from '@firebase/util';

@@ -70,3 +68,62 @@ import { Component } from '@firebase/component';

*/
const ERRORS = {
["already-exists" /* AnalyticsError.ALREADY_EXISTS */]: 'A Firebase Analytics instance with the appId {$id} ' +
' already exists. ' +
'Only one Firebase Analytics instance can be created for each appId.',
["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */]: 'initializeAnalytics() cannot be called again with different options than those ' +
'it was initially called with. It can be called again with the same options to ' +
'return the existing instance, or getAnalytics() can be used ' +
'to get a reference to the already-initialized instance.',
["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */]: 'Firebase Analytics has already been initialized.' +
'settings() must be called before initializing any Analytics instance' +
'or it will have no effect.',
["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */]: 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */]: 'Firebase Analytics is not supported in this environment. ' +
'Wrap initialization of analytics in analytics.isSupported() ' +
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */]: 'IndexedDB unavailable or restricted in this environment. ' +
'Wrap initialization of analytics in analytics.isSupported() ' +
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */]: 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
["no-api-key" /* AnalyticsError.NO_API_KEY */]: 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
'contain a valid API key.',
["no-app-id" /* AnalyticsError.NO_APP_ID */]: 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
'contain a valid app ID.',
["no-client-id" /* AnalyticsError.NO_CLIENT_ID */]: 'The "client_id" field is empty.',
["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */]: 'Trusted Types detected an invalid gtag resource: {$gtagURL}.'
};
const ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Verifies and creates a TrustedScriptURL.
*/
function createGtagTrustedTypesScriptURL(url) {
if (!url.startsWith(GTAG_URL)) {
const err = ERROR_FACTORY.create("invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */, {
gtagURL: url
});
logger.warn(err.message);
return '';
}
return url;
}
/**
* Makeshift polyfill for Promise.allSettled(). Resolves when all promises

@@ -81,2 +138,18 @@ * have either resolved or rejected.

/**
* Creates a TrustedTypePolicy object that implements the rules passed as policyOptions.
*
* @param policyName A string containing the name of the policy
* @param policyOptions Object containing implementations of instance methods for TrustedTypesPolicy, see {@link https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy#instance_methods
* | the TrustedTypePolicy reference documentation}.
*/
function createTrustedTypesPolicy(policyName, policyOptions) {
// Create a TrustedTypes policy that we can use for updating src
// properties
let trustedTypesPolicy;
if (window.trustedTypes) {
trustedTypesPolicy = window.trustedTypes.createPolicy(policyName, policyOptions);
}
return trustedTypesPolicy;
}
/**
* Inserts gtag script tag into the page to asynchronously download gtag.

@@ -86,12 +159,12 @@ * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").

function insertScriptTag(dataLayerName, measurementId) {
const trustedTypesPolicy = createTrustedTypesPolicy('firebase-js-sdk-policy', {
createScriptURL: createGtagTrustedTypesScriptURL
});
const script = document.createElement('script');
// We are not providing an analyticsId in the URL because it would trigger a `page_view`
// without fid. We will initialize ga-id using gtag (config) command together with fid.
//
// We also have to ensure the template string before the first expression constitutes a valid URL
// start, as this is what the initial validation focuses on. If the template literal begins
// directly with an expression (e.g. `${GTAG_SCRIPT_URL}`), the validation fails due to an
// empty initial string.
const url = trustedResourceUrl `https://www.googletagmanager.com/gtag/js?l=${dataLayerName}&id=${measurementId}`;
safeScriptEl.setSrc(script, url);
const gtagScriptURL = `${GTAG_URL}?l=${dataLayerName}&id=${measurementId}`;
script.src = trustedTypesPolicy
? trustedTypesPolicy === null || trustedTypesPolicy === void 0 ? void 0 : trustedTypesPolicy.createScriptURL(gtagScriptURL)
: gtagScriptURL;
script.async = true;

@@ -322,48 +395,2 @@ document.head.appendChild(script);

* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const ERRORS = {
["already-exists" /* AnalyticsError.ALREADY_EXISTS */]: 'A Firebase Analytics instance with the appId {$id} ' +
' already exists. ' +
'Only one Firebase Analytics instance can be created for each appId.',
["already-initialized" /* AnalyticsError.ALREADY_INITIALIZED */]: 'initializeAnalytics() cannot be called again with different options than those ' +
'it was initially called with. It can be called again with the same options to ' +
'return the existing instance, or getAnalytics() can be used ' +
'to get a reference to the already-initialized instance.',
["already-initialized-settings" /* AnalyticsError.ALREADY_INITIALIZED_SETTINGS */]: 'Firebase Analytics has already been initialized.' +
'settings() must be called before initializing any Analytics instance' +
'or it will have no effect.',
["interop-component-reg-failed" /* AnalyticsError.INTEROP_COMPONENT_REG_FAILED */]: 'Firebase Analytics Interop Component failed to instantiate: {$reason}',
["invalid-analytics-context" /* AnalyticsError.INVALID_ANALYTICS_CONTEXT */]: 'Firebase Analytics is not supported in this environment. ' +
'Wrap initialization of analytics in analytics.isSupported() ' +
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
["indexeddb-unavailable" /* AnalyticsError.INDEXEDDB_UNAVAILABLE */]: 'IndexedDB unavailable or restricted in this environment. ' +
'Wrap initialization of analytics in analytics.isSupported() ' +
'to prevent initialization in unsupported environments. Details: {$errorInfo}',
["fetch-throttle" /* AnalyticsError.FETCH_THROTTLE */]: 'The config fetch request timed out while in an exponential backoff state.' +
' Unix timestamp in milliseconds when fetch request throttling ends: {$throttleEndTimeMillis}.',
["config-fetch-failed" /* AnalyticsError.CONFIG_FETCH_FAILED */]: 'Dynamic config fetch failed: [{$httpStatus}] {$responseMessage}',
["no-api-key" /* AnalyticsError.NO_API_KEY */]: 'The "apiKey" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
'contain a valid API key.',
["no-app-id" /* AnalyticsError.NO_APP_ID */]: 'The "appId" field is empty in the local Firebase config. Firebase Analytics requires this field to' +
'contain a valid app ID.',
["no-client-id" /* AnalyticsError.NO_CLIENT_ID */]: 'The "client_id" field is empty.',
["invalid-gtag-resource" /* AnalyticsError.INVALID_GTAG_RESOURCE */]: 'Trusted Types detected an invalid gtag resource: {$gtagURL}.'
};
const ERROR_FACTORY = new ErrorFactory('analytics', 'Analytics', ERRORS);
/**
* @license
* Copyright 2020 Google LLC

@@ -1210,3 +1237,3 @@ *

const name = "@firebase/analytics";
const version = "0.10.6-canary.e542f1dbd";
const version = "0.10.6-dataconnect-preview.d986d4bf2";

@@ -1213,0 +1240,0 @@ /**

@@ -17,4 +17,9 @@ /**

*/
/// <reference types="trusted-types" />
import { DynamicConfig, DataLayer, Gtag, MinimalDynamicConfig } from './types';
/**
* Verifies and creates a TrustedScriptURL.
*/
export declare function createGtagTrustedTypesScriptURL(url: string): string;
/**
* Makeshift polyfill for Promise.allSettled(). Resolves when all promises

@@ -27,2 +32,10 @@ * have either resolved or rejected.

/**
* Creates a TrustedTypePolicy object that implements the rules passed as policyOptions.
*
* @param policyName A string containing the name of the policy
* @param policyOptions Object containing implementations of instance methods for TrustedTypesPolicy, see {@link https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy#instance_methods
* | the TrustedTypePolicy reference documentation}.
*/
export declare function createTrustedTypesPolicy(policyName: string, policyOptions: Partial<TrustedTypePolicyOptions>): Partial<TrustedTypePolicy> | undefined;
/**
* Inserts gtag script tag into the page to asynchronously download gtag.

@@ -29,0 +42,0 @@ * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").

@@ -17,4 +17,9 @@ /**

*/
/// <reference types="trusted-types" />
import { DynamicConfig, DataLayer, Gtag, MinimalDynamicConfig } from './types';
/**
* Verifies and creates a TrustedScriptURL.
*/
export declare function createGtagTrustedTypesScriptURL(url: string): string;
/**
* Makeshift polyfill for Promise.allSettled(). Resolves when all promises

@@ -27,2 +32,10 @@ * have either resolved or rejected.

/**
* Creates a TrustedTypePolicy object that implements the rules passed as policyOptions.
*
* @param policyName A string containing the name of the policy
* @param policyOptions Object containing implementations of instance methods for TrustedTypesPolicy, see {@link https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy#instance_methods
* | the TrustedTypePolicy reference documentation}.
*/
export declare function createTrustedTypesPolicy(policyName: string, policyOptions: Partial<TrustedTypePolicyOptions>): Partial<TrustedTypePolicy> | undefined;
/**
* Inserts gtag script tag into the page to asynchronously download gtag.

@@ -29,0 +42,0 @@ * @param dataLayerName Name of datalayer (most often the default, "_dataLayer").

{
"name": "@firebase/analytics",
"version": "0.10.6-canary.e542f1dbd",
"version": "0.10.6-dataconnect-preview.d986d4bf2",
"description": "A analytics package for new firebase packages",

@@ -41,19 +41,18 @@ "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",

"peerDependencies": {
"@firebase/app": "0.10.7-canary.e542f1dbd"
"@firebase/app": "0.10.7-dataconnect-preview.d986d4bf2"
},
"dependencies": {
"@firebase/installations": "0.6.8-canary.e542f1dbd",
"@firebase/logger": "0.4.2-canary.e542f1dbd",
"@firebase/util": "1.9.7-canary.e542f1dbd",
"@firebase/component": "0.6.8-canary.e542f1dbd",
"tslib": "^2.1.0",
"safevalues": "0.6.0"
"@firebase/installations": "0.6.8-dataconnect-preview.d986d4bf2",
"@firebase/logger": "0.4.2-dataconnect-preview.d986d4bf2",
"@firebase/util": "1.9.7-dataconnect-preview.d986d4bf2",
"@firebase/component": "0.6.8-dataconnect-preview.d986d4bf2",
"tslib": "^2.1.0"
},
"license": "Apache-2.0",
"devDependencies": {
"@firebase/app": "0.10.7-canary.e542f1dbd",
"@firebase/app": "0.10.7-dataconnect-preview.d986d4bf2",
"rollup": "2.79.1",
"@rollup/plugin-commonjs": "21.1.0",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.3.0",
"rollup": "2.79.1",
"rollup-plugin-typescript2": "0.31.2",

@@ -60,0 +59,0 @@ "typescript": "4.7.4"

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc