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

pinterest-conversions-server

v3.0.1

Published

A simple package to integrate Pinterest Tag and Conversions API.

Downloads

1,081

Readme

Pinterest Conversions Server & API

This package simplifies the integration of Pinterest's Conversion API for tracking conversion events. It includes tools server-side event tracking (Pinterest Conversion API).

Installation

npm install pinterest-conversions-server

Features

  • Pinterest Conversion API: Server-side event tracking using the Pinterest API.
  • Express Server Integration: Easily set up an API server for handling conversion events.
  • Test Environment Support: Send test events for validation.

Usage

1. Import and Initialize

import {
  PinterestConversionsServer,
  PinterestConversionsAPI,
} from "pinterest-conversions-server";

3. Pinterest Conversions API (Server-Side)

a. Initialize the API Client

const conversionsAPI = new PinterestConversionsAPI("<ACCESS_TOKEN>");

b. Track an Event

const data = {
  event_name: "custom",
  action_source: "web",
  event_time: Math.floor(Date.now() / 1000),
  event_id: "eventId001",
  user_data: {
    external_id: ["<hashed_external_id>"],
    em: ["<hashed_email>"],
    client_user_agent: "user-agent",
    client_ip_address: "123.45.67.89",
  },
};

const response = await conversionsAPI.trackEvent("<ADVERTISER_ID>", data);
console.log(response);

c. Send Test Events

const testResponse = await conversionsAPI.trackEventTest(
  "<ADVERTISER_ID>",
  data
);
console.log(testResponse);

4. Pinterest Conversions Server

a. Start the Server

new PinterestConversionsServer(
  "<ACCESS_TOKEN>",
  "<ADVERTISER_ID>"
).startPinterestApiServer(3000);

b. API Endpoints

  • POST /track-event

    • Body:
      {
        "advertiser_id": "<ADVERTISER_ID>",
        "event_data": { ...eventPayload }
      }
  • POST /track-event-test

    • Body: Same as /track-event but validates test events.

Example Implementation Outside the Package

import { PinterestConversionsServer } from "pinterest-conversions-server";

const TOKEN = "<ACCESS_TOKEN>";
const ADVERTISER = "<ADVERTISER_ID>";

new PinterestConversionsServer(TOKEN, ADVERTISER).startPinterestApiServer(3001);

Interfaces

PinterestEvent

interface PinterestEvent {
  event_name: string;
  action_source: string;
  event_time: number;
  event_id?: string;
  user_data: Record<string, string | number | boolean | Array<string>>;
}

TrackEventResponse

interface TrackEventResponse {
  status?: number;
  [key: string]: any;
}

TrackEventRequest

interface TrackEventRequest {
  advertiser_id: string;
  event_data: PinterestEvent;
}

Development

Testing

  • Run the server and test API endpoints using Postman or similar tools.
  • Use mock data for advertiser_id and event_data.

Example Data

{
  "event_name": "purchase",
  "action_source": "web",
  "event_time": 1609459200,
  "user_data": {
    "em": ["hashed_email"],
    "external_id": ["hashed_id"]
  }
}

Notes

  • Ensure all sensitive data is hashed as required by Pinterest API.
  • The server includes CORS support. Adjust allowed origins as needed for security.

License

MIT