Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"plugins": [
["transform-decorators-legacy"],
["transform-react-jsx", { "pragma": "h" }],
["transform-object-assign"]
["transform-object-assign"],
["transform-es2015-parameters"]
]
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/s1/loader.js
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
}
},
"globals": {
"sleep": 1
"sleep": 1,
"define": 1
},
"rules": {
"react/jsx-no-bind": [2, { "ignoreRefs": true }],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/node_modules
/npm-debug.log
/build
/dist
.DS_Store
/coverage
/.idea
Expand Down
1 change: 1 addition & 0 deletions .node_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.11.3
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<a name="0.0.1"></a>

## [0.0.1](https://github.com/openmail/system1-cmp/compare/v0.0.0...v0.0.1) (2018-07-02)

### Features

- [x] Initial Release!
- [x] Versioned Deployment and updated README for installing CMP
241 changes: 241 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,244 @@
# system1-cmp

System1-CMP is a container around the [appnexus-cmp](https://github.com/appnexus/cmp) that provides additional features for loading the CMP and for providing a complete CMP solution. We would like to customize the CMP but still be able to upgrade the CMP SDK as the upstream [appnexus-cmp](https://github.com/appnexus/cmp) improves over time.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [Installation](#installation)
- [CMP Loader API](#cmp-loader-api)
- [init](#init)
- [init: config](#init-config)
- [init: callback](#init-callback)
- [Arguments](#arguments)
- [Possible Commands](#possible-commands)
- [Examples](#examples)
- [Events](#events)
- [Examples](#examples-1)
- [Build](#build)
- [Deploy](#deploy)
- [Upload](#upload)
- [AppNexus CMP](#appnexus-cmp)
- [Installation](#installation-1)
- [Build for Production](#build-for-production)
- [Documentation](#documentation)
- [Development](#development)
- [Testing](#testing)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Installation

Check the version you want to use, new versions are opt-in only.

```
<html>
<body>
<script type="text/javascript" src="//s.flocdn.com/cmp/0.0.1/loader.js"></script>
<script type="text/javascript">
const config = {
scriptSrc: 'https://s.flocdn.com/cmp/s1.cmp.js',
gdprApplies: true,
// logging: true,
// pubVendorListLocation: '/.well-known/pubvendors.json',
// customPurposeListLocation: './purposes.json',
// globalVendorListLocation: 'https://vendorlist.consensu.org/vendorlist.json',
// globalConsentLocation: './portal.html',
// storeConsentGlobally: false,
// storePublisherData: false,
// localization: {},
// forceLocale: null,
// allowedVendorIds: null
}

function onConsentChanged(result) {
if (document.cookie.indexOf("gdpr_opt_in=1") < 0) {
console.log("all:consent:failed", result);
// window.location.reload();
} else {
console.log("all:consent:succeeded", result);
}
}

cmp('init', config, (result) => {
if (result.gdprApplies) {
if (result.errorMsg) {
cmp('showConsentTool');
cmp('addEventListener', 'onConsentChanged', onConsentChanged);
} else {
// consent achieved
if (document.cookie.indexOf("gdpr_opt_in=1") >= 0) {
console.log("cmp:init: all consent achieved", result);
} else {
console.log("cmp:init: only some consent achieved", result);
}
}
} else {
console.log("cmp:init: consent not required", result);
}
});
</script>
</body>
</html>
```

## CMP Loader API

The CMP Loader exposes access to the underlying CMP SDK: [appnexus-cmp API](http://s.flocdn.com/cmp/docs/#/cmp-api) and externalizes configuration of the CMP SDK.

### init

You must call `init` explicitly to start the CMP. Otherwise, the CMP Loader will only queue commands and not initialize the CMP SDK.

* `config` is REQUIRED
* `callback` is OPTIONAL

```
cmp('init', config, callback);
```

#### init: config

`config` is a required argument of `init`. It allows us to configure/customize the CMP.

Example Configuration:

```
const config = {
scriptSrc: '//s.flocdn.com/cmp/s1.cmp.js',
gdprApplies: true,
pubVendorListLocation: '//s.flocdn.com/cmp/pubvendors.json', // OPTIONAL, whitelists vendors
logging: false,
customPurposeListLocation: './purposes.json',
globalVendorListLocation: '//vendorlist.consensu.org/vendorlist.json',
globalConsentLocation: './portal.html',
storeConsentGlobally: false,
storePublisherData: false,
localization: {},
forceLocale: null,
allowedVendorIds: null
}
cmp('init', config);
```

- `scriptSrc`: String: Required: location of CMP SDK.
- `gdprApplies`: Booelan: Enable / disable load of the CMP SDK
- `pubVendorListLocation`: OPTIONAL: location of pub vendor list
- `globalVendorListLocation`: OPTIONAL: global vendorList is managed by the IAB.

#### init: callback

Use the callback to determine if you should show the consent tool or not.

- `errorMsg`: STRING // detail on the result CMP initializing
- `gdprApplies`: BOOLEAN // true if in EU, false if consent not required
- `hasConsented`: BOOLEAN // true if use has consented to all permissions
- `vendorConsents`: OBJECT
- `vendorList`: OBJECT

Callback Example

```
<script type="text/javascript" src="https://s.flocdn.com/cmp/loader.js"></script>

cmp('init', {
gdprApplies: true,
scriptSrc: '//s.flocdn.com/cmp/s1.cmp.js'
}, (result) => {

// Consent is required and there was an error
if (result.gdprApplies && result.errorMsg) {
cmp('showConsentTool');
}

// Consent is required and a user has not consented to all permissions
if (result.gdprApplies && !result.hasConsented) {
cmp('showConsentTool');
}
});
```

### Arguments

```
cmp(command, [parameter], [callback])
```

- `command` (String): Name of the command to execute
- `[parameter]` (\*): Parameter to be passed to the command function
- `[callback]` (Function): Function to be executed with the result of the command

### Possible Commands

- `init` REQUIRED, can only be called once
- `addEventListener`
- `removeEventListener`
- `showConsentTool`

- `getVendorConsents`
- `getPublisherConsents`
- `getConsentData`
- `getVendorList`

### Examples
```
cmp('getVendorConsents', null, (response) => console.log(response));
cmp('getPublisherConsents', null, (response) => console.log(response));
cmp('getConsentData', null, (response) => console.log(response));
cmp('showConsentTool');
```

## Events

- `onConsentChanged` CUSTOM: triggers whenever consent has changed
- `isLoaded`
- `cmpReady`
- `onSubmit`

### Examples

```
cmp('addEventListener', 'onConsentChanged', (event) => console.log(event));
cmp('addEventListener', 'onSubmit', (event) => console.log(event));
```

## Build

Build the original project and the System1 project:
```
yarn build # builds both projects
yarn build:s1 # builds just the System1 loader and "complete" CMP SDK.
yarn build:original # builds just the original CMP provided by appnexus
```

## Deploy

Deploy will build and upload the project files to a System1 S3 bucket for public use

```
yarn deploy # builds and uploads both projects
yarn build:s1 # builds and uploads just the versioned S1 project
yarn build:original # builds and uploads just the original project
```

## Upload

The system1-cmp project lives in `dist/{version}` and is immutable, you can't upload it more than once.
This *should* be a safe operation to make as you'll just see an error in the terminal telling you the files already exist.
You will need to bump the `package.json` version in order to publish any changes to S3.

```
yarn upload:s1
```

The original project gets deployed to S3, but it's for reference only, it will invalidate automatically, and no one should have a production dependency on it.
This should be a safe operation as it does not affect production files.

```
yarn upload:original
```

[![Build Status](https://travis-ci.org/appnexus/cmp.svg?branch=master)](https://travis-ci.org/appnexus/cmp)

# AppNexus CMP
Expand Down
Loading