Skip to content

Commit

Permalink
only send as attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
metal-messiah committed Feb 2, 2025
1 parent d046881 commit 0624d83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/features/generic_events/aggregate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ export class Aggregate extends AggregateBase {
}

const { userJourneyPaths, userJourneyTimestamps } = agentRef.runtime.session.read()
const splitPaths = userJourneyPaths?.split('>')
this.userJourney = {
host: globalScope.location?.host,
paths: userJourneyPaths,
timestamps: userJourneyTimestamps,
navs: userJourneyPaths.split('>').length,
maxSizeReached: false
navs: splitPaths.length,
maxSizeReached: false,
...(splitPaths.length && splitPaths.reduce((acc, path, i) => {
acc['path' + i] = path
return acc
}, {}))
}

this.waitForFlags(['ins']).then(([ins]) => {
Expand All @@ -54,7 +59,10 @@ export class Aggregate extends AggregateBase {
pathname
// search
} = new URL(url)
if (this.userJourney.paths.length + pathname.length + hash.length > 4096 || this.userJourney.timestamps.length + ('' + timestamp).length > 4096) {
if (
// this.userJourney.paths.length + pathname.length + hash.length > 4096 ||
this.userJourney.timestamps.length + ('' + timestamp).length > 4096 ||
this.userJourney.navs >= 254) {
this.userJourney.maxSizeReached = true
return

Check warning on line 67 in src/features/generic_events/aggregate/index.js

View check run for this annotation

Codecov / codecov/patch

src/features/generic_events/aggregate/index.js#L66-L67

Added lines #L66 - L67 were not covered by tests
}
Expand All @@ -63,19 +71,18 @@ export class Aggregate extends AggregateBase {
this.userJourney.paths += pathname + hash
if (this.userJourney.timestamps) this.userJourney.timestamps += '>'
this.userJourney.timestamps += this.agentRef.runtime.timeKeeper.correctRelativeTimestamp(timestamp)
this.userJourney.navs++

this.userJourney['path' + this.userJourney.navs++] = pathname + hash

this.syncWithSessionManager({ userJourneyPaths: this.userJourney.paths, userJourneyTimestamps: this.userJourney.timestamps })
}, this.featureName, this.ee)
this.beforeUnloadFns.push(() => {
if (!this.userJourney.paths) return
const { paths, ...rest } = this.userJourney
this.addEvent({

Check warning on line 82 in src/features/generic_events/aggregate/index.js

View check run for this annotation

Codecov / codecov/patch

src/features/generic_events/aggregate/index.js#L81-L82

Added lines #L81 - L82 were not covered by tests
eventType: 'SessionMetadata',

maxSizeReached: this.userJourney.maxSizeReached,
navs: this.userJourney.navs,
host: this.userJourney.host,
paths: this.userJourney.paths,
timestamps: this.userJourney.timestamps
})
...rest
}, true, true)
})

registerHandler('api-recordCustomEvent', (timestamp, eventType, attributes) => {
Expand Down Expand Up @@ -267,7 +274,7 @@ export class Aggregate extends AggregateBase {
* @param {object=} obj the event object for storing in the event buffer
* @returns void
*/
addEvent (obj = {}) {
addEvent (obj = {}, ignoreDefaultAttributes = false, ignoreCustomAttributes = false) {
if (!obj || !Object.keys(obj).length) return
if (!obj.eventType) {
warn(44)
Expand All @@ -289,9 +296,9 @@ export class Aggregate extends AggregateBase {

const eventAttributes = {
/** Agent-level custom attributes */
...(this.agentRef.info.jsAttributes || {}),
...(!ignoreCustomAttributes && (this.agentRef.info.jsAttributes || {})),
/** Fallbacks for required properties in-case the event did not supply them, should take precedence over agent-level custom attrs */
...defaultEventAttributes,
...(!ignoreDefaultAttributes && defaultEventAttributes),
/** Event-specific attributes take precedence over agent-level custom attributes and fallbacks */
...obj
}
Expand Down
2 changes: 2 additions & 0 deletions tests/components/spa/route-change.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import helpers from './helpers'
import { ee } from '../../../src/common/event-emitter/contextual-ee'
import { Spa } from '../../../src/features/spa'

jest.retryTimes(3)

jest.mock('../../../src/common/constants/runtime')
jest.mock('../../../src/common/config/info', () => ({
__esModule: true,
Expand Down

0 comments on commit 0624d83

Please sign in to comment.