I am currently working on some tests regarding the dataLayer of a webshop. My goal is to use Tosca to check the dataLayer at specific points in the webshop to verify that the correct data for tracking is pushed to the dataLayer.
The Tosca Manual shows 2 modules for this "Execute JavaScript" and "Verify JavaScript". I can get the dataLayer or specific values by adding the following into the line for JavaScript: "return dataLayer[0].event.charAt(0)" This is just for getting to know the module, but it shows that I can correctly read some things from the dataLayer. But I am struggling to move on from this point. Cause I would really like to search/filter for specific values or do some checks directly via JavaScript. But I cant manage to let Tosca execute anything more then a simple read from the dataLayer even though it works fine when I execute the code in the browser console. Example: "var result = dataLayer.filter(obj => { return obj.event === "PageView"})" simple piece of code to search through the dataLayer for a specific type of event and save that to a variable, but Tosca wont execute this code. I added an extra pair of " so it looks like this: "var result = dataLayer.filter(obj => { return obj.event === """PageView"""})" But no matter if I add a return before or not - Tosca always says "Expression provided in test step item "JavaScript"could not be parsed due to the following reason: Token is not valid in this context: " " Seems like he has a problem with the quotation marks, but I added an extra pair for each of them to skip them - just like the manual says. And if I use a number instead of a string (which of course doesnt make sense, but just for trying it): "return var result = dataLayer.filter(obj => { return obj.event === 1})" I get the error No suitable value found for command ' return obj.event === 1'
Therefor I am clueless about what syntax I need to follow to execute my JavaScript code. I would be thankful for any help. Maybe I am even missing an easier way to check the DataLayer?