highreel
Developers

In your framework, or your app

The elements are standard custom elements, so every framework takes them. A few lines of setup make them typed and keep them in the browser.

2 min read

Load the script once

Whatever the framework, the script goes once on the page, in your HTML's head or through your framework's way of adding one. It defines highreel-banner and highreel-player and window.Highreel; loading it twice is harmless, the first copy stays. The elements render nothing until it has run, so they're safe in server-rendered HTML.

HTML
<script src="https://highreel.app/embed/v1.js" async></script>

The address keeps v1 for as long as the elements work the way these pages describe; a change that would break a site's lines gets a new address, and v1 stays.

React

React 19 passes attributes to custom elements as they are, so the tags work in JSX with no wrapper. For TypeScript, tell JSX about them once:

highreel.d.ts
import type { DetailedHTMLProps, HTMLAttributes } from 'react'

type HighreelElement = DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> & {
  link?: string
  variant?: 'card' | 'bar'
  open?: 'overlay' | 'tab'
  dismissible?: boolean
  layout?: 'phone' | 'wide'
}

declare module 'react' {
  namespace JSX {
    interface IntrinsicElements {
      'highreel-banner': HighreelElement
      'highreel-player': HighreelElement
    }
  }
}
A member's home
export function YourYear({ member }: { member: { highreelLink?: string } }) {
  if (!member.highreelLink) return null
  return <highreel-banner link={member.highreelLink} variant="bar" dismissible />
}

To hear its events, add a listener from a ref, since they're named highreel:open and the like:

TSX
const ref = useRef<HTMLElement>(null)
useEffect(() => {
  const el = ref.current
  const opened = () => analytics.track('highreel_opened')
  el?.addEventListener('highreel:open', opened)
  return () => el?.removeEventListener('highreel:open', opened)
}, [])

return <highreel-banner ref={ref} link={link} />

Next.js

Load the script with next/script in your root layout; the tags can then go in any component, server or client.

app/layout.tsx
import Script from 'next/script'

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script src="https://highreel.app/embed/v1.js" strategy="afterInteractive" />
      </body>
    </html>
  )
}

Call Highreel.open only from the browser, in an event handler, never while rendering on the server.

Vue

Vue needs to know the tags are custom elements, or it warns that it can't resolve them. With Vite:

vite.config.ts
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [vue({
    template: { compilerOptions: { isCustomElement: tag => tag.startsWith('highreel-') } },
  })],
})
Vue
<highreel-banner v-if="member.highreelLink" :link="member.highreelLink" @highreel:open="onOpen" />

Nuxt

The same option, in nuxt.config, and the script in the app's head:

nuxt.config.ts
export default defineNuxtConfig({
  vue: { compilerOptions: { isCustomElement: tag => tag.startsWith('highreel-') } },
  app: { head: { script: [{ src: 'https://highreel.app/embed/v1.js', async: true }] } },
})

Server rendering is fine: the server writes the tag, and the browser turns it into a banner once the script runs.

A native app

An iOS or Android app can't run the script, but it can show the same thing:

  • Open the link. The simplest: open the person's link in an in-app browser (SFSafariViewController on iOS, Custom Tabs on Android). Their Highreel plays full screen, with its music, Share and Save image.
  • A WebView. Load the link with ?via=site added, so the open counts as "On your website" in Analytics. Turn on JavaScript, and allow media to play inline after a tap, or a song won't start.
  • Your own banner. Draw it in your app's own UI from the API: look has the cover's background, text and button colors, and image is a ready picture of their Highreel, 1,200 × 630. Tapping it opens the link.

Questions

Is there an npm package?

Not yet. The script tag works in every framework, and the type declarations above cover React. A package with types for React and Vue may come later.

Does it work with Svelte, Angular or plain JavaScript?

Yes. They're standard custom elements: Svelte takes them as they are, Angular needs CUSTOM_ELEMENTS_SCHEMA in the component that uses them, and plain JavaScript can create one with document.createElement('highreel-banner') and set its link attribute.

What if my page changes person without reloading?

Set the element's link attribute to the new person's link and it shows theirs. Removing the element cleans up after it.

Keep reading

Your customers had a great year. Show them.

No account needed · from $99 per campaign