diff --git a/src/lib/page.js b/src/lib/page.js index 6543752..d2e77d0 100644 --- a/src/lib/page.js +++ b/src/lib/page.js @@ -25,25 +25,11 @@ export default function page (...args) { } if (route) { - const { - router, - autoTracking: { - transformQueryString, - prependBase - } - } = config - - const queryString = getQueryString(route.query) - const base = router && router.options.base - const needsBase = prependBase && base - - let path = route.path + (transformQueryString ? queryString : '') - path = needsBase ? getBasePath(base, path) : path - - set('page', path) - query('send', 'pageview') + trackRoute(route) } else { - set('page', args[0].page) + // We can call with `page('/my/path')` + let page = typeof args[0] === 'object' ? args[0].page : args[0] + set('page', page) query('send', 'pageview', ...args) } } @@ -68,7 +54,26 @@ export function trackRoute (route) { return } - page(proxy ? proxy(route) : route) + if (proxy) { + page(proxy(route)) + } else { + const { + router, + autoTracking: { + transformQueryString, + prependBase + } + } = config + + const queryString = getQueryString(route.query) + const base = router && router.options.base + const needsBase = prependBase && base + + let path = route.path + (transformQueryString ? queryString : '') + path = needsBase ? getBasePath(base, path) : path + + page(path) + } } export function autoTracking () {