npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@trede/backredirect

v0.0.3

Published

Sistema de redirecionamento de volta (Back Redirect) que intercepta a navegação do usuário e redireciona para uma URL específica quando ele tenta voltar na página.

Downloads

8

Readme

🔙 T3 BackRedirect

Sistema de redirecionamento de volta (Back Redirect) que intercepta a navegação do usuário e redireciona para uma URL específica quando ele tenta voltar na página.

NPM Version


✅ Funcionalidades

  • ✅ Intercepta cliques em links e adiciona ao histórico
  • ✅ Intercepta navegação de volta (botão voltar do navegador)
  • ✅ Redireciona automaticamente para URL configurada
  • ✅ Preserva parâmetros de busca (opcional)
  • ✅ Sistema de tracking e logs
  • ✅ Callbacks antes e depois do redirecionamento
  • ✅ Suporte a delay configurável
  • ✅ Modo debug para desenvolvimento
  • ✅ Bloqueio global anti-duplicação

✅ Instalação

npm install @trede/backredirect
# ou
yarn add @trede/backredirect
# ou
pnpm add @trede/backredirect

✅ Uso Básico (TypeScript / ESM)

import { init } from "@trede/backredirect";

const tracker = init({
  url: "https://example.com",
  preserveSearchParams: true,
  enabled: true,
  debug: true,
});

✅ Uso via Script Tag (AutoInit)

<script 
  src="https://cdn.jsdelivr.net/npm/@trede/backredirect/dist/index.global.js"
  data-backredirect
  data-url="https://example.com"
  data-preserve-search-params="true"
  data-enabled="true"
  data-debug="true"
  data-delay="0"
  data-force-redirect="false">
</script>

✅ Configuração (InitProps)

| Propriedade | Tipo | Padrão | Descrição | |---|---|---|---| | url | string | - | URL de destino | | preserveSearchParams | boolean | false | Mantém os query params | | enabled | boolean | true | Ativa/desativa o tracker | | delay | number | 0 | Delay antes do redirect | | forceRedirect | boolean | false | Redireciona imediatamente | | onBeforeRedirect | Function | () => {} | Executa antes do redirect | | onAfterRedirect | Function | () => {} | Executa após o redirect | | debug | boolean | false | Habilita logs |


✅ API Pública

| Função | Descrição | |---|---| | init(config) | Inicializa o tracker | | BackRedirectInit | Classe principal | | injectBackRedirect(config) | Injeta o sistema | | forceFakeHistoryEntry() | Adiciona entrada falsa ao histórico | | waitForFirstUserInteraction(callback) | Aguarda interação | | interceptLinkClicks() | Intercepta cliques | | interceptBackNavigation(targetUrl) | Intercepta volta | | executeRedirect(context) | Executa redirecionamento | | buildTargetUrl(config) | Constrói a URL final |


✅ Tipos Importantes

interface RedirectData {
  timestamp: number;
  currentUrl: string;
  targetUrl: string;
  referrer: string;
  sessionId: string;
  userAgent: string;
  screenResolution: string;
  timeOnPage: number;
  redirectType: "back" | "forward" | "external" | "fallback";
  preservedParams?: string;
  metadata?: Record<string, any>;
}

interface TrackerContext {
  config: Required<InitProps>;
  sessionId: string;
  startTime: number;
  redirectHistory: RedirectData[];
  isTracking: boolean;
  targetUrl: string;
}

✅ Fluxo Interno

  1. Inicializa configurações
  2. Gera Fake History Entry
  3. Aguarda primeira interação do usuário
  4. Intercepta cliques em links
  5. Monitora navegação de volta
  6. Executa o redirecionamento
  7. Dispara callbacks
  8. Salva histórico de redirecionamento

✅ Desenvolvimento Local

pnpm install
pnpm build
pnpm dev

✅ Estrutura Interna

src/
├── index.ts              # Exportações principais
├── init.ts               # Função de inicialização
├── types.ts              # Tipos globais
└── utils/
    ├── backRedirectTracker.ts
    ├── injectBackRedirect.ts
    ├── forceFakeHistoryEntry.ts
    ├── waitForFirstUserInteraction.ts
    ├── interceptLinkClicks.ts
    ├── interceptBackNavigation.ts
    ├── executeRedirect.ts
    ├── buildTargetUrl.ts
    ├── startTracking.ts
    ├── trackLinkClick.ts
    ├── trackHistoryNavigation.ts
    ├── trackPageExit.ts
    ├── saveRedirectData.ts
    ├── saveSessionDate.ts
    ├── generateSessionId.ts
    ├── log.ts
    ├── addMetaData.ts
    └── getSession.ts

✅ Licença

MIT