@telefonica/google-analytics
Advanced tools
Comparing version 1.0.2-beta to 1.0.2-beta2
import type { AnalyticsApi } from './type'; | ||
export declare const consoleApi: AnalyticsApi; |
import type { AnalyticsApi } from './type'; | ||
export declare const gtagApi: AnalyticsApi; |
@@ -0,0 +0,0 @@ export interface AnalyticsApi { |
@@ -7,3 +7,3 @@ import { sanitizeAnalyticsParam, sanitizeAnalyticsParams } from './sanitize'; | ||
export { gtagApi, consoleApi, sanitizeAnalyticsParam, sanitizeAnalyticsParams }; | ||
export declare type TrackingEvent = { | ||
export type TrackingEvent = { | ||
name: string; | ||
@@ -17,5 +17,6 @@ [key: string]: unknown; | ||
} | ||
declare let api: AnalyticsApi; | ||
export declare const initAnalytics: (trackingId: string, options?: { | ||
api?: AnalyticsApi | undefined; | ||
} | undefined) => Promise<void>; | ||
api?: AnalyticsApi; | ||
}) => Promise<void>; | ||
export declare const resetScreenName: () => void; | ||
@@ -22,0 +23,0 @@ export declare const setScreenName: (screenName: string, params?: { |
@@ -1,8 +0,41 @@ | ||
'use strict' | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./google-analytics.cjs.production.min.js') | ||
} else { | ||
module.exports = require('./google-analytics.cjs.development.js') | ||
} | ||
import { sanitizeAnalyticsParam, sanitizeAnalyticsParams } from './sanitize'; | ||
import { consoleApi } from './api/console'; | ||
import { gtagApi } from './api/gtag'; | ||
export { gtagApi, consoleApi, sanitizeAnalyticsParam, sanitizeAnalyticsParams }; | ||
let api = gtagApi; | ||
let handleInitFinished; | ||
const waitInitialization = new Promise((resolve) => { | ||
handleInitFinished = resolve; | ||
}); | ||
export const initAnalytics = (trackingId, options) => { | ||
if (options?.api) { | ||
api = options.api; | ||
} | ||
return api.initialize(trackingId).then(handleInitFinished); | ||
}; | ||
let currentScreenName = ''; | ||
export const resetScreenName = () => { | ||
currentScreenName = ''; | ||
}; | ||
export const setScreenName = (screenName, params) => { | ||
return waitInitialization.then(() => { | ||
const sanitizedScreenName = sanitizeAnalyticsParam(screenName); | ||
if (sanitizedScreenName === currentScreenName) { | ||
return; | ||
} | ||
currentScreenName = sanitizedScreenName; | ||
return api.setScreenName(sanitizedScreenName, sanitizeAnalyticsParams(params || {})); | ||
}); | ||
}; | ||
export const logEvent = (event) => { | ||
return waitInitialization.then(() => { | ||
const { name, ...rest } = sanitizeAnalyticsParams(event); | ||
return api.logEvent(name, { | ||
...rest, | ||
screenName: rest.screenName || currentScreenName, | ||
}); | ||
}); | ||
}; | ||
export const setUserProperty = (name, value) => { | ||
return waitInitialization.then(() => api.setUserProperty(name, sanitizeAnalyticsParam(value))); | ||
}; |
export declare const sanitizeAnalyticsParam: (str: string) => string; | ||
export declare const sanitizeAnalyticsParams: (params: Record<string, unknown>) => Record<string, unknown>; |
{ | ||
"name": "@telefonica/google-analytics", | ||
"type": "module", | ||
"version": "1.0.2-beta", | ||
"version": "1.0.2-beta2", | ||
"description": "", | ||
@@ -9,3 +9,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/google-analytics.esm.js" | ||
"default": "./dist/index.js" | ||
} | ||
@@ -17,6 +17,8 @@ }, | ||
"scripts": { | ||
"build": "tsdx build", | ||
"prepare": "tsdx build", | ||
"test": "tsdx test", | ||
"prepack": "yarn test && yarn build" | ||
"clean": "rm -rf dist", | ||
"build": "yarn clean && tsc -p tsconfig.production.json", | ||
"prepare": "yarn build", | ||
"test": "jest", | ||
"prepack": "yarn test && yarn build", | ||
"ts-check": "tsc" | ||
}, | ||
@@ -37,5 +39,7 @@ "keywords": [], | ||
"jest": "^29.6.1", | ||
"tsdx": "^0.14.1", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"ts-jest": "^29.2.5", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
1
10934
6
12
187
1