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/jquery-plugin

v2.0.0

Published

This package allows to easily implement Spearly in your jQuery codes!

Downloads

4

Readme

Spearly CMS jQuery Plugin

his package allows to easily implement Spearly in your jQuery codes!

spec test

Getting Started

Load

Use npm or Yarn and webpack

  1. Install with the following command:
    // npm
    $ npm i -S @spearly/jquery-plugin
       
    // yarn
    $ yarn add @spearly/jquery-plugin
  2. Add the following to webpack.config.js:
    ...
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
      }),
    ],
    ...
  3. Add an import statement to your js file.
    import '@spearly/jquery-plugin'

Use CDN

Put the following code under the jQuery script tag.

<script src="/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@spearly/jquery-plugin/dist/spearly-plugin.js" defer></script>

How to Use

Initialize setup

Get the API Key from Spearly CMS and set up as follows.

$(function() {
  $.spearly.init({ apiKey: 'YOUR_API_KEY' })
})

Get Content Lists

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

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

Filtered Options

  • limit (number, 10)
  • offset (number, 0)
  • order ('desc' | 'asc', 'desc')
  • orderBy ('latest' | 'popular' | string)
  • filterBy (string)
  • filterValue (string)
  • filterRef (string)
  • rangeTo (string)
  • rangeFrom (string)
  • distinctId (string)
  • sessionId (string)
  • patternName ('a' | 'b')

Get Content

async function() {
  // basic
  const content = await $.spearly.getContent(CONTENT_TYPE_ID, CONTENT_ID)

  // when using some options
  const optionalContent = await $.spearly.getContent(CONTENT_TYPE_ID, CONTENT_ID, { distinctId: DISTINCT_ID })
}

Options

  • distinctId (string)
  • patternName ('a' | 'b')

Get Content Preview

async function() {
  const content = await $.spearly.getContentPreview(CONTENT_TYPE_ID, CONTENT_ID, PREVIEW_TOKEN)
}

PREVIEW_TOKEN can be obtained on the content edit page of the Spearly CMS.

Get Form

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

FORM_ID is for Form ID for embedding in Spearly CMS.

Submit Form

async function() {
  const submit = await $.spearly.postFormAnswers(FORM_VERSION_ID, { ...YOUR_FORM_FIRLD_ANSWERS, _spearly_gotcha: '' })
}
  • FORM_VERSION_ID is the ID to be obtained by Get Form.
  • YOUR_FORM_FIELD_ANSWERS is an object whose key is the form field ID and whose value is the content.
    For example, If the form has name, email, and content, and you answer 'James', '[email protected]', and 'Hello world!', here is:
    {
      name: 'James',
      email: '[email protected]',
      content: 'Hello world!'
    }
  • _spearly_gotcha is an anti-spam field. Be sure to add it to YOUR_FORM_FIELD_ANSWERS.
    Don't forget to install it in an invisible field on your form.

A/B Testing analytics

Page view

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

const content = await $.spearly.getContent(CONTENT_ID)
$.spearly.pageView({
  patternName: content.attributes.patternName,
  contentId: content.id,
})

Conversion

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

const content = await $.spearly.getContent(CONTENT_ID)
$('#submit').on('submit', () => {
  $.spearly.conversion({
    patternName: content.attributes.patternName,
    contentId: content.id,
  })
});