AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
2.5K members online now
2.5K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Dynamic Form Submission w/ Cross-domain Redirect

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm trying to add a tracker to a dynamic form that doesn't have an action URL to decorate.  So, the tracker fires after the form is submitted, but before it redirects to the payment page.  The form and payment page are on two different domains (cross-domain).  I'll paste the code below.  It's returning an error in Inspect > Console - "Uncaught TypeError: tracker.get is not a function"

 

I'm using Wordpress multisite + Formidable Pro forms.  Forms are loaded/submitted using Ajax.  If I turn off Ajax, it returns a different error, "Uncaught ReferenceError: ga is not defined".  I can't identify the problem in the code.  Any help would be greatly appreciated.

 

<script>
jQuery(document).ready(function(){
var tracker = ga.getAll();
for (i = 0; i < tracker.length; i++) {
var trackingID = tracker[i].get('trackingId');
if (trackingID == "UA-123456-78") {
var linkerParam = tracker.get('linkerParam');
var url = 'https://siteabc.com/payment/?' + linkerParam;
window.setTimeout(window.location = url, 4000);
}
}
});
</script>

 

Re: Dynamic Form Submission w/ Cross-domain Redirect

[ Edited ]
Explorer ✭ ✭ ✭
# 2
Explorer ✭ ✭ ✭

Hi,

This error occurs becuase either google analytics does not exist on the page or its library is not loaded completey
I have made a few changes to your code

<script>
jQuery(document).ready(function(){
    setTimeout(function(){
        if(typeof ga !== 'undefined' && typeof ga.getAll === 'function') {
            var tracker = ga.getAll();
            for (i = 0; i < tracker.length; i++) {
                var trackingID = tracker[i].get('trackingId');
                if (trackingID == "UA-123456-78") {
                    var linkerParam = tracker.get('linkerParam');
                    var url = 'https://siteabc.com/payment/?' + linkerParam;
                    window.setTimeout(window.location = url, 4000);
                }
            }
        }
    },1000);
});
</script>


hope this helps,
cheers
Noman Karim

Re: Dynamic Form Submission w/ Cross-domain Redirect

[ Edited ]
Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hi Norman,

Thanks for your help. Does the code above actually load the library? If the library doesn't load, then the code won't fire. This is the problem I'm encountering. I see tag manager has loaded and fired its tags.

Thanks again,
Chris