Plugin Directory

Changeset 2760263


Ignore:
Timestamp:
07/22/2022 12:59:40 PM (4 years ago)
Author:
newsmanapp
Message:

updates:

Location:
newsmanapp/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • newsmanapp/trunk/includes/class-wc-newsman-remarketing-js.php

    r2743446 r2760263  
    160160
    161161        $ga_snippet_head = "
    162         //Newsman remarketing tracking code             
     162
     163        //Newsman remarketing tracking code REPLACEABLE
     164
     165        var remarketingid = '$remarketingid';
     166        var _nzmPluginInfo = '2.3.8:woocommerce';
     167       
     168        //Newsman remarketing tracking code REPLACEABLE
     169
     170        //Newsman remarketing tracking code 
     171
    163172        var endpoint = 'https://retargeting.newsmanapp.com';
    164173        var remarketingEndpoint = endpoint + '/js/retargeting/track.js';
    165         var remarketingid = '$remarketingid';
    166 
    167         var _nzmPluginInfo = '2.3.7:woocommerce';
     174
    168175        var _nzm = _nzm || [];
    169176        var _nzm_config = _nzm_config || [];
     
    193200        //Newsman remarketing tracking code     
    194201
     202        //Newsman remarketing auto events REPLACEABLE
     203
     204        var ajaxurl = 'https://' + document.location.hostname + '?newsman=getCart.json';
     205
     206        //Newsman remarketing auto events REPLACEABLE
     207
    195208        //Newsman remarketing auto events
    196209
    197         let _nzmIsProd = true;
     210        var isProd = true;
    198211
    199212        let lastCart = sessionStorage.getItem('lastCart');
    200213        if (lastCart === null)
    201             lastCart = {};
     214            lastCart = {};
    202215
    203216        var lastCartFlag = false;
     
    205218        var bufferedXHR = false;
    206219        var unlockClearCart = true;
    207         var ajaxurl = '" . get_site_url() . "?newsman=getCart.json';
    208         var documentComparer = '" . get_site_url() . "/';
     220        var isError = false;
     221        var documentComparer = document.location.hostname;
    209222        var documentUrl = document.URL;
    210223        var sameOrigin = (documentUrl.indexOf(documentComparer) !== -1);
    211224
    212         let startTime, endTime;
    213         let retryS = 5;
    214         var errorFirstLoad = true;
     225        let startTime, endTime;
    215226
    216227        function startTimePassed() {
     
    221232
    222233        function endTimePassed() {
    223 
    224             var flag = true;
     234            var flag = false;
    225235
    226236            endTime = new Date();
     
    231241            var seconds = Math.round(timeDiff);
    232242
    233             if(errorFirstLoad)
    234                 return true;
    235 
    236             if (seconds < retryS)
    237                 flag = false;
     243            if (firstLoad)
     244                flag = true;
     245
     246            if (seconds >= 5)
     247                flag = true;
    238248
    239249            return flag;
     
    247257        }
    248258
     259        function timestamp(min, max) {
     260            min = Math.ceil(min);
     261            max = Math.floor(max);
     262            return Math.floor(Math.random() * (max - min + 1)) + min;
     263        }
     264
    249265        function NewsmanAutoEvents() {
    250266
    251267            if (!endTimePassed())
    252             {
    253                 if (!_nzmIsProd)
    254                 console.log('newsman remarketing: endTimePassed false, exit execution');
    255 
    256268                return;
     269
     270            if (isError && isProd == true) {
     271                console.log('newsman remarketing: an error occurred, set isProd = false in console, script execution stopped;');
     272
     273                return;
    257274            }
    258275
     
    261278            if (bufferedXHR || firstLoad) {
    262279
    263                 xhr.open('GET', ajaxurl, true);
     280                var paramChar = '?t=';
     281
     282                if (ajaxurl.indexOf('?') >= 0)
     283                    paramChar = '&t=';
     284
     285                var timestamp = paramChar + Date.now() + this.timestamp(999, 999999999);
     286
     287                xhr.open('GET', ajaxurl + timestamp, true);
    264288
    265289                startTimePassed();
     
    269293                    if (xhr.status == 200 || xhr.status == 201) {
    270294
    271                         try{
     295                        try {
    272296                            var response = JSON.parse(xhr.responseText);
     297                        } catch (error) {
     298                            if (!isProd)
     299                                console.log('newsman remarketing: error occured json parsing response');
     300
     301                            isError = true;
     302
     303                            return;
    273304                        }
    274                         catch(ex)
    275                         {
    276                             retryS += 5;
    277 
    278                             errorFirstLoad = false;
    279 
    280                             if (!_nzmIsProd)
    281                             {
    282                                     console.log('newsman remarketing: error occurred on parsing xhr');
    283                                     console.log('newsman remarketing: error: ' + ex);
    284                             }
    285 
    286                             return;
    287                         }                   
    288305
    289306                        lastCart = JSON.parse(sessionStorage.getItem('lastCart'));
     
    295312                        if (lastCart.length > 0 && lastCart != null && lastCart != undefined && response.length > 0 && response != null && response != undefined) {
    296313                            if (JSON.stringify(lastCart) === JSON.stringify(response)) {
    297                                 if (!_nzmIsProd)
     314                                if (!isProd)
    298315                                    console.log('newsman remarketing: cache loaded, cart is unchanged');
    299316
     
    302319                                lastCartFlag = false;
    303320
    304                                 if (!_nzmIsProd)
     321                                if (!isProd)
    305322                                    console.log('newsman remarketing: cache loaded, cart is changed');
    306323                            }
     
    317334                            clearCart();
    318335
    319                             if (!_nzmIsProd)
     336                            if (!isProd)
    320337                                console.log('newsman remarketing: clear cart sent');
    321338
    322339                        } else {
    323340
    324                             if (!_nzmIsProd)
     341                            if (!isProd)
    325342                                console.log('newsman remarketing: request not sent');
    326343
    327344                        }
    328345
     346                        firstLoad = false;
     347                        bufferedXHR = false;
     348
     349                    } else {
     350                        if (!isProd)
     351                            console.log('newsman remarketing: response http status code is not 200');
     352
     353                        isError = true;
    329354                    }
    330355
    331                     firstLoad = false;
    332                     bufferedXHR = false;
    333                     errorFirstLoad = false;
    334 
    335356                }
    336357
     
    338359
    339360            } else {
    340                 if (!_nzmIsProd)
    341                     console.log('newsman remarketing: !buffered xhr || !first load');
     361                if (!isProd)
     362                    console.log('newsman remarketing: !buffered xhr || first load');
    342363            }
    343364
     
    358379
    359380            _nzm.run('ec:setAction', 'clear_cart');
    360 
    361             try{
    362 
    363                 _nzm.run('send', 'event', 'detail view', 'click', 'clearCart', null, _nzm.createFunctionWithTimeout(function() {
    364 
    365                     for (var item in response) {
    366 
    367                         _nzm.run('ec:addProduct',
    368                             response[item]
    369                         );
    370 
    371                     }
    372 
    373                     _nzm.run('ec:setAction', 'add');
    374                     _nzm.run('send', 'event', 'UX', 'click', 'add to cart');
    375 
    376                     sessionStorage.setItem('lastCart', JSON.stringify(response));
    377                     unlockClearCart = true;
    378 
    379                     if (!_nzmIsProd)
    380                         console.log('newsman remarketing: cart sent');
    381 
    382                 }));
    383 
    384             }
    385             catch(ex){
    386 
    387                 retryS += 5;
    388 
    389                 errorFirstLoad = false;
    390 
    391                 if (!_nzmIsProd)
    392                 {
    393                         console.log('newsman remarketing: add to cart failed, error loading tracking code (adblock, or other problem)');
    394                         console.log('newsman remarketing: error: ' + ex);
     381            _nzm.run('send', 'event', 'detail view', 'click', 'clearCart', null, _nzm.createFunctionWithTimeout(function() {
     382
     383                for (var item in response) {
     384
     385                    _nzm.run('ec:addProduct',
     386                        response[item]
     387                    );
     388
    395389                }
    396390
    397             }
     391                _nzm.run('ec:setAction', 'add');
     392                _nzm.run('send', 'event', 'UX', 'click', 'add to cart');
     393
     394                sessionStorage.setItem('lastCart', JSON.stringify(response));
     395                unlockClearCart = true;
     396
     397                if (!isProd)
     398                    console.log('newsman remarketing: cart sent');
     399
     400            }));
    398401
    399402        }
     
    416419                    //own request exclusion
    417420                    if (
    418                         pointer.responseURL.indexOf('getCart.json') >= 0 ||
    419                         //magento 2-2.3.x
    420                         pointer.responseURL.indexOf('/static/') >= 0 ||
    421                         pointer.responseURL.indexOf('/pub/static') >= 0 ||
    422                         pointer.responseURL.indexOf('/customer/section') >= 0 ||
    423                         //opencart 1
    424                         pointer.responseURL.indexOf('getCart=true') >= 0
     421                                    pointer.responseURL.indexOf('getCart.json') >= 0 ||
     422                                    //magento 2.x
     423                                    pointer.responseURL.indexOf('/static/') >= 0 ||
     424                                    pointer.responseURL.indexOf('/pub/static') >= 0 ||
     425                                    pointer.responseURL.indexOf('/customer/section') >= 0 ||
     426                                    //opencart 1
     427                                    pointer.responseURL.indexOf('getCart=true') >= 0
    425428                    ) {
    426429                        validate = false;
     
    433436                        bufferedXHR = true;
    434437
    435                         if (!_nzmIsProd)
     438                        if (!isProd)
    436439                            console.log('newsman remarketing: ajax request fired and catched from same domain');
    437440
  • newsmanapp/trunk/newsmanapp.php

    r2743446 r2760263  
    55Plugin URI: https://github.com/Newsman/WP-Plugin-NewsmanApp
    66Description: NewsmanApp for Wordpress (sign up widget, subscribers sync, create and send newsletters from blog posts)
    7 Version: 2.3.7
     7Version: 2.3.8
    88Author: Newsman
    99Author URI: https://www.newsman.com
  • newsmanapp/trunk/wc-newsman-remarketing.php

    r2743446 r2760263  
    66 * Author: Newsman
    77 * Author URI: https://newsman.com
    8  * Version: 2.3.7
     8 * Version: 2.3.8
    99 * WC requires at least: 2.1
    1010 * WC tested up to: 4.1
     
    8080                                                   
    8181                         }                                                         
    82 
    83                         $this->_json($prod);
    84                         return;
     82 
     83                         header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
     84                         header("Cache-Control: post-check=0, pre-check=0", false);
     85                         header("Pragma: no-cache");
     86                         header('Content-Type:application/json');
     87                         echo json_encode($prod, JSON_PRETTY_PRINT);
     88                         exit;
    8589
    8690                        break;
Note: See TracChangeset for help on using the changeset viewer.