Skip to content

Commit dd4b14d

Browse files
committed
wip
1 parent b17f6e5 commit dd4b14d

File tree

1 file changed

+18
-10
lines changed
  • packages/browser/src/core/arguments-resolver

1 file changed

+18
-10
lines changed

packages/browser/src/core/arguments-resolver/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,31 @@ export function resolvePageArguments(
7676
let resolvedName: string | undefined | null = null
7777
const args = [category, name, properties, options, callback]
7878

79-
if (typeof args[0] === 'string') {
80-
resolvedCategory = args[0]
81-
}
82-
if (typeof args[1] === 'string') {
83-
resolvedName = args[1]
84-
}
85-
86-
// if there is just one string in the first two args, it's the name
87-
const strings = [args[0], args[1]].filter(isString)
79+
// handle:
80+
// - analytics.page('name')
81+
// - analytics.page('category', 'name')
82+
const strings = args.filter(isString)
8883
if (strings.length === 1) {
8984
resolvedCategory = null
9085
resolvedName = strings[0]
86+
} else if (strings.length === 2) {
87+
if (typeof args[0] === 'string') {
88+
resolvedCategory = args[0]
89+
}
90+
if (typeof args[1] === 'string') {
91+
resolvedName = args[1]
92+
}
9193
}
9294

93-
// if there is any function, it's always the callback
95+
// handle: analytics.page('category', 'name', properties, options, callback)
9496
const resolvedCallback = args.find(isFunction) as Callback | undefined
9597

98+
// handle:
99+
// - analytics.page(properties)
100+
// - analytics.page(properties, options)
101+
// - analytics.page('name', properties)
102+
// - analytics.page('name', properties, options)
103+
// - analytics.page('category', 'name', properties, options)
96104
args.forEach((obj, argIdx) => {
97105
if (isPlainObject(obj)) {
98106
if (argIdx === 0) {

0 commit comments

Comments
 (0)