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

@spearly/sdk-js

v2.0.2

Published

[![Spec Test](https://github.com/unimal-jp/spearly-sdk-js/actions/workflows/spec.yml/badge.svg)](https://github.com/unimal-jp/spearly-sdk-js/actions/workflows/spec.yml)

Downloads

211

Readme

@spearly/sdk-js

Spec Test

It is a Development Kit that makes it easy to use Spearly CMS from JavaScript or NodeJS in API mode.

Getting Started

Install

// npm
$ npm install -S @spearly/sdk-js

// yarn
$ yarn add @spearly/sdk-js

Usage

Setup

import { SpearlyApiClient } from '@spearly/sdk-js'

const apiClient = new SpearlyApiClient(API_KEY)

You can specify the API Server as well using by optional.

import { SpearlyApiClient } from '@spearly/sdk-js'

const apiClient = new SpearlyApiClient(API_KEY, API_SERVER_DOMAIN)

Get Content Lists

async function() {
  // basic
  const contents =  await apiClient.getList(CONTENT_TYPE_ID)

  // when using some options
  const filteredContents =  await apiClient.getList(CONTENT_TYPE_ID, { limit: 10, offset: 20 })}

Get Content

async function() {
  const content = await apiClient.getContent(CONTENT_TYPE_ID, CONTENT_ID)
}

Get Form

async function() {
  const form = await apiClient.getFormLatest(FORM_ID)
}

Submit Form

async function() {
  const submit = await apiClient.postFormAnswers(FORM_VERSION_ID, { ...YOUR_FORM_FIRLD_ANSWERS, _spearly_gotcha: '' })
}

A/B Testing analytics

Warning
A/B Testing does not support Server side.
We are working on it now, so please wait for a while.

Page view

If you are using A/B testing, you can run the following code on page load to count impressions.

import { SpearlyAnalytics } from '@spearly/sdk-js'

const analytics = new SpearlyAnalytics()

analytics.pageView({
  patternName: PATTERN_NAME,
  contentId: CONTENT_ALIAS,
})

Conversion

If you are using A/B testing, you can count conversions by using the conversion method as follows

import { SpearlyAnalytics } from '@spearly/sdk-js'

const analytics = new SpearlyAnalytics()

document.querySelector('#submit').addEventListener('submit', () => {
  analytics.conversion({
    patternName: PATTERN_NAME,
    contentId: CONTENT_ALIAS,
  })
});

Support TypeScript

Type definitions are also included, so there is no need to add anything else.

  • GetParams : This is options that can be set when retrieving the ContentList.
  • List : The type of the content list returned by the API.
  • Content : The type of content returned by the API.
  • Form : The type of form returned by the API.