Google Analytics E-Commerce transaction Data

Hi , I have to execute a script with parameters  like this example :

<script>
window .dataLayer = window .dataLayer || [];
dataLayer.push({
'transactionId' : 'WS0001' , //ordernumber
'transactionAffiliation' : 'Export' ,
'transactionTotal' : 30.00 ,
'transactionTax' : 6.30 , // 21% btw
'transactionShipping' : 1.80 ,
'sku' : 'Export document' ,
'name' : 'Export' ,
'category' : 'Document' ,
'price' : 20.00 ,
'quantity' : 1
},{
'sku' : 'Service Level Advanced' ,
'name' : 'Service toeslag' ,
'category' : 'Document' ,
'price' : 10.00 ,
'quantity' : 1
}],
'event' : 'transactionSend',
'paymentMethod' : 'iDeal'
});
</script>

I have tried to use the RunJavascript (HTTPRequestHandler) with the function EncodeJavaSript like this

But is does not work.  

Is there anyone who already has experience with this?

https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

I already have implemented Google Tag Manager in the head and body of the pages

https://developers.google.com/tag-manager/quickstart

Can you give some more details on what "it does not work" means? Have you tried checking the devtools and seeing if there were error messages in the console?


thanks


Stacey

Solution

You are wrapping your entire script with EncodeJavaScript. It won't execute that way, because it will encode parts that you may want encoded.

Try wrapping only the parameters in EncodeJavaScript, like this:

SyntaxEditor Code Snippet

"
<script>
    $('." + EncodeJavaScript(instanceId) + "_knob').knob({
        'release': function(value) {
             TriggerKnobEvents('" + EncodeJavaScript(instanceId) + "', value);
        }
    });
</script>
"
Solution

G. Andrew Duthie wrote:

You are wrapping your entire script with EncodeJavaScript. It won't execute that way, because it will encode parts that you may want encoded.

Try wrapping only the parameters in EncodeJavaScript, like this:

SyntaxEditor Code Snippet

"
<script>
    $('." + EncodeJavaScript(instanceId) + "_knob').knob({
        'release': function(value) {
             TriggerKnobEvents('" + EncodeJavaScript(instanceId) + "', value);
        }
    });
</script>
"

Hi Andrew,  

thanks that's the solution!, 

I am now using a structure and a json serialize.