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

@phntms/ft-react-components

v0.0.8-rc8

Published

A collection of UI/utility React/NextJS components for Phantom FT sites

Downloads

47

Readme

ft-react-components

NPM version Actions Status PR Welcome

A collection of React/NextJS UI and utility components for Phantom FT sites.

Introduction

Currently implemented:

  • FTTracker - Provides a context and hook for easier access to the FTTracker and ReactPlayerTracking tracking functions from @phntms/ft-lib.
  • FTCookieMessage - Wrapper loader for the standard FT origami cookie consent popup
  • FTFooter - Renders the standard FT partner site footer
  • FTHeader - Renders the standard FT partner site header.
  • FTPartnerContent - Renders the FT partner header
  • ShareButton - used in the FTPartnerContent component
  • PermutiveSetup - Outputs the Permutive tracking scripts for FT partner sites.
  • PreviewMessage - a component to display a preview mode indicator for sites using Directus CMS.
  • BrandMetricsSurvey - A component that loads the BrandMetrics script and survey to the page.
  • TrackingPixel - A component for (hidden) tracking pixels.

Installation

Install this package with npm.

npm i @phntms/ft-react-components

Usage

FTTracker

Add the provider to _app.tsx, pass the site's page content to PageViewData

import { FTTrackerProvider } from "@phntms/ft-react-components";
.
.
.
return (
<FTTrackerProvider>
    <PageViewData pageProps={pageProps} />
    <Component {...pageProps} />;
  </FTTrackerProvider>
)

Construct the pageViewData object from the site content data. use setPageViewData and setTrackingOptions to update the tracker provider. See the Phantom FT partner tracking implementation guide for the full config object schema. TODO - consider moving to this lib with empty/default values and adding Yup validation to console error/eslint when incomplete.

import { useFTTracker, TrackingOptions, ConfigType } from "@phntms/ft-react-components";
.
.
const { setPageViewData, setTrackingOptions } = useFTTracker();

 useEffect(() => {
    const globals = pageProps.globals;
    const article = pageProps.article;
    const category = pageProps.category;

    setTrackingOptions({
      scrollTrackerSelector: "#o_tracker_scroll",
      isCustomGTMEvent: true,
      sendGTMPageViewYN: true,
    });

      const errorValue = "404";
    if (!setPageViewData) return;
    setPageViewData({
      advertiserIndustry: (globals && globals.sitewide.industry) || errorValue,
      app:
        (article && article.content_type) ||
        (globals && globals.sitewide.homepage_label) ||
        errorValue,
      articleName:
        (article && article.title) ||
        (globals && globals.sitewide.homepage_label) ||
        errorValue,
      author:
      .
      .
      .
      } as ConfigType);
    }, [pageProps]);

Video tracking

Video event tracking is handled by the videoTracker instance available from the useFTTracker hook. It is currently only compatible with react-player implementations which is the current standard player implementation for Phantom NextJS sites.

import { useFTTracker } from "@phntms/ft-react-components";
import ReactPlayer from "react-player";
.
.
const { videoTracker } = useFTTracker();
.
.
<ReactPlayer
  controls
  height="100%"
  style={{ position: "absolute", top: 0, left: 0 }}
  onDuration={videoTracker?.setDuration}
  onEnded={videoTracker?.trackEnded}
  onPause={videoTracker?.trackPause}
  onPlay={videoTracker?.trackPlay}
  onProgress={videoTracker?.trackProgress}
  width="100%"
  url={fileToURL(article.video)}
  light={fileToURL(article.image)}
  playIcon={<PlayIconCircle />}
  onClick={handlePlayButtonClick}
/>

PermutiveSetup

Loads the external permutive scripts, requires Permutive project specific IDs (environment variables) - add to the sites' _document.tsx

import { PermutiveSetup } from "@phntms/ft-react-components";
.
.
// Permutive tracking
const PERMUTIVE_PROJECT_ID = process.env.PERMUTIVE_PROJECT_ID || "";
const PERMUTIVE_PUBLIC_API_KEY = process.env.PERMUTIVE_PUBLIC_API_KEY || "";
.
.
render() {
    return (
      <Html lang="en">
        <Head>
          <FontPreloadEmbed />
          <FaviconEmbed />
          <TrackingHeadScript id={GA_TRACKING_ID} />
          <PermutiveSetup
            projectID={PERMUTIVE_PROJECT_ID}
            publicAPIKey={PERMUTIVE_PUBLIC_API_KEY}
          />
.
.

FTCookieMessage, FTFooter, FTHeader, FTPartnerContent reuseable components

Render in an appropriate page level component. FTPartnerContent requires 3 props as below to display the site's required partner links. It has optional disclaimer (controls the on/off tooltip state) and author (determines 1 of 4 tooltip texts) props.

import {
  CookieMessage,
  FTHeader,
  FTFooter,
  FTPartnerContent,
} from "@phntms/ft-react-components";
.
.
  <Container>
        <FTHeader />
        <FTPartnerContent
          siteUrl={globals.sitewide.url}
          siteTitle={globals.sitewide.title}
          partner={{
            title: "Zurich",
            url: "https://www.zurich.com/",
          }}
        />
        {showHero && <CategoryHero />}
        <Navbar categories={globals.categories} selected={category} />
        <div id="o_tracker_scroll">{children}</div>
        <CookieMessage />
        <FTFooter />
      </Container>

Reuseable component styles and icons

NOTE: all 4 components rely on a single global .scss styles file, which needs to be loaded in _app.tsx as a global import:

//load combined FT components styles as global
import "@phntms/ft-react-components/src/components/ft/styles/app.scss";

Additionally, some the components use styling from the @financial-times root components, so adding a node_modules sass path to NextJS's next.config.js is required:

module.exports = {
  //other config
  sassOptions: {
    includePaths: [
      // Required by the @financial-times/o-<component> sass
      path.resolve(__dirname, "./node_modules/@financial-times"),
    ],
  },
};

Currently, the partner header icons need to be copied to the NextJS sites' /public/ft/partner-content folder

BrandmetricsSurvey

Implements the placeholder div and initialisation for Brandmetrics surveys. NOTE: Surveys also require the separate Brandmetrics external CDN script to be loaded and available on window.

import { BrandMetricsSurvey } from "@phntms/ft-react-components";
.
.
{article.brandmetrics_survey_id && (
  <BrandMetricsSurvey surveyId={article.brandmetrics_survey_id}
  />
)}

TrackingPixel

Renders an img with with display:hidden and height:0

import { TrackingPixel } from "@phntms/ft-react-components";
.
.
{article.brandmetrics_pixel_url && (
  <TrackingPixel src={article.brandmetrics_pixel_url} />
)}