Add Javascript Code To Specific Pages

Hello there i would like to add these line of codes in the propriate pages. please help

the following code must be insert in every page before the

this code must be placed when a product is added to cart (i believe those in red are examples so must be the replaced with propriate values of cs-cart)

glami('track', 'AddToCart', {
item_ids: ['ADZXFLUX002'], // product ID currently added to a cart. Use the same ID as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red'], // product name currently added to a cart. Use the same names as you use in the feed (PRODUCTNAME).
value: 2495.00, // product price
currency: 'EUR' // product price currency
});

and this code must be placed in the confirmation of an order

glami('track', 'Purchase', {
item_ids: ['ADZXFLUX002', 'NRS01'], // bought product IDs. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts'], // bought product names. Use the same names as you use in the feed (PRODUCTNAME).
value: 3490.00, // order value
currency: 'EUR', // order value currency
transaction_id: 'ORDER212' // order ID
});

>we are using version 4.8.2 SP2 and the website is mariedore.gr

>i managed to add the first code in every page but it is inserted in the tag not before

every help is appreciated

There is no easy way to do it

1. You can use index:head_scripts hook to add this script

2. I suggest you to use ajax call back to use this code

We can use this also,
$.ceEvent('on', 'ce.ajaxdone', function(e){
     //call event here
});

3. Use checkout:order_confirmation hook on the order landing page to call this event

i tried 1. as u mentioned like

[root]/design/themes/[my_theme]/templates/addons/my_changes/hooks/index/head_scripts.post.tpl

and added the following code

{literal}

{/literal}

but it went between

not before

Use

{literal}

{/literal}

yup that did worked! thanks..

do we know the correct values that must be inserted in the other 2 codes?

item_ides

product_names

value

glami('track', 'AddToCart', {
item_ids: ['ADZXFLUX002'], // product ID currently added to a cart. Use the same ID as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red'], // product name currently added to a cart. Use the same names as you use in the feed (PRODUCTNAME).
value: 2495.00, // product price
currency: 'EUR' // product price currency
});

&

glami('track', 'Purchase', {
item_ids: ['ADZXFLUX002', 'NRS01'], // bought product IDs. Use the same IDs as you use in the feed (ITEM_ID).
product_names: ['Adidas ZX Flux Power Red', 'Nike running shorts'], // bought product names. Use the same names as you use in the feed (PRODUCTNAME).
value: 3490.00, // order value
currency: 'EUR', // order value currency
transaction_id: 'ORDER212' // order ID
});

item_ids

product_names

value

transaction_id

For the purchase print out $order_info array in the template to find required parameters

{$order_info|fn_print_r}

As for Add to cart, how did you integrate it?

Did not find it yet

Did not find it yet

Its not that hard, just use javascript:

$(document).on('click', '.ty-btn__add-to-cart', function () {
    // Javascript code that ought to be triggered on add to cart here
});

The only catch here is that every button for adding something to cart has to have the class '.ty-btn__add-to-cart '

Kind regards,

and where do i insert that code? (our add to cart button includes the .ty-btn__add-to-cart