@giphy/js-analytics
Advanced tools
Comparing version 0.0.0-canary-20230620165510 to 0.0.0-canary-20230621031504
@@ -1,32 +0,3 @@ | ||
import { PingbackEventType } from '@giphy/js-types'; | ||
type PingbackAttributes = { | ||
[key: string]: string; | ||
}; | ||
type Pingback = { | ||
userId?: string | number; | ||
eventType?: PingbackEventType; | ||
actionType: PingbackActionType; | ||
attributes?: PingbackAttributes; | ||
queueEvents?: boolean; | ||
analyticsResponsePayload: string; | ||
}; | ||
type PingbackActionType = 'CLICK' | 'SEEN' | 'HOVER' | 'FAVORITE' | 'SENT' | 'START'; | ||
type PingbackEvent = { | ||
event_type?: PingbackEventType; | ||
user_id?: string; | ||
logged_in_user_id?: string; | ||
action_type: string; | ||
random_id?: string; | ||
attributes: any; | ||
ts: number; | ||
analytics_response_payload?: string; | ||
}; | ||
declare const mergeAttribute: (attributes: PingbackAttributes, newAttributes: PingbackAttributes, key: string) => { | ||
[x: string]: string; | ||
}; | ||
declare const pingback: ({ userId, eventType, actionType, attributes, queueEvents, analyticsResponsePayload, }: Pingback) => void; | ||
export { Pingback, PingbackActionType, PingbackAttributes, PingbackEvent, mergeAttribute as mergeAttributes, pingback }; | ||
export { default as mergeAttributes } from './merge-attributes'; | ||
export { default as pingback } from './pingback'; | ||
export * from './types'; |
@@ -1,102 +0,26 @@ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
return a; | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
// src/merge-attributes.ts | ||
import { pick } from "@giphy/js-util"; | ||
var mergeAttribute = (attributes, newAttributes, key) => { | ||
const result1 = pick(attributes, [key]); | ||
const result2 = pick(newAttributes, [key]); | ||
if (result1[key] && result2[key]) { | ||
return __spreadValues(__spreadValues(__spreadValues({}, attributes), newAttributes), { [key]: result1[key] + ", " + result2[key] }); | ||
} | ||
return __spreadValues(__spreadValues({}, attributes), newAttributes); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var merge_attributes_default = mergeAttribute; | ||
// src/pingback.ts | ||
import { getPingbackId, Logger as Logger2 } from "@giphy/js-util"; | ||
import { debounce } from "throttle-debounce"; | ||
// src/global.ts | ||
var global_default = (typeof window !== "undefined" ? window : global) || {}; | ||
// src/send-pingback.ts | ||
import { getGiphySDKRequestHeaders, Logger } from "@giphy/js-util"; | ||
var _a; | ||
var environment = ((_a = global_default) == null ? void 0 : _a.GIPHY_PINGBACK_URL) || "https://pingback.giphy.com"; | ||
var pingBackUrl = `${environment}/v2/pingback?apikey=l0HlIwPWyBBUDAUgM`; | ||
var sendPingback = (events) => { | ||
const headers = getGiphySDKRequestHeaders(); | ||
headers == null ? void 0 : headers.set("Content-Type", "application/json"); | ||
Logger.debug(`Pingback session`, events); | ||
if (!events.length) { | ||
return new Promise((resolve) => resolve()); | ||
} | ||
return fetch(pingBackUrl, { | ||
method: "POST", | ||
body: JSON.stringify({ events }), | ||
headers | ||
}).catch((error) => { | ||
Logger.warn(`pingbacks failing to post ${error}`); | ||
}); | ||
}; | ||
// src/pingback.ts | ||
var queuedPingbackEvents = []; | ||
global_default.giphyRandomId = getPingbackId(); | ||
var loggedInUserId = ""; | ||
function sendPingbacks() { | ||
const sendEvents = [...queuedPingbackEvents]; | ||
queuedPingbackEvents = []; | ||
sendPingback(sendEvents); | ||
} | ||
var debouncedPingbackEvent = debounce(1e3, sendPingbacks); | ||
var _a2, _b; | ||
(_b = (_a2 = global_default).addEventListener) == null ? void 0 : _b.call(_a2, "beforeunload", sendPingbacks); | ||
var pingback = ({ | ||
userId, | ||
eventType, | ||
actionType, | ||
attributes, | ||
queueEvents = true, | ||
analyticsResponsePayload | ||
}) => { | ||
loggedInUserId = userId ? String(userId) : loggedInUserId; | ||
const newEvent = { | ||
ts: Date.now(), | ||
attributes, | ||
action_type: actionType, | ||
user_id: getPingbackId(), | ||
analytics_response_payload: analyticsResponsePayload | ||
}; | ||
if (loggedInUserId) { | ||
newEvent.logged_in_user_id = loggedInUserId; | ||
} | ||
if (newEvent.analytics_response_payload) { | ||
newEvent.analytics_response_payload = `${newEvent.analytics_response_payload}${Logger2.ENABLED ? "&mode=verification" : ""}`; | ||
} | ||
if (eventType) { | ||
newEvent.event_type = eventType; | ||
} | ||
queuedPingbackEvents.push(newEvent); | ||
queueEvents ? debouncedPingbackEvent() : sendPingbacks(); | ||
}; | ||
var pingback_default = pingback; | ||
export { | ||
merge_attributes_default as mergeAttributes, | ||
pingback_default as pingback | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.pingback = exports.mergeAttributes = void 0; | ||
var merge_attributes_1 = require("./merge-attributes"); | ||
Object.defineProperty(exports, "mergeAttributes", { enumerable: true, get: function () { return __importDefault(merge_attributes_1).default; } }); | ||
var pingback_1 = require("./pingback"); | ||
Object.defineProperty(exports, "pingback", { enumerable: true, get: function () { return __importDefault(pingback_1).default; } }); | ||
__exportStar(require("./types"), exports); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"scripts": { | ||
"lint": "run -T eslint . --ext .ts,.tsx", | ||
"clean": "rm -rf ./dist", | ||
"clean": "rm -rf ./dist ./esm", | ||
"dev": "tsc --watch", | ||
"build": "run -T tsup src/index.ts --format cjs,esm --dts && run -T publint", | ||
"build": "tsc && npm run build:esm", | ||
"build:esm": "tsc -p ./tsconfig-esm.json", | ||
"prepublish": "npm run clean && npm run build", | ||
@@ -13,18 +14,10 @@ "test": "run -T jest --config ./jestconfig.js", | ||
"homepage": "https://github.com/Giphy/giphy-js/tree/master/packages/analytics", | ||
"version": "0.0.0-canary-20230620165510", | ||
"main": "dist/index.cjs", | ||
"version": "0.0.0-canary-20230621031504", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"module": "dist/index.js", | ||
"type": "module", | ||
"module": "esm/index.js", | ||
"sideEffects": false, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"files": [ | ||
"dist/", | ||
"esm/", | ||
"src/**/*" | ||
@@ -38,3 +31,3 @@ ], | ||
"@giphy/js-types": "*", | ||
"@giphy/js-util": "0.0.0-canary-20230620165510", | ||
"@giphy/js-util": "0.0.0-canary-20230621031504", | ||
"append-query": "^2.1.0", | ||
@@ -41,0 +34,0 @@ "throttle-debounce": "^3.0.1" |
36542
47
719
No
+ Added@giphy/js-util@0.0.0-canary-20230621031504(transitive)
- Removed@giphy/js-util@0.0.0-canary-20230620165510(transitive)