fam-sdk

0.0.2 • Public • Published

Free All Media Javascript SDK

  • Helps you integrate FAM into your web site or web app with minimal setup.
  • Event callbacks for everything you need.
  • Can be included into an HTML document or imported directly via npm.
  • CDN hosted and non-hosted copies available.

Installation

CDN Hosted

You can always pull the latest version of the FAM Javascript SDK from our CDN at:

https://cdn.freeallmedia.com/sdk/js/0/latest/fam.js

HTML

<!-- Include this at the bottom of your 'body' tag -->
<script src="https://cdn.freeallmedia.com/sdk/js/0/latest/fam.js"></script>
<script type="text/javascript">
  (function (window) {
    const fam = new Fam();
  })(window);
</script>

NPM

You can install the FAM Javascript SDK from npm:

$ npm install fam-sdk --save

You can import FAM directly as a module via the import keyword:

import Fam from "fam-sdk";

const fam = new Fam()

There is a /dist/ directory for those that prefer directly including a local copy into their HTML documents:

$ npm install fam-sdk
$ ls ./node_modules/fam-sdk/dist/fam.js

Example Code

A complete example is available in the /dist/examples directory and on our CDN:

Usage

fam.window(url)

  1. Takes a FAM campaign URL
  2. Displays the FAM campaign in a new window or tab.
  3. Returns the new window object.
const famWindow = fam.window("https://cdn.freeallmedia.com/campaigns/my-campaign/index.html");

setTimeout(() => {
  famWindow.close();
}, 5000);

fam.iframe(domID, url)

  1. Takes a domID to an element on your HTML page and a FAM campaign URL.
  2. Creates an iFrame within the designated element that displays the FAM campaign.
  3. Returns the iFrame's DOM element.
const iFrameElement = fam.iframe("https://cdn.freeallmedia.com/campaigns/my-campaign/index.html");

fam.on(eventName, eventHandler)

  1. Takes an event name and event handler function.
  2. Calls the event handler function each time
  3. Returns the iFrame's DOM element.
fam.on("start", function () {
  console.log("FAM experience started.");
});
fam.on("end", function () {
  console.log("FAM experience ended.");
});
fam.on("close", function (activity) {
  console.log(`FAM experience closed by user while on activity named "${activity.name}"`);
});
fam.on("activity:start", function (activity) {
  console.log(`Activity named "${activity.name}" of type "${activity.type}" started.`);
});
fam.on("activity:end", function (activity, results) {
  console.log(`Activity named "${activity.name}" of type "${activity.type}" ended with the following results:`, results);
});
fam.on("image:impression", function (activity, creative) {
  console.log(`Image "${creative.name}" shown in activity "${activity.name}"`);
});
fam.on("image:clickthrough", function (activity, creative, url) {
  console.log(`Image "${creative.name}" clicked through to url "${url}" in activity "${activity.name}"`);
});
fam.on("video:play", function (activity) {
  console.log(`Video for activity "${activity.name}" playing.`);
});
fam.on("video:pause", function (activity) {
  console.log(`Video for activity "${activity.name}" paused.`);
});
fam.on("video:end", function (activity) {
  console.log(`Video for activity "${activity.name}" ended.`);
});
fam.on("video:mute", function (activity) {
  console.log(`Video for activity "${activity.name}" muted.`);
});
fam.on("video:unmute", function (activity) {
  console.log(`Video for activity "${activity.name}" un-muted.`);
});

Readme

Keywords

none

Package Sidebar

Install

npm i fam-sdk

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • fam