Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@telefonica/google-analytics
Advanced tools
@telefonica/google-analytics
Google Analytics 4 library for Telefonica web projects
import {initAnalytics, logEvent, setScreenName} from '@telefonica/google-analytics';
initAnalytics('G-XXXXXXXXXX');
setScreenName('my_screen_name');
logEvent({name: 'my_event_name', foo: 'bar'});
initAnalytics
must be called before any other function. This function will inject the gtag script in the
document.
initAnalytics
function is idempotent. Subsequent calls to initAnalytics
will not have any effect.
logEvent
and setScreenName
calls won't send any data to Google Analytics until initAnalytics
is
called. If you call logEvent
or setScreenName
before initAnalytics
, the calls will be queued and sent
to Google Analytics once initAnalytics
is done.
Events are normalized before being sent to Google Analytics:
If setScreenName
is called multiple times with the same screen name, only the first call will be sent to
Google Analytics.
setScreenName
and logEvent
return a promise that resolves when the event has been sent to Google
Analytics.
All the events are automatically filled with a screenName
param containing the last screen name set with
setScreenName
.
Events are sent to Google servers by default (using gtagApi
), but you can use a custom api to change this
behavior. For example, Novum app uses the webview bridge to send the events to the native app, and then the
native app sends the events to Firebase.
Another use case of custom api is to log events in the browser console in development mode:
import {initAnalytics, consoleApi, gtagApi} from '@telefonica/google-analytics';
initAnalytics('G-XXXXXXXXXX', {
api: process.env.NODE_ENV === 'production' ? gtagApi : consoleApi,
});
If you are using a CSP, you must add the following directives for Google Analytics to work:
script-src https://*.googletagmanager.com; connect-src https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com; img-src https://*.google-analytics.com https://*.googletagmanager.com;
Check Google docs for CSP in Google Analytics 4
FAQs
> Google Analytics 4 library for Telefonica web projects
The npm package @telefonica/google-analytics receives a total of 104 weekly downloads. As such, @telefonica/google-analytics popularity was classified as not popular.
We found that @telefonica/google-analytics demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.