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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@intract/attribution

v2.0.0

Published

This SDK can be used to track attribution data for your app. It is designed to privacy preserving and easy to use.

Downloads

330

Readme

Attribution-SDK

This SDK can be used to track attribution data for your app. It is designed to privacy preserving and easy to use.

To use this SDK, you need to sign up on Intract and get your API key.

Installation

npm i @intract/attribution

Usage

You need to initialize the SDK in the root component of your app (App.ts in case of React).

Import

import IntractAttribution from "@intract/attribution";

Initialize

useEffect(() => {
    IntractAttribution(<YOUR_APP_ID>, {
        configAllowCookie: true,
    });
}, []);

TrackWallet

You can track wallet by directly passing the address in trackCustomWallet function.

To use, import:

import {trackCustomWallet} from "@intract/attribution";

You need to pass user address as parameter to trackCustomWallet function in your auth flow:

function connectWallet(){
    //after your wallet authentication flow
    trackCustomWallet("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045");
}

For NextJs:

To initialize our SDK in NextJs and similar frameworks that use SSR (server side rendering), you must take a few extra steps as our SDK depends on window object.

Create a Component

Create a new, empty component (Tracking.jsx in our case) and initialize the SDK as shown in the above steps.

import React, {useEffect} from 'react'
import IntractAttribution from "@intract/attribution"


const Tracking = () => {

    useEffect(() => {
        IntractAttribution(<YOUR_APP_ID>, {
            configAllowCookie: true
        });
    }, [])

    return (
        <></>
    )
}

export default Tracking

We're going to render this empty component on the client side. To do that we're gonna use "next/dynamic". Then, Import this component into the page from which you want to collect data.

Home.jsx

import dynamic from "next/dynamic";
const Tracking = dynamic(() => import("path/to/Tracking.jsx"), {
    ssr: false
});


const Home = () => {
    return(
        <>
            <Tracking/>
            <h1>Homepage</h1>
            Your code goes here
        </>
    )
}

For any other function like trackCustomWallet or trackWalletConnect import it within the function where you want to call them like in the following snippet.

function connectWallet(){
    const {trackCustomWallet} = (await import('@intract/attribution')).default
    trackCustomWallet('0xkjasn..1291a')
}

Auto-wallet tracking

Note: Due to the unpredictable nature of the web3 wallet providers, your dApp may face issues while tracking the user's wallet address automatically using enableWalletActivityTracking or trackWalletConnect functions. We advise you to use only trackCustomWallet function to track the user's wallet address.

Still, In case you want to track wallet automatically, you can use the enableWalletActivityTracking function which triggers every time when "accountChanged" event triggers. Also you can use trackWalletConnect which can be called after the user connects wallets, and our sdk will automatically track the wallet address.

These function will track the user's wallet address whenever the user connects a new wallet address.

Initialize

useEffect(() => {
    IntractAttribution(<YOUR_APP_ID>, {
        configAllowCookie: true,
        useMetamask: true // needed to track wallet automatically
    });
}, []);

Methods

enableWalletActivityTracking

If you want to track the user's wallet address automatically, you can use the enableWalletActivityTracking function. This function will track the user's wallet address whenever the user connects a new wallet address.

To use, import:

import {enableWalletActivityTracking} from "@intract/attribution";

Call after initializing the SDK: Note: This function will only work if you have initialized the SDK with useMetamask: true option.

useEffect(() => {
    IntractAttribution(<YOUR_APP_ID>, {
        configAllowCookie: true
        useMetamask: true
    });
    enableWalletActivityTracking();
}, []);

TrackWalletConnect

In some cases, you can use trackWalletConnect function explicitly after the user connects wallets.

To use, import:

import {trackWalletConnect} from "@intract/attribution";

Call at the appropriate time: Note: This function will only work if you have initialized the SDK with useMetamask: true option.

function connectWallet(){
    //after connect wallet code
    trackWalletConnect();
}