Run JavaScript in preparation

Hello friends,


I'm try to Run JavaScript in my preparation WebPage, but not works.

Someone know what is wrong?


Code in RunJavaScript:

"<script type='text/javascript'>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
            'event': 'VirtualPageView',
            'pageType': 'TipoDeAgendamento'
        });
</script>"


Regards.

Solution

Hi Agno,


When using the RunJavaScript action you don't need to have the <script> tags.


Cheers,
João

Solution

Agno Silveira wrote:

Hello friends,


I'm try to Run JavaScript in my preparation WebPage, but not works.

Someone know what is wrong?


Code in RunJavaScript:

"<script type='text/javascript'>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
            'event': 'VirtualPageView',
            'pageType': 'TipoDeAgendamento'
        });
</script>"


Regards.

Hi,

Can you please use the debugger to test what's going wrong in the script.



Agno Silveira wrote:

Hello friends,


I'm try to Run JavaScript in my preparation WebPage, but not works.

Someone know what is wrong?


Code in RunJavaScript:

"<script type='text/javascript'>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
            'event': 'VirtualPageView',
            'pageType': 'TipoDeAgendamento'
        });
</script>"


Regards.


Hi, Don't use script tags(<Script>) in RunJavascript action.

Preparation is not a place for JS.

The screen is still being rendered so the code may not have what it needs (probably has nothing yet).

You can place that code on screen. Why do it in Preparation?

Agno Silveira wrote:

Hello friends,


I'm try to Run JavaScript in my preparation WebPage, but not works.

Someone know what is wrong?


Code in RunJavaScript:

"<script type='text/javascript'>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
            'event': 'VirtualPageView',
            'pageType': 'TipoDeAgendamento'
        });
</script>"


Regards.

Hi,

In place of preparation you can use JS in Page JavaScript block and belows so that other dependent JS file will be loaded first.

$(document).ready(function(){

window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
            'event': 'VirtualPageView',
            'pageType': 'TipoDeAgendamento'
        });

});



 


Salman you mean add the JS to the Javascript of the page itself? Cos that's what I was about to comment on, too:


Mariano Picco wrote:

Salman you mean add the JS to the Javascript of the page itself? Cos that's what I was about to comment on, too:


Right


Thank you a lot guys, many correct answer.  \o/

I removed the <script> and now it works, in preparation.

Regards.