Jump to content
  • 0
Sign in to follow this  
davidhshugar

Auto-submit a Form to Track User Page Views

Question

Hello,

I want to include a hidden form at the bottom of a web page with multiple datapages that auto-submits when a user enters a page. This is meant to track which user view which specific website pages.

All the other scripts I have tried have put my page into a infinite loop and are not working. For example, this script below does not work. 

<script type="text/javascript">
  if(document.getElementById("caspioform")) {
  document.getElementById("caspioform").style.display = 'none';
  setTimeout('document.forms["caspioform"].submit()',1000); } 
</script>

Any advice? 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

@davidhshugar

I suggest you using the custom event to fire scrip only if datapage is ready.

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
// do something  
});
</script>


Check this article to get familiar with this event - https://howto.caspio.com/release-notes/caspio-bridge-13-0/13-0-impacted-areas/

Also, you use the string as the first parameter of the setTimeout() method. setTimeout() works in a different way.
You need to use a function to do something inside setTimeout() method.

Please check this article: https://www.w3schools.com/jsref/met_win_settimeout.asp

<script type="text/javascript">
document.addEventListener('DataPageReady', function () {
 let submissionForm = document.querySelector('form[action~="your_deploy_url"]');
 submissionForm.style.display = 'none';
 setTimeout(
   function() {
     submissionForm.submit();
   }, 1000); 
 } 
});
</script>

Use the Deploy URL link of your datapage instead of "your_deploy_url" within the code.

joxi_screenshot_1560432627071.png.62a16af8e663d0de87dc6178f5cbf577.png

Share this post


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.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   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...
Sign in to follow this  

×
×
  • Create New...