Re: XHR requests every second

Solved

XHR requests every second

Alex2094
Visitor
2 0 0

My website is Hobbystories.com. There are constant requests to cart.js, every second, I can't figure out what this is about. Is it supposed to be like this? If not, help me fix it.Снимок экрана 2022-02-07 в 19.08.55.png

Accepted Solution (1)

SB_90
Shopify Partner
216 52 69

This is an accepted solution.

Hi @Alex2094 

 

I'm not entirely sure what's causing it. Have you had any custom work done on the site - or just installed apps?

 

It's this bit of code that's causing the call:

 

var orichiCartItemCount = -1;
setInterval(function() {
    if (window.pixels != undefined && window.pixels.length > 0) {
        //debugger;
        $.ajax({
            type: 'GET',
            url: '/cart.js',
            dataType: 'json'
        }).done(cart => {
            if (cart.item_count > 0 && orichiCartItemCount != -1 && cart.item_count > orichiCartItemCount) {
                //debugger;       
                var lastItem = cart.items[0];
                let event_id = (new Date()).getTime() + getRandomInt(1, 100000);
                window.pixels.forEach(function(pixel, index) {
                    let pixelID = pixel.FacebookPixel;
                    orfbq(`${pixelID}`, 'AddToCart', {
                        content_ids: lastItem['product_id'],
                        content_type: 'product_group',
                        value: parseInt(cart.total_price) / 100,
                        content_name: lastItem['product_title'],
                        currency: currency,
                    }, event_id, pixel);
                })
            };
            orichiCartItemCount = cart.item_count;
        }).fail(function(jqXHR, textStatus) {
            orichiCartItemCount = -1;
        });
    }

}, 1000);

 

A quick search on "Orichi Shopify" shows these apps:

 

https://apps.shopify.com/partners/orichi

 

Do you have either of those installed?
 

View solution in original post

Replies 3 (3)

SB_90
Shopify Partner
216 52 69

This is an accepted solution.

Hi @Alex2094 

 

I'm not entirely sure what's causing it. Have you had any custom work done on the site - or just installed apps?

 

It's this bit of code that's causing the call:

 

var orichiCartItemCount = -1;
setInterval(function() {
    if (window.pixels != undefined && window.pixels.length > 0) {
        //debugger;
        $.ajax({
            type: 'GET',
            url: '/cart.js',
            dataType: 'json'
        }).done(cart => {
            if (cart.item_count > 0 && orichiCartItemCount != -1 && cart.item_count > orichiCartItemCount) {
                //debugger;       
                var lastItem = cart.items[0];
                let event_id = (new Date()).getTime() + getRandomInt(1, 100000);
                window.pixels.forEach(function(pixel, index) {
                    let pixelID = pixel.FacebookPixel;
                    orfbq(`${pixelID}`, 'AddToCart', {
                        content_ids: lastItem['product_id'],
                        content_type: 'product_group',
                        value: parseInt(cart.total_price) / 100,
                        content_name: lastItem['product_title'],
                        currency: currency,
                    }, event_id, pixel);
                })
            };
            orichiCartItemCount = cart.item_count;
        }).fail(function(jqXHR, textStatus) {
            orichiCartItemCount = -1;
        });
    }

}, 1000);

 

A quick search on "Orichi Shopify" shows these apps:

 

https://apps.shopify.com/partners/orichi

 

Do you have either of those installed?
 

Alex2094
Visitor
2 0 0

Yes, I have the Facebook Pixels Conversion API app installed, thanks for your help!

PaulNewton
Shopify Partner
6419 585 1362

Per @SB_90 sample, it's analytics code doing exactly what it needs to for it to be able to track conversions of what users are putting in the cart.

 

The calls sizes are very small and can be ignored for the most part , If you want to over optimize performance you would need to deeply integrate the apps code with the themes cart javascript so the calls only happen when users change the cart.

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org