Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zmp-ga4

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zmp-ga4 - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

2

package.json
{
"name": "zmp-ga4",
"version": "1.3.0",
"version": "1.4.0",
"author": {

@@ -5,0 +5,0 @@ "name": "Nguyễn Hồng Phát",

@@ -65,15 +65,20 @@ "use strict";

this.collect = function () {
if (_this.eventQueue.length) {
fetch("https://www.google-analytics.com/mp/collect?measurement_id=".concat(_this.propertyId, "&api_secret=").concat(_this.apiSecretKey), {
method: "POST",
body: JSON.stringify({
client_id: "4627379193",
events: _this.eventQueue
})
});
_this.eventQueue = [];
if (_this.userId) {
if (_this.eventQueue.length) {
fetch("https://www.google-analytics.com/mp/collect?measurement_id=".concat(_this.propertyId, "&api_secret=").concat(_this.apiSecretKey), {
method: "POST",
body: JSON.stringify({
client_id: _this.propertyId,
events: _this.eventQueue
})
});
_this.eventQueue = [];
}
}
else {
setTimeout(_this.collect, 1000);
}
};
if (this.isMeasurementProtocolRequired()) {
this.userId = this.getVisitorID();
this.getVisitorID().then(function (visitorId) { return (_this.userId = visitorId); });
window.addEventListener("beforeunload", this.collect);

@@ -116,18 +121,22 @@ var handleLocationChange = function () {

AdaptiveAnalytics.prototype.getVisitorID = function () {
var _this = this;
return new Promise(function (resolve) {
if (typeof window.ZJSBridge != "undefined" &&
typeof window.ZJSBridge.callCustomAction == "function") {
window.ZJSBridge.callCustomAction("action.mp.get.visitor.id", {}, function (result) {
if (result.error_code == 0 && result.data != "{}") {
return resolve(result.data);
}
else {
return resolve(_this.uuidv4());
}
});
}
else {
return resolve(_this.uuidv4());
}
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve) {
if (typeof window.ZJSBridge != "undefined" &&
typeof window.ZJSBridge.callCustomAction == "function") {
window.ZJSBridge.callCustomAction("action.mp.get.visitor.id", {}, function (result) {
if (result.error_code == 0 && result.data != "{}") {
return resolve(result.data);
}
else {
return resolve(_this.uuidv4());
}
});
}
else {
return resolve(_this.uuidv4());
}
})];
});
});

@@ -134,0 +143,0 @@ };

export class AdaptiveAnalytics {
private userId;
private userId: string;
private startTime = performance.now();

@@ -22,3 +22,3 @@ private eventQueue: {

if (this.isMeasurementProtocolRequired()) {
this.userId = this.getVisitorID();
this.getVisitorID().then((visitorId) => (this.userId = visitorId));
window.addEventListener("beforeunload", this.collect);

@@ -65,3 +65,3 @@

getVisitorID() {
async getVisitorID() {
return new Promise<string>((resolve) => {

@@ -118,14 +118,18 @@ if (

private collect = () => {
if (this.eventQueue.length) {
fetch(
`https://www.google-analytics.com/mp/collect?measurement_id=${this.propertyId}&api_secret=${this.apiSecretKey}`,
{
method: "POST",
body: JSON.stringify({
client_id: "4627379193",
events: this.eventQueue,
}),
}
);
this.eventQueue = [];
if (this.userId) {
if (this.eventQueue.length) {
fetch(
`https://www.google-analytics.com/mp/collect?measurement_id=${this.propertyId}&api_secret=${this.apiSecretKey}`,
{
method: "POST",
body: JSON.stringify({
client_id: this.propertyId,
events: this.eventQueue,
}),
}
);
this.eventQueue = [];
}
} else {
setTimeout(this.collect, 1000);
}

@@ -132,0 +136,0 @@ };

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