-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browsi Moduleで開催されたオークションでPrebid Analyticsを送信できるようにする #4
Changes from 1 commit
45c0fd3
9ea3ffc
ebb8e94
b3c2d38
476ae68
c3ffdb9
44964be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,11 @@ const isBrowsiAuction = (auctionId) => { | |
const siteKey = find(pbjs.getConfig().realTimeData?.dataProviders ?? [], provider => provider.name === 'browsi')?.params.siteKey | ||
return Boolean(auctionId.match(new RegExp(`^${siteKey}`, 'g'))) | ||
} | ||
/** | ||
* @param {string} divId | ||
* @returns {boolean} | ||
*/ | ||
const isBrowsiDivId = (divId) => Boolean(divId.match(/^browsi_ad_/g)) | ||
|
||
/* eslint-disable-next-line compat/compat */ | ||
let fluctAnalyticsAdapter = Object.assign( | ||
|
@@ -189,6 +194,17 @@ let fluctAnalyticsAdapter = Object.assign( | |
} | ||
break; | ||
} | ||
// 全てnobid時発火しない | ||
case CONSTANTS.EVENTS.SET_TARGETING: { | ||
let setTargetingEvent = args | ||
/** @type {Array<String>} */ | ||
let divIds = Object.keys(setTargetingEvent) | ||
if (divIds.every(isBrowsiDivId)) { | ||
let auctionId = find(Object.values(cache.auctions), auction => find(auction.adUnits, adUnit => divIds.includes(adUnit.code)))?.auctionId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 setTargetingされた枠のdivIdからauctionIdを引いている |
||
sendMessage(auctionId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AUCTION_ENDイベント時に送信しなかった分をこっちで送っている |
||
} | ||
break; | ||
} | ||
case CONSTANTS.EVENTS.BID_WON: { | ||
/** @type {Bid} */ | ||
let bidWonEvent = args | ||
|
@@ -200,11 +216,9 @@ let fluctAnalyticsAdapter = Object.assign( | |
bidWon: true, | ||
timeout: false, | ||
}) | ||
if (!isBrowsiAuction(auctionId)) { | ||
cache.timeouts[auctionId] = setTimeout(() => { | ||
sendMessage(auctionId); | ||
}, pbjs.getConfig().bidderTimeout || 3000); | ||
} | ||
cache.timeouts[auctionId] = setTimeout(() => { | ||
sendMessage(auctionId); | ||
}, pbjs.getConfig().bidderTimeout || 3000); | ||
break; | ||
} | ||
default: | ||
|
@@ -233,15 +247,15 @@ export const getAdUnitCodeBeforeReplication = (slots, adUnitCode) => { | |
return slot.code === adUnitCode | ||
|| slot.code.match(new RegExp(`^${browsiPrefix}`, 'g'))?.[0] | ||
}) | ||
return find(slots, _slot => _slot.path === slot.path && !_slot.code.match(/^browsi_/g))?.code ?? adUnitCode | ||
return find(slots, _slot => _slot.path === slot.path && !isBrowsiDivId(_slot.code))?.code ?? adUnitCode | ||
} | ||
|
||
/** | ||
* @param {AdUnit} adUnit | ||
* @returns {AdUnit} | ||
*/ | ||
const modifyBrowsiAdUnit = (adUnit) => { | ||
if (!adUnit.code.match(/^browsi_/g)) return adUnit | ||
if (!isBrowsiDivId(adUnit.code)) return adUnit | ||
// e.g. | ||
// [ | ||
// [{ code: 'div-gpt-ad-1629864618640-0', path: '/62532913/p_fluctmagazine_320x50_surface_15377' }] | ||
|
@@ -272,7 +286,7 @@ const modifyBrowsiAuctionId = (auctionId, adUnits) => { | |
/** @type {string|undefined} */ | ||
const siteKey = find(pbjs.getConfig().realTimeData?.dataProviders ?? [], provider => provider.name === 'browsi')?.params.siteKey | ||
/** @type {string|undefined} */ | ||
const reloadCount = getBrowsiRefreshCount(find(adUnits, adUnit => adUnit.code.match(/^browsi_/g))?.code) | ||
const reloadCount = getBrowsiRefreshCount(find(adUnits, adUnit => isBrowsiDivId(adUnit.code))?.code) | ||
return auctionId.match(new RegExp(`^${siteKey}`, 'g')) && reloadCount | ||
? `${auctionId}_${reloadCount}` | ||
: auctionId | ||
|
@@ -333,10 +347,10 @@ const sendMessage = (auctionId) => { | |
ajax(url, () => utils.logInfo(`[sendMessage] ${Date.now()} :`, payload), JSON.stringify(payload), { contentType: 'application/json', method: 'POST' }); | ||
}; | ||
|
||
window.addEventListener('browsiImpression', (data) => { | ||
const auction = find(Object.values(cache.auctions), auction => auction.adUnitCodes.includes(data.detail.adUnit.code)) | ||
sendMessage(auction.auctionId) | ||
}) | ||
// window.addEventListener('browsiImpression', (data) => { | ||
// const auction = find(Object.values(cache.auctions), auction => auction.adUnitCodes.includes(data.detail.adUnit.code)) | ||
// sendMessage(auction.auctionId) | ||
// }) | ||
Comment on lines
+344
to
+347
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
fluctAnalyticsAdapter.originEnableAnalytics = fluctAnalyticsAdapter.enableAnalytics; | ||
fluctAnalyticsAdapter.enableAnalytics = (config) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
browsiImpression
実装までの繋ぎSET_TARGETING
browsi枠がGPTで定義された直後のタイミングAUCTION_END
時は未定義のため、analytics送信を遅らせる