🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-tracker-teko

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-tracker-teko - npm Package Compare versions

Comparing version

to
3.1.5

3

dist/common.d.ts

@@ -12,1 +12,4 @@ import { UseTrackPageViewT } from "./types";

};
export declare const getLocationFromString: (href: string) => HTMLAnchorElement;
export declare const getPreviousFullPath: (prevLoc: any, currentLoc: any) => string;
export declare const getMatchRoute: (path: string, routes: any) => any;

@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () {

};
import { matchPath } from "react-router-dom";
export var getProtocal = function (loc) {

@@ -31,2 +32,39 @@ // Protocol may or may not contain a colon

export var getPropsPageView = function (props) { return (__assign({}, props)); };
export var getLocationFromString = function (href) {
var l = document.createElement("a");
l.href = href;
return l;
};
export var getPreviousFullPath = function (prevLoc, currentLoc) {
var previousFullPath = null;
if (!prevLoc) {
if (!document.referrer) {
previousFullPath = getFullPath(currentLoc);
}
else {
previousFullPath = document.referrer;
}
}
else {
previousFullPath = getFullPath(prevLoc);
}
return previousFullPath;
};
export var getMatchRoute = function (path, routes) {
var pathname = getLocationFromString(path).pathname;
var matches = routes
.map(function (route) {
return { match: matchPath(pathname, route), route: route };
})
.filter(function (_a) {
var match = _a.match;
return !!match;
});
if (matches && matches.length !== 0) {
var _a = matches[0], match = _a.match, route = _a.route;
var others = route.parser ? route.parser(path, match) : {};
return __assign(__assign({}, route), others);
}
return {};
};
//# sourceMappingURL=common.js.map

6

dist/index.d.ts

@@ -1,2 +0,2 @@

import { InitContructor } from "./types";
import { InitContructor, RouteParamT } from "./types";
declare class ReactTracker {

@@ -7,5 +7,7 @@ private previousPath;

private history;
private routes;
constructor(setupOptions: InitContructor);
connectToHistory(history: any): any;
connectToHistory(history: any, routes?: RouteParamT[]): any;
disconnectFromHistory(): boolean;
private getExtraAttr;
private registerListener;

@@ -12,0 +14,0 @@ private track;

@@ -12,3 +12,3 @@ var __assign = (this && this.__assign) || function () {

};
import { getPath, getFullPath } from "./common";
import { getPath, getFullPath, getPreviousFullPath, getMatchRoute, } from "./common";
var defaultOptions = {

@@ -54,2 +54,3 @@ host: "https://dev-tracking.teko.vn",

var _this = this;
this.routes = [];
this.registerListener = function (history) {

@@ -60,5 +61,6 @@ var prevLoc = typeof history.getCurrentLocation === "undefined"

_this.previousPath = getPath(prevLoc);
_this.previousFullPath = getFullPath(prevLoc);
_this.previousFullPath = getPreviousFullPath(null, prevLoc);
window.track("setReferrerUrl", _this.previousFullPath);
window.track("trackLoadPageView");
var currentFullPath = document.location.href;
window.track("trackLoadPageView", __assign({}, _this.getExtraAttr(currentFullPath)));
_this.unlistenFromHistory = history.listen(function (loc) {

@@ -75,7 +77,8 @@ _this.track(loc);

}
ReactTracker.prototype.connectToHistory = function (history) {
ReactTracker.prototype.connectToHistory = function (history, routes) {
if (routes === void 0) { routes = []; }
this.routes = routes;
if (this.history) {
return history;
}
window.track("enableUnloadPageView");
this.history = history;

@@ -92,2 +95,8 @@ this.registerListener(history);

};
ReactTracker.prototype.getExtraAttr = function (currentPath) {
if (!this.routes || this.routes.length === 0)
return {};
var _a = getMatchRoute(currentPath, this.routes) || {}, contentType = _a.contentType, screenName = _a.screenName, skuId = _a.skuId, skuName = _a.skuName;
return JSON.parse(JSON.stringify({ contentType: contentType, screenName: screenName, skuId: skuId, skuName: skuName }));
};
ReactTracker.prototype.track = function (loc) {

@@ -103,7 +112,8 @@ if (typeof window === "undefined") {

window.track("setCurrentUrl", this.previousFullPath);
window.track("trackUnLoadPageView");
window.track("trackUnLoadPageView", __assign({}, this.getExtraAttr(this.previousFullPath)));
window.track("setReferrerUrl", this.previousFullPath);
window.track("setCurrentUrl", currentFullPath);
window.track("trackLoadPageView");
window.track("trackLoadPageView", __assign({}, this.getExtraAttr(currentFullPath)));
this.previousPath = currentPath;
this.previousFullPath = currentFullPath;
};

@@ -110,0 +120,0 @@ return ReactTracker;

import * as React from "react";
import { useEffect } from "react";
import TrackerContext from "./TrackerContext";
import { getPropsPageView, getFullPath } from "./common";
import { getPropsPageView, getFullPath, getPreviousFullPath } from "./common";
var mPrevLoc;

@@ -26,14 +26,3 @@ var loc = null;

var callTrackLoadPage = function (props) {
var previousFullPath = null;
if (!mPrevLoc) {
if (!document.referrer) {
previousFullPath = getFullPath(loc);
}
else {
previousFullPath = document.referrer;
}
}
else {
previousFullPath = getFullPath(mPrevLoc);
}
var previousFullPath = getPreviousFullPath(mPrevLoc, loc);
var currentFullPath = getFullPath(loc);

@@ -40,0 +29,0 @@ window.track("setReferrerUrl", previousFullPath);

/// <reference types="react" />
import { History } from "history";
import { match } from "react-router-dom";
export interface PropsProviderT {

@@ -18,2 +19,15 @@ children: React.ReactNode;

}
export interface ParserResponseT {
skuId?: string;
skuName?: string;
}
export interface RouteParamT {
path?: string;
exact?: boolean;
sensitive?: boolean;
strict?: boolean;
screenName?: string;
contentType?: string;
parser?: (url: string, match: match) => ParserResponseT;
}
export interface Instance {

@@ -20,0 +34,0 @@ callTrackLoadPage: (props: UseTrackPageViewT) => void;

{
"name": "react-tracker-teko",
"version": "3.1.4",
"version": "3.1.5",
"main": "dist/index.js",

@@ -18,3 +18,4 @@ "types": "dist/index.d.ts",

"@types/history": "^4.7.5",
"@types/react": "^16.9.20",
"@types/react": "^16.9.43",
"@types/react-router-dom": "^5.1.5",
"history": "^4.10.1",

@@ -25,3 +26,4 @@ "husky": "^4.2.5",

"peerDependencies": {
"react": ">=16.8.0"
"react": ">=16.8.0",
"react-router-dom": "^5.2.0"
},

@@ -28,0 +30,0 @@ "husky": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet