fam-sdk
v0.0.2
Published
A javascript library to integrate FAM into web apps.
Downloads
6
Readme
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)
- Takes a FAM campaign URL
- Displays the FAM campaign in a new window or tab.
- 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)
- Takes a domID to an element on your HTML page and a FAM campaign URL.
- Creates an iFrame within the designated element that displays the FAM campaign.
- Returns the iFrame's DOM element.
const iFrameElement = fam.iframe("https://cdn.freeallmedia.com/campaigns/my-campaign/index.html");
fam.on(eventName, eventHandler)
- Takes an event name and event handler function.
- Calls the event handler function each time
- 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.`);
});