Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default callback => {
if (JS.browserOrNode().isBrowser && window.location) {
const url = window.location.href;
callback({ url });
} else if (JS.browserOrNode().isNode) {
// continue building on ssr
() => {}; // noop
} else {
throw new Error('Not supported');
}
};
/**
* Copyright (c) 2017, Philip Walton
*/
import { JS } from '@aws-amplify/core';
const proto =
JS.browserOrNode().isBrowser && window['Element']
? window['Element'].prototype
: null;
const nativeMatches = proto
? proto.matches ||
// @ts-ignore
proto.matchesSelector ||
// @ts-ignore
proto.webkitMatchesSelector ||
// @ts-ignore
proto.mozMatchesSelector ||
// @ts-ignore
proto.msMatchesSelector ||
// @ts-ignore
proto.oMatchesSelector
: null;
export default callback => {
if (JS.browserOrNode().isBrowser && window.location) {
const url = window.location.href;
callback({ url });
} else if (JS.browserOrNode().isNode) {
// continue building on ssr
() => {}; // noop
} else {
throw new Error('Not supported');
}
};
private _envCheck() {
if (!JS.browserOrNode().isBrowser) {
return false;
}
if (!document || !document.addEventListener) {
logger.debug('not in the supported web environment');
return false;
}
if (typeof document.hidden !== 'undefined') {
this._hidden = 'hidden';
this._visibilityChange = 'visibilitychange';
} else if (typeof document['msHidden'] !== 'undefined') {
this._hidden = 'msHidden';
this._visibilityChange = 'msvisibilitychange';
} else if (typeof document['webkitHidden'] !== 'undefined') {
this._hidden = 'webkitHidden';
const getUrl = () => {
if (!JS.browserOrNode().isBrowser) return '';
else return window.location.origin + window.location.pathname;
};
constructor(tracker, opts) {
if (!JS.browserOrNode().isBrowser || !window.addEventListener) {
logger.debug('not in the supported web environment');
return;
}
this._config = Object.assign({}, defaultOpts, opts);
this._tracker = tracker;
this._delegates = {};
this._trackFunc = this._trackFunc.bind(this);
logger.debug('initialize pageview tracker with opts', this._config);
this.configure(this._config);
}
private async _pageViewTrackDefault() {
if (!JS.browserOrNode().isBrowser || !window.addEventListener || !window.sessionStorage) {
logger.debug('not in the supported web enviroment');
return;
}
const url = this._config.getUrl();
const customAttrs = typeof this._config.attributes === 'function'?
await this._config.attributes() : this._config.attributes;
const attributes = Object.assign(
{
url
},
customAttrs
);
if (this._config.enable && !this._isSameUrl()) {
this._tracker(
{
private _pageViewTrackSPA() {
if (!JS.browserOrNode().isBrowser || !window.addEventListener || !history.pushState) {
logger.debug('not in the supported web enviroment');
return;
}
if (this._config.enable && !this._hasEnabled) {
MethodEmbed.add(history, 'pushState', this._trackFunc);
MethodEmbed.add(history, 'replaceState', this._trackFunc);
window.addEventListener('popstate', this._trackFunc);
this._trackFunc();
this._hasEnabled = true;
} else {
MethodEmbed.remove(history, 'pushState');
MethodEmbed.remove(history, 'replaceState');
window.removeEventListener('popstate', this._trackFunc);
this._hasEnabled = false;
}