Developer forum

Forum » Swift » Extend gtag add_to_cart

Extend gtag add_to_cart

Alexander Tømmerholen
Reply

Hello,

I need to extend gtag event "add_to_cart". Is there any way that I can overwrite the standard function inside of _cart.js? I`m aware that i can get to the update.swift.cart event but not sure how I should overwrite/change a function inside of that event.  

Inside of _cart.js there is this code:


I need to add two parameters to items. The site im working on is running on Swift 1.23.0

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Alexander

It depends what change you need to do. The only way to change the actual JS is to checkout the Swift project from Github and rebuild the JS with your customization.

Can you tell what you need to change? It might be a change that we have made or need to make or if it is one of the values you need to change, you can do it in the template instead.

Also there is this discussion: https://github.com/dynamicweb/DynamicWeb/issues/139 - if you have any comments on that.

BR Nicolai

 
Alexander Tømmerholen
Reply

Hi Nicolai,

For this case exactly i need to add "item_category" and "item_category2" to items. 

One way is two just add this to _cart.js but if possible i want to avoid that so we don`t have to remeber that we have made some changes to a standard file when we are going to update Swift version later. 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Thanks.

Currently that is the only option with this one....

Sorry about the inconvenience.

BR Nicolai

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Alexander,

 

You should be able to override the function easily in another JS file OR a Razor template as such:


swift.Cart.PushDataToGoogleAnalytics = function () {
    //  My code here
}

 

That way you don't need to change the default js file from Swift if you don't want to. That will also allow you to more easily take a Swift update (because you're not really changing the source).

 

Best Regards,

Nuno Aguiar

 
Alexander Tømmerholen
Reply

Hi Nuno,

Thanks for your suggestion but I was not able to make it work. I will just change the default file for now. 

 

You must be logged in to post in the forum