@giphy/js-analytics
Advanced tools
Comparing version 2.2.1 to 3.0.0
import { Pingback } from './types'; | ||
declare const pingback: ({ gif, userId, eventType, actionType, attributes, queueEvents }: Pingback) => void; | ||
declare const pingback: ({ userId, eventType, actionType, attributes, queueEvents, analyticsResponsePayload, }: Pingback) => void; | ||
export default pingback; |
@@ -27,3 +27,3 @@ "use strict"; | ||
var pingback = function (_a) { | ||
var gif = _a.gif, userId = _a.userId, eventType = _a.eventType, actionType = _a.actionType, attributes = _a.attributes, _b = _a.queueEvents, queueEvents = _b === void 0 ? true : _b; | ||
var userId = _a.userId, eventType = _a.eventType, actionType = _a.actionType, attributes = _a.attributes, _b = _a.queueEvents, queueEvents = _b === void 0 ? true : _b, analyticsResponsePayload = _a.analyticsResponsePayload; | ||
// save the user id for whenever create session is invoked | ||
@@ -36,2 +36,3 @@ loggedInUserId = userId ? String(userId) : loggedInUserId; | ||
user_id: js_util_1.getPingbackId(), | ||
analytics_response_payload: analyticsResponsePayload, | ||
}; | ||
@@ -41,10 +42,5 @@ if (loggedInUserId) { | ||
} | ||
if (gif) { | ||
if (!gif.analytics_response_payload) { | ||
js_util_1.Logger.debug("no pingback for " + gif.id + ", not all endpoints have ARPs"); | ||
// abort pingback, analytics_response_payload is required for gif events | ||
return; | ||
} | ||
var gifEvent = newEvent; | ||
gifEvent.analytics_response_payload = "" + gif.analytics_response_payload + (js_util_1.Logger.ENABLED ? '&mode=verification' : ''); | ||
// add verification mode | ||
if (newEvent.analytics_response_payload) { | ||
newEvent.analytics_response_payload = "" + newEvent.analytics_response_payload + (js_util_1.Logger.ENABLED ? '&mode=verification' : ''); | ||
} | ||
@@ -51,0 +47,0 @@ if (eventType) { |
@@ -1,2 +0,2 @@ | ||
import { IGif, PingbackEventType } from '@giphy/js-types'; | ||
import { PingbackEventType } from '@giphy/js-types'; | ||
export declare type PingbackAttributes = { | ||
@@ -6,3 +6,2 @@ [key: string]: string; | ||
export declare type Pingback = { | ||
gif?: IGif; | ||
userId?: string | number; | ||
@@ -13,2 +12,3 @@ eventType?: PingbackEventType; | ||
queueEvents?: boolean; | ||
analyticsResponsePayload: string; | ||
}; | ||
@@ -24,5 +24,3 @@ export declare type PingbackActionType = 'CLICK' | 'SEEN' | 'HOVER' | 'FAVORITE' | 'SENT'; | ||
ts: number; | ||
analytics_response_payload?: string; | ||
}; | ||
export declare type PingbackGifEvent = PingbackEvent & { | ||
analytics_response_payload: string; | ||
}; |
@@ -11,3 +11,3 @@ { | ||
"name": "@giphy/js-analytics", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"main": "dist/index.js", | ||
@@ -24,4 +24,4 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@giphy/js-types": "^3.0.1", | ||
"@giphy/js-util": "^2.1.1", | ||
"@giphy/js-types": "^3.1.0", | ||
"@giphy/js-util": "^2.2.0", | ||
"append-query": "^2.1.0", | ||
@@ -36,3 +36,3 @@ "throttle-debounce": "^2.3.0" | ||
}, | ||
"gitHead": "6f3eff856199c719d208dd1350c9490488eda2b5" | ||
"gitHead": "e44fe56b1cc4b4f7180a8e6759cb2710bc91f89d" | ||
} |
@@ -18,2 +18,3 @@ import { IGif, IUser } from '@giphy/js-types' | ||
test('no gif, but pingback type', () => { | ||
// @ts-ignore | ||
pingback({ | ||
@@ -38,3 +39,3 @@ actionType: 'CLICK', | ||
pingback({ | ||
gif: gif as IGif, | ||
analyticsResponsePayload: gif.analytics_response_payload || '', | ||
actionType: 'CLICK', | ||
@@ -58,3 +59,3 @@ queueEvents: false, | ||
pingback({ | ||
gif: gif as IGif, | ||
analyticsResponsePayload: gif.analytics_response_payload || '', | ||
actionType: 'CLICK', | ||
@@ -78,3 +79,3 @@ queueEvents: false, | ||
pingback({ | ||
gif: gif as IGif, | ||
analyticsResponsePayload: gif.analytics_response_payload || '', | ||
userId: user?.id, | ||
@@ -86,3 +87,3 @@ actionType: 'FAVORITE', | ||
pingback({ | ||
gif: gif as IGif, | ||
analyticsResponsePayload: gif.analytics_response_payload || '', | ||
actionType: 'SEEN', | ||
@@ -122,16 +123,5 @@ queueEvents: false, | ||
}) | ||
test('no analytics_response_payload should abort', () => { | ||
const testGif = { ...gif } as IGif | ||
testGif.analytics_response_payload = '' | ||
pingback({ | ||
gif: testGif, | ||
actionType: 'CLICK', | ||
queueEvents: false, | ||
}) | ||
expect(fetch.mock.calls.length).toEqual(0) | ||
}) | ||
test('request custom attributes', () => { | ||
pingback({ | ||
gif: gif as IGif, | ||
analyticsResponsePayload: gif.analytics_response_payload || '', | ||
actionType: 'CLICK', | ||
@@ -158,3 +148,3 @@ attributes: { position: `1` }, | ||
pingback({ | ||
gif: gif as IGif, | ||
analyticsResponsePayload: gif.analytics_response_payload || '', | ||
actionType: 'CLICK', | ||
@@ -161,0 +151,0 @@ }) |
@@ -5,3 +5,3 @@ import { getPingbackId, Logger } from '@giphy/js-util' | ||
import { sendPingback } from './send-pingback' | ||
import { Pingback, PingbackEvent, PingbackGifEvent } from './types' | ||
import { Pingback, PingbackEvent } from './types' | ||
@@ -22,3 +22,10 @@ let queuedPingbackEvents: PingbackEvent[] = [] | ||
const pingback = ({ gif, userId, eventType, actionType, attributes, queueEvents = true }: Pingback) => { | ||
const pingback = ({ | ||
userId, | ||
eventType, | ||
actionType, | ||
attributes, | ||
queueEvents = true, | ||
analyticsResponsePayload, | ||
}: Pingback) => { | ||
// save the user id for whenever create session is invoked | ||
@@ -32,2 +39,3 @@ loggedInUserId = userId ? String(userId) : loggedInUserId | ||
user_id: getPingbackId(), | ||
analytics_response_payload: analyticsResponsePayload, | ||
} | ||
@@ -39,10 +47,5 @@ | ||
if (gif) { | ||
if (!gif.analytics_response_payload) { | ||
Logger.debug(`no pingback for ${gif.id}, not all endpoints have ARPs`) | ||
// abort pingback, analytics_response_payload is required for gif events | ||
return | ||
} | ||
const gifEvent = newEvent as PingbackGifEvent | ||
gifEvent.analytics_response_payload = `${gif.analytics_response_payload}${ | ||
// add verification mode | ||
if (newEvent.analytics_response_payload) { | ||
newEvent.analytics_response_payload = `${newEvent.analytics_response_payload}${ | ||
Logger.ENABLED ? '&mode=verification' : '' | ||
@@ -49,0 +52,0 @@ }` |
@@ -1,2 +0,2 @@ | ||
import { IGif, PingbackEventType } from '@giphy/js-types' | ||
import { PingbackEventType } from '@giphy/js-types' | ||
@@ -6,4 +6,2 @@ export type PingbackAttributes = { [key: string]: string } | ||
export type Pingback = { | ||
// for pingbacks with GIFs | ||
gif?: IGif | ||
userId?: string | number | ||
@@ -14,2 +12,3 @@ eventType?: PingbackEventType | ||
queueEvents?: boolean | ||
analyticsResponsePayload: string | ||
} | ||
@@ -27,6 +26,3 @@ | ||
ts: number | ||
analytics_response_payload?: string | ||
} | ||
export type PingbackGifEvent = PingbackEvent & { | ||
analytics_response_payload: string | ||
} |
Sorry, the diff of this file is not supported yet
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
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
21922
439
Updated@giphy/js-types@^3.1.0
Updated@giphy/js-util@^2.2.0