Skip to content

Added refreshOnRouteChange param #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions packages/gpt-ads/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ Debounce duration between each window resize handling.

Override `collapseEmptyDivs` option at the slot's level.

#### refreshOnRouteChange

- Type: `Boolean`
- Default: `false`

### Examples


Expand Down
14 changes: 14 additions & 0 deletions packages/gpt-ads/lib/templates/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export default {
required: false,
default: null,
},
refreshOnRouteChange: {
type: Boolean,
required: false,
default: false
},
},
computed: {
networkCode() {
Expand Down Expand Up @@ -168,6 +173,15 @@ export default {
return index;
},
},

watch: {
'$route.path': function() {
if (this.refreshOnRouteChange) {
this.refreshSlot();
}
}
},

mounted() {
if (!window.googletag) {
return;
Expand Down
4 changes: 2 additions & 2 deletions packages/gpt-ads/lib/templates/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export default async function (ctx, inject) {
// Inject GPT lib
const gptLibScript = {
id: GPT_LIB_SCRIPT_ID,
src: 'https://www.googletagservices.com/tag/js/gpt.js',
src: 'https://securepubads.g.doubleclick.net/tag/js/gpt.js',
async: true,
};
injectScript(gptLibScript);

// Inject GPT init script
let gptInitScriptHtml = 'var googletag = googletag || {};googletag.cmd = googletag.cmd || [];';
let gptInitScriptHtml = 'window.googletag = window.googletag || {cmd: []};';
if (debug) {
gptInitScriptHtml += 'googletag.cmd.push(function(){googletag.openConsole();});';
}
Expand Down