Skip to content

Commit

Permalink
Merge pull request #467 from dailymotion/adding-error-logs
Browse files Browse the repository at this point in the history
Upgraded fetching method, added error logging, and code Improvment
  • Loading branch information
ZacharieTFR authored Apr 25, 2024
2 parents 83f5464 + fefb556 commit ba5bcd8
Show file tree
Hide file tree
Showing 24 changed files with 1,079 additions and 652 deletions.
5 changes: 4 additions & 1 deletion bundle_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const oldDistPath = './dist_old';

const getFileSizes = (folderPath) => {
return fs.readdirSync(folderPath).reduce((res, fileName) => {
res[fileName] = fs.readFileSync(path.join(folderPath, fileName)).byteLength;
const stats = fs.statSync(`${folderPath}/${fileName}`);
if (stats.isFile()) {
res[fileName] = stats.size;
}
return res;
}, {});
};
Expand Down
62 changes: 62 additions & 0 deletions docs/api/vast-tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,27 @@ const vastTracker = new VASTTracker(null, ad, creative);

## Events<a name="events"></a>


`VASTTracker` extends a custom [`EventEmitter`](https://github.com/dailymotion/vast-client-js/blob/master/docs/api/event-emitter.md), therefore is possible to add event listeners like this:


```Javascript
vastTracker.on('exitFullscreen', () => {
// Deal with the event
});
```

In addition, you can add a specific event listener to listen to any errors.

##### TRACKER-error

- `message: String`
```Javascript
vastTracker.on('TRACKER-error', ({message}) => {
console.log(message)
});
```

### Events list

| **Event** | **Description** | **Payload** |
Expand Down Expand Up @@ -181,6 +194,10 @@ Pass `isCustomCode` as true only if you want to use a custom code for the `[ERRO
- **`macros : Object `** - An optional Object containing macros and their values to be used and replaced in the tracking calls.
- **`isCustomCode: Boolean`** - Flag to allow custom values on error code.

#### Event emitted

- **`TRACKER-error`**

#### Example

```Javascript
Expand All @@ -206,6 +223,10 @@ Sends a request to the URI provided by the VAST `<Error>` element. If an `[ERROR
- **`errorCode: String`** - Replaces `[ERRORCODE]` macro. `[ERRORCODE]` values are listed in the VAST specification
- **`isCustomCode: Boolean`** - Flag to allow custom values on error code.

#### Event emitted

- **`TRACKER-error`**

#### Example

```Javascript
Expand All @@ -228,6 +249,7 @@ Must be called when the player considers that it has loaded and buffered the cre
#### Events emitted

- **`loaded`**
- **`TRACKER-error`**

#### Example

Expand All @@ -253,6 +275,7 @@ Must be called when the user watched the linear creative until its end. Calls th
#### Events emitted

- **`complete`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -280,6 +303,7 @@ Must be called when the user clicks on the creative. Calls the tracking URLs.
#### Events emitted

- **`clickthrough`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -307,6 +331,7 @@ Must be called when the player or the window is closed during the ad. Calls the

- **`closeLinear`**
- **`close`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -338,6 +363,7 @@ Must be called when the skip button is clicked. Calls the skip tracking URLs.
#### Events emitted

- **`skip`**
- **`TRACKER-error`**

#### Example

Expand All @@ -360,6 +386,10 @@ Sets the duration of the ad and updates the quartiles based on that.

- **`duration: Number`** - The duration of the ad

#### Event Emitted

- **`TRACKER-error`**

### setExpand(expanded, macros) <a name="setExpand"></a>

Updates the expand state and calls the expand/collapse as well as playerExpand/playerCollapse for VAST 4.1. tracking URLs.
Expand All @@ -375,6 +405,7 @@ Updates the expand state and calls the expand/collapse as well as playerExpand/p
- **`playerExpand`**
- **`collapse`**
- **`playerCollapse`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -413,6 +444,7 @@ Updates the fullscreen state and calls the fullscreen tracking URLs.

- **`fullscreen`**
- **`exitFullscreen`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -448,6 +480,7 @@ Updates the mute state and calls the mute/unmute tracking URLs.

- **`mute`**
- **`unmute`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -479,6 +512,7 @@ Update the pause state and call the resume/pause tracking URLs.

- **`pause`**
- **`resume`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -515,6 +549,7 @@ Sets the duration of the ad and updates the quartiles based on that. This is req
- **`midpoint`**
- **`firstQuartile`**
- **`thirdQuartile`**
- **`TRACKER-error`**

#### Example

Expand All @@ -539,6 +574,10 @@ Do not call this method if you want to keep the original `Skipoffset` value.

- **`duration: Number`** - The time in seconds until the skip button is displayed

#### Event emitted

- **`TRACKER-error`**

#### Example

```Javascript
Expand All @@ -560,6 +599,7 @@ Reports the impression URI. Can only be called once. Will report the following U
#### Events emitted

- **`creativeView`**
- **`TRACKER-error`**

#### Example

Expand All @@ -585,6 +625,10 @@ This method should be used when the ad meets criteria for Viewable impression as

- - **`macros: Object`** - Optional parameter. Object containing macros and their values to be replaced. Macros must be supported by VAST specification.

#### Event emitted

- **`TRACKER-error`**

#### Example


Expand All @@ -607,6 +651,10 @@ This method should be used when the ad meets criteria for NotViewable impression

- - **`macros: Object`** - Optional parameter. Object containing macros and their values to be replaced. Macros must be supported by VAST specification.

#### Event emitted

- **`TRACKER-error`**

#### Example


Expand All @@ -629,6 +677,10 @@ This method should be used when the ad meets criteria for ViewUndetermined impre

- - **`macros: Object`** - Optional parameter. Object containing macros and their values to be replaced. Macros must be supported by VAST specification.

#### Event emitted

- **`TRACKER-error`**

#### Example


Expand Down Expand Up @@ -656,6 +708,7 @@ Calls the notUsed tracking URLs.
#### Events emitted

- **`notUsed`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -683,6 +736,7 @@ Calls the otherAdInteraction tracking URLs.
#### Events emitted

- **`otherAdInteraction`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -711,6 +765,7 @@ Calls the acceptInvitation tracking URLs.
#### Events emitted

- **`acceptInvitation`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -738,6 +793,7 @@ Calls the adExpand tracking URLs.
#### Events emitted

- **`adExpand`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -765,6 +821,7 @@ Calls the adCollapse tracking URLs.
#### Events emitted

- **`adCollapse`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -794,6 +851,7 @@ Calls the minimize tracking URLs.
#### Events emitted

- **`minimize`**
- **`TRACKER-error`**

#### Example

Expand Down Expand Up @@ -836,6 +894,7 @@ Calls the overlayViewDuration tracking URLs.
#### Events emitted

- **`overlayViewDuration`**
- **`TRACKER-error`**

#### Example

Expand All @@ -861,6 +920,7 @@ Calls the verificationNotExecuted trackings URLs.
#### Events emitted

- **`verificationNotExecuted`**
- **`TRACKER-error`**

#### Example

Expand All @@ -886,6 +946,8 @@ Calls the tracking URLs for the given eventName and emits the event.
#### Events emitted

- **`given eventName`**
- **`TRACKER-error`**


#### Example

Expand Down
56 changes: 32 additions & 24 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import alias from '@rollup/plugin-alias';
import resolve from '@rollup/plugin-node-resolve';

const babelPlugin = babel({
Expand All @@ -16,28 +15,16 @@ function onwarn(warning) {
}

const createNodeConfig = (filePath, minifiedOutput, notMinifiedOutput) => {
let config = {
const baseConfig = {
input: filePath,
output: [
{
format: 'cjs',
file: `dist/${notMinifiedOutput}`,
output: {
format: 'cjs',
dir: 'dist',
manualChunks: {
xmldom: ['@xmldom/xmldom'],
},
{
format: 'cjs',
file: `dist/${minifiedOutput}`,
plugins: [terser()],
},
],
},
plugins: [
alias({
entries: [
{
find: './urlhandlers/mock_node_url_handler',
replacement: './urlhandlers/node_url_handler',
},
],
}),
resolve({
preferBuiltins: true,
}),
Expand All @@ -46,7 +33,26 @@ const createNodeConfig = (filePath, minifiedOutput, notMinifiedOutput) => {
onwarn,
};

return config;
const nonMinifiedConfig = {
...baseConfig,
output: {
...baseConfig.output,
entryFileNames: notMinifiedOutput,
chunkFileNames: 'chunks/[name]-[hash].js',
},
};

const minifiedConfig = {
...baseConfig,
output: {
...baseConfig.output,
entryFileNames: minifiedOutput,
chunkFileNames: 'chunks/[name]-[hash].min.js',
},
plugins: [...baseConfig.plugins, terser()],
};

return [nonMinifiedConfig, minifiedConfig];
};

const createBrowserConfig = (filePath, minifiedOutput, notMinifiedOutput) => {
Expand All @@ -55,11 +61,13 @@ const createBrowserConfig = (filePath, minifiedOutput, notMinifiedOutput) => {
output: [
{
format: 'es',
file: `dist/${notMinifiedOutput}`,
dir: 'dist',
entryFileNames: notMinifiedOutput,
},
{
format: 'es',
file: `dist/${minifiedOutput}`,
dir: 'dist',
entryFileNames: minifiedOutput,
plugins: [terser()],
},
],
Expand All @@ -73,7 +81,7 @@ export default [
// Browser-friendly build [package.json "browser"]
createBrowserConfig('src/index.js', 'vast-client.min.js', 'vast-client.js'),
// CommonJS build for Node usage [package.json "main"]
createNodeConfig(
...createNodeConfig(
'src/index.js',
'vast-client-node.min.js',
'vast-client-node.js'
Expand Down
Loading

0 comments on commit ba5bcd8

Please sign in to comment.