2.0.4 • Published 4 months ago

@spearly/sdk-js v2.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

@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.
2.0.3

4 months ago

2.0.4

4 months ago

1.2.0

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.2

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago

1.0.0-next.10

3 years ago

0.5.0

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

1.0.0-next.3

3 years ago

1.0.0-next.4

3 years ago

1.0.0-next.5

3 years ago

1.0.0-next.6

3 years ago

1.0.0-next.7

3 years ago

0.4.1

3 years ago

1.0.0-next.8

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

1.0.0-next.9

3 years ago

0.4.2

3 years ago

0.2.0

3 years ago

1.0.0-next.1

3 years ago

1.0.0-next.2

3 years ago

0.1.11

3 years ago

1.0.0-next.0

3 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago