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

@giphy/js-analytics

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@giphy/js-analytics - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

dist/send-pingback.d.ts

3

dist/index.d.ts

@@ -1,1 +0,2 @@

export { default as pingback, Action as PingbackAction } from './pingback';
export { default as pingback } from './pingback';
export * from './types';

@@ -5,3 +5,2 @@ "use strict";

exports.pingback = pingback_1.default;
exports.PingbackAction = pingback_1.Action;
//# sourceMappingURL=index.js.map

@@ -1,17 +0,3 @@

import { IGif } from '@giphy/js-types';
import { IPingbackUser } from './types';
export declare enum Action {
click = "CLICK",
seen = "SEEN",
hover = "HOVER"
}
export declare type Pingback = {
gif: IGif;
user: IPingbackUser;
category: string;
searchResponseId: string;
action: Action;
position?: ClientRect;
};
declare const pingback: ({ gif, user, searchResponseId, category, action, position }: Pingback) => void;
import { Pingback } from './types';
declare const pingback: ({ gif, user, responseId, type: pingbackType, actionType, position }: Pingback) => void;
export default pingback;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var pingback_requests_1 = require("./pingback-requests");
var pingbackFunction = {
search: pingback_requests_1.searchPingBackEvent,
home: pingback_requests_1.trendingGridPingBackEvent,
related: pingback_requests_1.relatedPingBackEvent,
'gif detail': pingback_requests_1.relatedPingBackEvent,
channel: null,
explore: pingback_requests_1.explorePingBackEvent,
homeCarousel: pingback_requests_1.trendingCarouselPingBackEvent,
};
var Action;
(function (Action) {
Action["click"] = "CLICK";
Action["seen"] = "SEEN";
Action["hover"] = "HOVER";
})(Action = exports.Action || (exports.Action = {}));
function firePingback(action, category, searchResponseId, user, skipQueue) {
if (skipQueue === void 0) { skipQueue = false; }
var pingbackRequest = pingbackFunction[category];
// check to see if there are pingback events to send && make sure you dont duplicate the batch call
pingbackRequest(action, searchResponseId, user, skipQueue);
var throttle_debounce_1 = require("throttle-debounce");
var session_1 = require("./session");
var util_1 = require("./util");
var js_util_1 = require("@giphy/js-util");
var send_pingback_1 = require("./send-pingback");
var queuedPingbacks = {};
var loggedInUserId = '';
function fetchPingbackRequest() {
js_util_1.forEach(queuedPingbacks, function (actionMap, pingbackType) {
if (actionMap) {
js_util_1.forEach(actionMap, function (action, responseId) {
// if there are no actions lined up inside this pingbackType do nothing
if (action.length) {
var session = session_1.createSession(pingbackType, action, responseId, loggedInUserId);
send_pingback_1.sendPingback(session);
// empty this specific batch
actionMap[responseId] = [];
}
});
}
});
}
function createPingbackAction(actionType, gifId, tid, position) {
var attributes = [];
if (position) {
attributes.push({
key: "position",
value: JSON.stringify(position),
});
}
return {
action_type: actionType,
ts: new Date().getTime(),
gif_id: gifId,
tid: tid,
attributes: attributes,
};
}
var formatPingbackAndFire = function (_a, user, searchResponseId, actionType, category, position) {
var id = _a.id, _b = _a.bottle_data, bottle_data = _b === void 0 ? { tid: '' } : _b;
var debouncedPingbackEvent = throttle_debounce_1.debounce(1000, fetchPingbackRequest);
var pingback = function (_a) {
var gif = _a.gif, user = _a.user, responseId = _a.responseId, pingbackType = _a.type, actionType = _a.actionType, position = _a.position;
var id = gif.id, _b = gif.bottle_data, bottle_data = _b === void 0 ? {} : _b;
var tid = bottle_data.tid;
var action = createPingbackAction(actionType, id, tid, position);
firePingback(action, category, searchResponseId, user, !!tid);
// save the user id for whenever create session is invoked
loggedInUserId = user && user.id ? String(user.id) : loggedInUserId;
// the queue doesn't exist for this pingbackType yet so create it
if (!queuedPingbacks[pingbackType])
queuedPingbacks[pingbackType] = {};
// a map of actions based on pingback type
var actionMap = queuedPingbacks[pingbackType]; // we just created it so ! is ok
// create the searchRepsonseId queue
if (!actionMap[responseId])
actionMap[responseId] = [];
// add the action
actionMap[responseId].push(util_1.getAction(actionType, String(id), tid, position));
// if there's a tid, skip the queue
tid ? fetchPingbackRequest() : debouncedPingbackEvent();
};
var pingback = function (_a) {
var gif = _a.gif, user = _a.user, searchResponseId = _a.searchResponseId, category = _a.category, action = _a.action, position = _a.position;
return formatPingbackAndFire(gif, user, searchResponseId, action, category, position);
};
exports.default = pingback;
//# sourceMappingURL=pingback.js.map

@@ -1,3 +0,18 @@

export declare type IPingbackUser = {
id?: number;
import { IGif, IUser } from '@giphy/js-types';
export declare type Pingback = {
gif: IGif;
user: Partial<IUser>;
type: PingbackEventType;
responseId: string;
actionType: PingbackActionType;
position?: ClientRect;
};
export declare type PingbackActionType = 'CLICK' | 'SEEN' | 'HOVER';
export declare type PingbackRequestAction = {
action_type: PingbackActionType;
attributes: any;
gif_id: string;
tid?: string;
ts: number;
};
export declare type PingbackEventType = 'GIF_TRENDING' | 'GIF_RELATED' | 'GIF_CHANNEL' | 'GIF_SEARCH' | 'GIF_EXPLORE';

@@ -5,6 +5,9 @@ {

"dev": "tsc --watch",
"build": "npm run clean && tsc"
"build": "npm run clean && tsc",
"refresh": "tsc",
"test": "jest --config ./jestconfig.js",
"test:watch": "jest --config ./jestconfig.js --watchAll"
},
"name": "@giphy/js-analytics",
"version": "1.0.1",
"version": "1.0.2",
"main": "dist/index.js",

@@ -17,14 +20,18 @@ "types": "dist/index.d.ts",

"dependencies": {
"@giphy/js-types": "^1.0.1",
"@giphy/js-types": "^1.0.2",
"@giphy/js-util": "^1.0.2",
"cookie": "0.3.1",
"dompurify": "^1.0.10",
"lodash": "4.17.11"
"lodash": "4.17.11",
"throttle-debounce": "^2.1.0"
},
"devDependencies": {
"@types/cookie": "^0.3.2",
"@types/lodash": "^4.14.121",
"parcel-bundler": "^1.12.0",
"typescript": "^3.3.3"
"@types/lodash": "^4.14.123",
"@types/throttle-debounce": "1.1.1",
"jest-fetch-mock": "^2.1.1",
"parcel-bundler": "^1.12.3",
"typescript": "^3.3.4"
},
"gitHead": "1d3ed46de5181c223e0596a37f8fdb02442b49f5"
"gitHead": "0dc93b5f9813ca1ab4c84feaa9e59415863bd116"
}

Sorry, the diff of this file is not supported yet

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