Data Layer and Javascript object = error

Hello. I am trying to get a javascript object that is pushed in the datalayer.

this is the event push:

_mtm.push({
    'event': 'myevent',
    'obj':{'param1':'value1','param2':'value2'},
});

and this is the tag:

<script type="text/javascript">
var myobj = {{Obj}};
</script>

i have created a variable “Obj” for the object “obj”.

But i have an error:

SyntaxError: missing ] after element list
note: [ opened at line 2, column 12

Thank you for your help.

Update:

inside the code of the website, the tag appear like this:

<script type="text/javascript">
var myobj = [object Object];
</script>

Cheers @c3do

I’ve created a pull request to be able to assign objects through Custom HTML. Initially, it was only supported to add strings

1 Like

Great! i will use JSON or a javascript variable as a temporary solution. Thank you very much thomas.

I created a patchfile for you: customhtmlobjfix.patch (45.1 KB)

You can apply it to the tag manager with git apply customhtmlobjfix.patch.

1 Like