@@ -16,6 +16,8 @@ import { obj, param } from '../url/encode'
1616import { warn } from '../util/console'
1717import { stringify } from '../util/stringify'
1818import { getSubmitMethod , xhr as xhrMethod , xhrFetch as fetchMethod } from '../util/submit-data'
19+ import { activatedFeatures } from '../util/feature-flags'
20+ import { dispatchGlobalEvent } from '../dispatch/global-event'
1921
2022const RETRY_FAILED = 'Harvester/Retry/Failed/'
2123const RETRY_SUCCEEDED = 'Harvester/Retry/Succeeded/'
@@ -80,7 +82,8 @@ export class Harvester {
8082 localOpts,
8183 submitMethod,
8284 cbFinished,
83- raw : aggregateInst . harvestOpts . raw
85+ raw : aggregateInst . harvestOpts . raw ,
86+ featureName : aggregateInst . featureName
8487 } )
8588 ranSend = true
8689 } )
@@ -114,7 +117,7 @@ const warnings = {}
114117 * @param {NetworkSendSpec } param0 Specification for sending data
115118 * @returns {boolean } True if a network call was made. Note that this does not mean or guarantee that it was successful.
116119 */
117- function send ( agentRef , { endpoint, targetApp, payload, localOpts = { } , submitMethod, cbFinished, raw } ) {
120+ function send ( agentRef , { endpoint, targetApp, payload, localOpts = { } , submitMethod, cbFinished, raw, featureName } ) {
118121 if ( ! agentRef . info . errorBeacon ) return false
119122
120123 let { body, qs } = cleanPayload ( payload )
@@ -172,6 +175,24 @@ function send (agentRef, { endpoint, targetApp, payload, localOpts = {}, submitM
172175 } )
173176 }
174177 }
178+
179+ dispatchGlobalEvent ( {
180+ agentIdentifier : agentRef . agentIdentifier ,
181+ loaded : ! ! activatedFeatures ?. [ agentRef . agentIdentifier ] ,
182+ type : 'data' ,
183+ name : 'harvest' ,
184+ feature : featureName ,
185+ data : {
186+ endpoint,
187+ headers,
188+ targetApp,
189+ payload,
190+ submitMethod : getSubmitMethodName ( ) ,
191+ raw,
192+ synchronousXhr : ! ! ( localOpts . isFinalHarvest && isWorkerScope )
193+ }
194+ } )
195+
175196 return true
176197
177198 function shouldRetry ( status ) {
@@ -183,6 +204,12 @@ function send (agentRef, { endpoint, targetApp, payload, localOpts = {}, submitM
183204 }
184205 return ( status >= 502 && status <= 504 ) || ( status >= 512 && status <= 530 )
185206 }
207+
208+ function getSubmitMethodName ( ) {
209+ if ( submitMethod === xhrMethod ) return 'xhr'
210+ if ( submitMethod === fetchMethod ) return 'fetch'
211+ return 'beacon'
212+ }
186213}
187214
188215/**
0 commit comments