0

I'm attempting to track some actions on a webpage that requires me setting a value in the datalayer.

I'd like to do the casperjs/phantom equivilant to this...

dataLayer.push({test: "boom"});

Directly into the web browser's console. This works manually.

It's been a while since I've used casper/phantom so closely. Im currently trying the following...

this.evaluate('console.log(\'dataLayer.push({test: "boom"});\'); console.log("dataLayer");');

Is there a way to achieve my goal?

Also, bonus 'highfive' to anyone who can also allow me to follow this up by accessing the datalayer to verify its been set.

--Edit--

I am also currently launching the runs with options...

--ssl-protocol=any --web-security=no
  • Normally, you'd do `this.evaluate(function(){ dataLayer.push({test: "boom"}); });` and have some verification code after that like taking a screenshot or something like that. Have you tried it? If you're relying on `console.log` in the page context, then you need to register to the `"remote.message"` event. – Artjom B. Jun 20 '16 at 10:46
  • @ArtjomB. - Yep. I have the logging turned on on remote messaging and also on casper errors, trying to catch a syntax errors. This should be getting picked up in GA as well but its not. Thats where most of my verification has been lying. –  Jun 20 '16 at 17:28
  • So, you're probably using PhantomJS 2.x. It has a known bug that some errors cannot be caught and shown. You may try to run PhantomJS 1.9.8 or 1.9.7 (see [this](http://stackoverflow.com/a/33626030/1816580)). That way, you may catch all the syntax errors (or you could run something like eslint). – Artjom B. Jun 20 '16 at 18:16

0 Answers0