1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 19:42:38 +02:00
Daniel Neto 2023-06-30 08:55:17 -03:00
parent 746e163d01
commit 1c7ea28b46
808 changed files with 316395 additions and 381162 deletions

View file

@ -30,8 +30,8 @@ Your ad plugin can invoke these methods and events to play (or skip) ads. See [G
* For a preroll ad, you can invoke `startLinearAdMode` after the `readyforpreroll` event if `isWaitingForAdBreak()` is true.
* For a midroll ad, you can invoke `startLinearAdMode` during content playback if `isInAdMode()` is false.
* For a postroll ad, you can invoke `startLinearAdMode` after the `readyforpostroll` event if `isWaitingForAdBreak()` is true.
* `ads-ad-started` (event) -- Trigger this event during an ad break to indicate that an ad has actually started playing. This will hide the loading spinner. It is possible for an ad break to end without playing any ads.
* `endLinearAdMode()` (method) -- Invoke this method to end an ad break. This will cause content to resume. You can check if an ad break is active using `inAdBreak()`.
* `ads-ad-started` (EVENT) -- Trigger this event during an ad break to indicate that an ad has actually started playing. This will hide the loading spinner. It is possible for an ad break to end without playing any ads.
* `endLinearAdMode()` (METHOD) -- Invoke this method to end an ad break. This will cause content to resume. You can check if an ad break is active using `inAdBreak()`.
* `skipLinearAdMode()` (METHOD) -- At a time when `startLinearAdMode()` is expected, calling `skipLinearAdMode()` will immediately resume content playback instead.
* `nopreroll` (EVENT) -- You can trigger this event even before `readyforpreroll` to indicate that no preroll will play. The ad plugin will not check for prerolls and will instead begin content playback after the `play` event (or immediately, if playback was already requested).
* `nopostroll` (EVENT) -- Similar to `nopreroll`, you can trigger this event even before `readyforpostroll` to indicate that no postroll will play. The ad plugin will not wait for a postroll to play and will instead immediately trigger the `ended` event.

View file

@ -1,6 +1,6 @@
# Common Interface
videojs-contrib-ads does not implement these. This page establishes a convention used some some ad plugins that you may want to consider sending for consistency as they may be useful.
videojs-contrib-ads does not implement these. This page establishes a convention used by some ad plugins that you may want to consider sending for consistency as they may be useful.
## Events
@ -10,6 +10,7 @@ videojs-contrib-ads does not implement these. This page establishes a convention
* `ads-pod-ended`: Fired when a LINEAR ad pod has completed.
* `ads-allpods-completed`: Fired when all LINEAR ads are completed.
* `ads-ad-started`: Fired when the ad starts playing. Should include the event parameter `indexInBreak`.
* `ads-ad-skipped`: Fired when the ad unit is skipped.
* `ads-ad-ended`: Fired when the ad completes playing.
* `ads-first-quartile`: Fired when the ad playhead crosses first quartile.
* `ads-midpoint`: Fired when the ad playhead crosses midpoint.
@ -34,4 +35,9 @@ player.ads.ad = {
"duration": `Number`,
"currentTime": `Function`
}
player.ads.pod = {
"id": `String`,
"size": `Number`
}
```

View file

@ -18,7 +18,7 @@ With this basic structure in place, you're ready to develop an ad plugin.
### Including the files in your HTML
This is not the recommended approach, but may be useful in some cases. In addition to the video.js library, you'll need two files from this project: `videojs.ads.js` and `videojs.ads.css`. After you [build the project](/developer/getting-started.md) they are both in the `dist` directory.
This is not the recommended approach, but may be useful in some cases. In addition to the video.js library, you'll need two files from this project: `videojs.ads.js` and `videojs.ads.css`. After you [build the project](../developer/getting-started.md) they are both in the `dist` directory.
Include the CSS in your HTML's `<head>` section with a `<link>` tag:

View file

@ -1,49 +1,66 @@
# Macros
An optional feature that contrib-ads supports is ad macros. Ad macros are often used by ad plugins to support addition of run-time values into a server URL or configuration.
The contrib-ads library includes an optional ad macros feature, which allows ad plugins to incorporate runtime values into server URLs or configurations. Ad macros can be utilized to substitute specific placeholders in a URL string with dynamic values such as the player ID, page URL, or custom variables.
For example, an ad plugin that supports this feature might accept an ad server URL like this:
Here's an example of how ad macros work. An ad plugin might use a URL like this:
`'http://example.com/vmap.xml?id={player.id}'`
In the ad plugin code, it would use the videojs-contrib-ads macro feature to process that URL like this:
Within the ad plugin code, the videojs-contrib-ads macro feature is applied as follows:
`serverUrl = player.ads.adMacroReplacement(serverUrl, true, additionalMacros);`
This would result in a server URL like this:
This results in the final URL:
`'http://example.com/vmap.xml?id=12345'`
where 12345 is the player ID.
In this case, `12345` represents the player ID.
adMacroReplacement takes 3 arguments:
## Function: player.ads.adMacroReplacement
Replaces macros in a given string with their corresponding values.
1. The string that has macros to be replaced.
2. `true` if the macro values should be URI encoded when they are inserted, else `false` (default `false`)
3. An optional object that defines additional macros, such as `{'{five}': 5}` (default `{}`)
### Parameters
- `string` (string): A string containing macros to be replaced.
- `uriEncode` (boolean, optional, default: false): A boolean value indicating whether the macros should be replaced with URI-encoded values.
- `customMacros` (object, optional): An object containing custom macros and their values. It can also be used to disable default macro replacement and provide custom names for default macros.
- `customMacros.disableDefaultMacros` (boolean, optional, default: false): A boolean value indicating whether replacement of default macros should be skipped in favor of only custom macros.
- `customMacros.macroNameOverrides` (object, optional): An object containing custom names for default macros. For example: {'{player.id}': '{{PLAYER_ID}}', ...}.
## Static Macros
### Returns
- (string): The provided string with all macros replaced.
| Name | Value |
|:-------------------------|:----------------------------------|
| {player.id} | The player ID |
| {player.width} | The current player width |
| {player.height} | The current player height |
| {player.duration} | The duration of current video * |
| {player.pageUrl} | The page URL ** *** |
| {timestamp} | Current epoch time |
| {document.referrer} | Value of document.referrer *** |
| {window.location.href} | Value of window.location.href |
| {random} | A random number 0-1 trillion |
| {mediainfo.id} | Pulled from mediainfo object |
| {mediainfo.name} | Pulled from mediainfo object |
| {mediainfo.description} | Pulled from mediainfo object |
| {mediainfo.tags} | Pulled from mediainfo object |
| {mediainfo.reference_id} | Pulled from mediainfo object |
| {mediainfo.duration} | Pulled from mediainfo object |
| {mediainfo.ad_keys} | Pulled from mediainfo object |
| {playlistinfo.id} | Pulled from playlistinfo object |
| {playlistinfo.name} | Pulled from playlistinfo object |
## Default Macros
### Static Macros
| Name | Value |
|:-------------------------|:--------------------------------------|
| {player.id} | The player ID |
| {player.width} | The current player width |
| {player.height} | The current player height |
| {player.widthInt} | The current player width as int |
| {player.heightInt} | The current player height as int |
| {player.duration} | The duration of current video * |
| {player.durationInt} | The duration as int * |
| {player.live} | `1` if live, `0` if VOD * |
| {player.autoplay} | `1` if set to autoplay, `0` if not |
| {player.muted} | `1` if muted, `0` if not |
| {player.pageUrl} | The page URL ** *** |
| {player.language} | The current language of the player |
| {timestamp} | Current epoch time |
| {document.referrer} | Value of document.referrer *** |
| {window.location.href} | Value of window.location.href |
| {random} | A random number 0-1 trillion |
| {mediainfo.id} | Pulled from mediainfo object |
| {mediainfo.name} | Pulled from mediainfo object |
| {mediainfo.description} | Pulled from mediainfo object |
| {mediainfo.tags} | Pulled from mediainfo object |
| {mediainfo.reference_id} | Pulled from mediainfo object |
| {mediainfo.duration} | Duration from mediainfo object |
| {mediainfo.durationInt} | Duration from mediainfo object as int |
| {mediainfo.ad_keys} | Pulled from mediainfo object |
| {playlistinfo.id} | Pulled from playlistinfo object |
| {playlistinfo.name} | Pulled from playlistinfo object |
\* Returns 0 if video is not loaded. Be careful timing your ad request with this macro.
@ -51,11 +68,11 @@ adMacroReplacement takes 3 arguments:
\*** Document referrer may not return the full URL depending on the effective [referrer policy][referrer-policy].
## Dynamic Macro: mediainfo.custom_fields.*
### Dynamic Macro: mediainfo.custom_fields.*
A macro such as {mediainfo.custom_fields.foobar} allows the user to access the value of any property in `mediainfo.custom_fields`.
## Dynamic Macro: pageVariable.*
### Dynamic Macro: pageVariable.*
A macro such as {pageVariable.foobar} allows the user access the value of any property on the `window` object. Only certain value types are allowed, per this table:
@ -68,7 +85,7 @@ A macro such as {pageVariable.foobar} allows the user access the value of any pr
| Undefined | Logs warning and returns empty string |
| Other | Logs warning and returns empty string |
## TCF macros
### TCF macros
If a CMP supporting the [GDPR Transparency and Consent Framework][tcf] is in use additional tcf macros are made available. The syntax is `{tcf.*}`, with `*` being a property in the [tcData][tcdata] object. Most commonly used will be:
@ -81,9 +98,51 @@ Since `gdprApplies` is a boolean and many ad servers expect the value as an int,
If the player is in an iframe, a proxy will be added if any parent frame is detected to gain consent with the postmessage API. The CMP must be loaded first.
## Default values in macros
### Default values in macros
A default value can be provided within a macro, in which case this value will be used where not resolvable e.g. `http://example.com/ad/{pageVariable.adConf=1234}` becomes `http://example.com/ad/1234` if `window.adConf` is undefined.
A default value can be provided within a macro in the format `{MACRO=DEFAULT}`, in which case this value will be used where not resolvable e.g. `http://example.com/ad/{pageVariable.adConf=1234}` becomes `http://example.com/ad/1234` if `window.adConf` is undefined. If a blank default is given, there will be a blank param, `http://example.com/ad?config={pageVariable.adConf=}&a=b` becomes `http://example.com/ad?config=&a=b` if `window.adConf` is unset.
## Custom Macros
Custom macros can be added by providing an object to the `customMacros` parameter, with keys representing the macro names and values representing the macro values. For example, if you want to add a custom macro `{myVar}` with a value of `5`, you can do so like this:
```js
const stringWithMacros = "http://ads.example.com?custom_var={myVar}";
const customMacros = {
'{myVar}': 5
};
const replacedString = player.ads.adMacroReplacement(stringWithMacros, false, customMacros);
```
This would result in the `replacedString` containing `"http://ads.example.com?custom_var=5"`.
## Customizing Default Macro Names
You can also customize the names of any default macros, including dynamic macros, by providing a `macroNameOverrides` object within the `customMacros` parameter. For example, if you want to replace `{player.id}` with `{{PLAYER_ID}}`, you can do so like this:
```js
const stringWithMacros = "http://ads.example.com?player_id={{PLAYER_ID}}";
const customMacros = {
macroNameOverrides: {
'{player.id}': '{{PLAYER_ID}}'
}
};
const replacedString = player.ads.adMacroReplacement(stringWithMacros, false, customMacros);
```
This would result in the `replacedString` containing the player ID in place of the `{{PLAYER_ID}}` macro instead of the `{player.id}` macro.
## Disabling Default Macro Replacement
If you want to disable the replacement of default macros and only use custom macros, you can set the `disableDefaultMacros` property of the `customMacros` parameter to `true`. For example:
```js
const stringWithMacros = "http://ads.example.com?player_id={player.id}&custom_var={myVar}";
const customMacros = {
'{myVar}': 5,
disableDefaultMacros: true
};
const replacedString = player.ads.adMacroReplacement(stringWithMacros, false, customMacros);
```
In this case, the `replacedString` would not replace the `{player.id}` macro but would replace the custom `{myVar}` macro.
[tcf]: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md
[tcdata]: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#tcdata