2.0.2 • Published 6 months ago

@spearly/sdk-js v2.0.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
6 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.
1.2.0

10 months ago

1.3.3

10 months ago

1.3.2

10 months ago

1.3.1

10 months ago

1.3.0

10 months ago

2.0.2

6 months ago

2.0.1

8 months ago

2.0.0

9 months ago

1.1.2

12 months ago

1.1.1

1 year ago

1.0.2

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.0-next.10

2 years ago

0.5.0

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

1.0.0-next.3

2 years ago

1.0.0-next.4

2 years ago

1.0.0-next.5

2 years ago

1.0.0-next.6

2 years ago

1.0.0-next.7

2 years ago

0.4.1

2 years ago

1.0.0-next.8

2 years ago

0.4.0

2 years ago

0.3.1

2 years ago

1.0.0-next.9

2 years ago

0.4.2

2 years ago

0.2.0

2 years ago

1.0.0-next.1

2 years ago

1.0.0-next.2

2 years ago

0.1.11

2 years ago

1.0.0-next.0

2 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago