Jump to content

Recommended Posts

Hi!

 

I'm trying to build a loop, that looks for certain functions to be loaded, and then using one of them (window.mouseflow.getSessionId) to fetch a value, to be send to the other (s.tl). The getting and the sending works.

 

The issue is this:

 

When the script is loaded, it looks for the functions. It should then try to sending them every 10 ms, and do so 50 times. I want this, because the functions might not be loaded when this script runs.

 

I've added a console.log. If the functions are not there, I would expect it to print out the numbers 50-1. It does not, so I'm suspecing it only tries once. Can any of you tell me why?

 

var tries=50;

function trySending () {
   s.tl(this, 'o', 'mouseflow sessionID', {
linkTrackVars: 'prop50',
prop50: window.mouseflow.getSessionId()
   });}

      
      
 while (tries > 0)
   if (window.mouseflow.getSessionId && s.tl && tries > 0){
setTimeout(trySending(), 10);
        {break;}
      

      } else if (tries > 0); {
     tries--;
console.log(tries) 
      
}

 

Link to post
Share on other sites

Hi Again.

 

I found one issue. A missing set of { }

 

The script now looks like this - still do as I expect, though. It prints out a number about somwhere between 60 and 80, so I still need a helping hand I think.

var tries=50;

function trySending () {
   s.tl(this, 'o', 'mouseflow sessionID', {
linkTrackVars: 'prop50',
prop50: window.mouseflow.getSessionId()
   });}

      
      
while (tries > 0){
   if (window.mouseflow.getSessionId && s.tl && tries > 0 && window.mouseflow.getSessionId !== -1){
setTimeout(trySending(), 10);
        {break;}
      

      } else if (tries > 0); {
     tries--;
console.log(tries) ;
      
      }}
Link to post
Share on other sites

Google Analytics? I don't understand your fancy "truthy" conditionals. When is this true?

 if (window.mouseflow.getSessionId && s.tl && tries > 0 && window.mouseflow.getSessionId !== -1){

Also...

 

setTimeout(function_name_without_parens, delay)

Link to post
Share on other sites

I noticed this in your while loop:

 

      } else if (tries > 0); {

The semicolon inserts a blank statement in the 'else if', causing whatever came after it to behave incorrectly. I can't tell how you intended it to behave, but I'm sure you didn't put that semicolon intentionally.

Edited by setun-90
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...