Utilizing VueJS v2 in tandem with Ezoic (or Adsense) for enhanced website monet

Recently, I updated my website to utilize VueJS v2, which was not used in the previous version. The main code is contained within the <div id="app"></div> element where Vue is initialized. However, I am facing a problem with the ads provided by my advertising partner, Ezoic, as they are not displaying correctly. Upon investigation, it seems that the issue may be linked to the following errors:

show_ads.js:53 Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

Since Ezoic collaborates with Google Ad Exchange, I suspect that the above error is contributing to the issue.

I am exploring options to make my application compatible with Ezoic/Adsense. One idea is to only have Vue on specific areas of the page rather than the entire page (<div id="app"></div> encompasses the entire body), but this would require having multiple Vue instances running due to components at different locations within the page.

Unfortunately, I do not have access to the code that Ezoic injects into the page, as they handle this on their end. The Ezoic team is currently investigating the issue, but any insights I can provide could be beneficial.

Answer №1

Upon the request of the esteemed Dynamic Remo, I am presenting an answer tailored for implementing Ezoic's standalone solution in Vue.

It is important to note that Ezoic does not endorse this method and may not provide full support. However, this approach grants greater control over the placement of ads.

The Resolution: Commence by adding the following script tag outside or beyond your custom root element.

<script type="text/javascript" src="//www.ezojs.com/ezoic/sa.min.js" async=""></script>

Within your Vue component, create placeholder elements with an id of "ezoic-pub-ad-placeholder-xx", where xx corresponds to the id in your Ezoic dashboard. Dynamic creation is possible provided there is a matching id in Ezoic, giving you two viable options:

Dynamic:

<div v-for="placeholderId in ezoicArray" :id="'ezoic-pub-ad-placeholder-' + placeholderId" class="ezoic"></div>

Standard:

<div id="ezoic-pub-ad-placeholder-102" class="ezoic"></div>

To display ads in your placeholders, utilize the function provided below. Simply invoke it upon mounting the component.

ezoic(placeholderList) {
  // Function implementation as described in the original text
},
addPlaceholderOnce(array, placeholder) {
  // Function implementation as described in the original text
},

If adjustments to your placeholder setup are required for various reasons, such as in my case, include window.ezoicRefreshed = false; in the suitable lifecycle hook. In my scenario, it is placed in beforeUnmount due to custom placeholder lists per route.

This solution aims to offer assistance in navigating the implementation of Ezoic's standalone solution in a Vue environment. May it serve you well!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Move the focus to the previous input field by removing the key

I have created a phone number input with 10 fields that automatically skip to the next field when you fill in each number. However, I would like to be able to go back to the previous field if I make a mistake and need to delete a digit. How can I achieve ...

Navigational menu that slides or follows as you scroll

Wondering if anyone knows of a straightforward jQuery or Javascript method to create a navigation sidebar that smoothly moves with the user as they scroll down a page. A good example can be found here: Any suggestions would be greatly welcome. ...

Tips for making sure the Button component in material-ui consistently gives the same ID value for onClick events

Issue arises when trying to log the ID of the Button component, as it only logs correctly when clicked on the edges of the button (outside the containing class with the button label). This problem is not present in a regular JavaScript button where text is ...

How can I prevent v-model from filling multiple fields?

Having just started with Vue.js, I've managed to solve most of the issues I've encountered so far, but there's one that's stumping me. I'm working on displaying a list of posts fetched from an API and I want to include a comments ...

Beware: Inaccessible code detected in Reactjs usage

Currently, I am working on a ReactJS project where I have integrated two components - PrescriptionIndex and PrescriptionNew. Let's start with the 'PrescriptionNew' component: import React, { Component } from 'react'; import Flo ...

NodeJs is facing a challenge with the global variable for retrieving all routes methods after successful sign in

I have created a blog page with options for signing up and signing in. I used the req.locals.<name> method Using the GET method. Code snippet from server.js app.get('*',(req,res, next) => { res.locals.user = req.user || null; ...

automatically created button, form control named 'answer' that is not valid

Struggling with a challenge in attaching an event to a dynamically generated button. Despite conducting some research, most of the solutions suggest that this issue is typically related to a form control. However, in my scenario, the error "invalid form co ...

Input field with JQuery datepicker showing only months and years

I have encountered a question that closely resembles the one discussed here: year/month only datepicker inline The scenario I'm facing involves utilizing the input version instead of the div. In the case of using the div, the ui-datepicker-calendar ...

What steps are needed to enable the keyboard on a Otree application for mobile devices?

I previously utilized an Implicit Association Task (IAT) in an experiment conducted on computers. However, I now need to adapt this IAT for use on tablets or mobile devices. Here is how the IAT appears on a cellular device: https://i.stack.imgur.com/kNwo ...

Tips for effectively managing loading state within redux toolkit crud operations

Seeking guidance on efficiently managing the loading state in redux-toolkit. Within my slice, I have functionalities to create a post, delete a post, and fetch all posts. It appears that each operation requires handling a loading state. For instance, disp ...

Adjust Navbar Header Color Based on Screen Size

I am completely new to front-end development. I am in the process of building my own responsive website using Bootstrap 3. One issue I am facing is that when I resize my browser window to simulate a phone screen, I want the navigation bar color to change ...

What is the best way to incorporate a text box along with a submit button that triggers a callback to a javascript function when clicked, utilizing either plain javascript or jQuery?

As a beginner in the world of JavaScript, I'm struggling to find the solution to this problem. Any assistance would be greatly welcomed. ...

Error encountered: jQuery AJAX JSON request failed to be caught

While my WordPress AJAX process is successful, a peculiar error keeps popping up in Chrome Devtools: Uncaught TypeError: Cannot read property 'vehicle' of undefined. It's puzzling, as the parsed JSON data seems to be in the correct object fo ...

"Troubleshooting: The Dropzone js code sample from the documentation

I am currently implementing a tutorial from the documentation provided by Dropzone.js. However, I seem to be encountering an issue as the example is not working correctly. Here is the structure that I currently have: Dropzone.options.myAwesomeDropzone = ...

What is the best way to return JSON data in a compressed (gzip) format to an Ajax Request using Java?

When sending compressed JSON in response to an Ajax request from my Java program, I understand that I need to set the Content-Encoding in the Response Header to gzip. However, are there any additional steps I should take? ...

How can I make an AJAX request in Rails 3 to retrieve an HTML page?

I am experimenting with using Rails to display an .html.erb template via an ajax request under specific conditions. By default, I am consistently receiving the .js.erb file when making an ajax request. Without delving into the reasons behind this choice, ...

Dealing with the error "Type 'date[]' is not assignable to type '[date?, date?]' in a React hook

I'm attempting to assign a date range but encountering an error that states: Type 'Date[]' is not assignable to type '[Date?, Date?]'. Types of property 'length' are incompatible. Type 'number' is not assignab ...

Tips for executing an SQL query containing a period in its name using JavaScript and Node.JS for an Alexa application

Hello there, I've been attempting to make Alexa announce the outcomes of an SQOL query, but I'm encountering a persistent error whenever I try to incorporate owner.name in the output. this.t("CASEINFO",resp.records[0]._fields.casenumber, resp.r ...

Using ajax to submit a request to the controller

I'm currently developing an ASP.NET Core MVC application and have a registration page set up. My goal is to return View with errors if the model state is false: @model WebApplication2PROP.Entities.UserRegister @* For more information on enabling M ...

The IMG onclick event for LinkModalDialog does not function properly on Mozilla browsers

I am currently utilizing the following function: function OpenLinkModal(obj){ var arr=showModalDialog("../../files/list_simple.asp","","dialogHeight: 600px; dialogWidth: 450px; edge: Raised; center: Yes; resizable: Yes; status: Yes; scroll: Yes; help ...