Correct setup for cross-domain Google Analytics - google-analytics

I can't imagine this is an uncommon problem, but we keep running into challenges.
We have a campaign with a landing page on our site, with a form visitors can fill out. They give us their email, we email them some content. We want to track this as a single GA conversion.
Right now the setup has three pieces:
1) The campaign landing page on our web site
2) The actual form they fill out, which is in an iframe and hosted on a subdomain (info.MMMM.com instead of www.MMMM.com) (this form is managed and hosted by marketing automation service Pardot)
3) The "Thank You" page to which users are redirected once they fill out the form. This is on the main domain, not the subdomain.
We're using Universal Analytics, I believe. We have the stock UA snippet in the overall site footer, so it already appears on both the landing page and the thank-you page.
We have a cross-domain issues, in that right now info.MMMM.com appears as a high-traffic referrer. Of course this is wrong -- that's our own subdomain, and it's masking the real referrer.
I've been following Pardot's instructions for cross-domain tracking. In doing so, I added our UA code snippet to the code generator for the iframed form. This works, but the Google Tag Assistant then tells me I have two GA tags for the same property (one in the iframe and one in the overall page footer I guess).
Am I headed up the wrong tree? Should I just be following the guidelines for "Cross domain auto linking for forms" on this Google page?
https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
Any pointers would be helpful.
Thanks,
SGL

Related

Pass Google Analytics Data into iFrame (we control both the domains)

Currently we have a page laid out like this:
Page on Domain A contains an iFrame with Domain B inside it.
These are both our domains and we are using the same Google Tag Manager/Google Analytics code on both domains. How do I track traffic data into the iFrame from the parent page, so it does not display as "direct" and I can see all the correct information.
It is very important for me to be able to see the parent URL which is hosting the iFrame.
I do not think this is a duplicate question because we control both domains.
Thanks!
I would suggest adding the parent page URL to the Querystring for the embedded iFrame. So if the iFrame URL is current "http://myiframedomain.com/page1.html" it would become "http://myiframedomain.com/page1.html?embeddedIn=http%3A%2F%2Fmyparentdomain.com%2Fpagewithiframe.html"
On the pages within the iFrame you could read this data with either server side code or javascript and pass it to analytics.
In order to set the referrer manually in GA, you could use _gaq.push(['_setReferrerOverride','http://myparentdomain.com/pagewithiframe.html']);
For more on manually controlling referrers with GA, see https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiCampaignTracking#_gat.GA_Tracker_._setReferrerOverride

Google Analytics: Track third-party form submission embedded in iframe (with another iframe)

I have a form hosted by a third party embedded on my site via an iframe (I'll call this the "Parent iFrame"). I would like to track those form submissions in Google Analytics. If I embed another iframe (src being a page on my site that contains my site's GA code; I'll call this the "Child iFrame") within the Parent iFrame's form submission confirmation message, when the Child iFrame loads will that be recorded as a Pageview in Google Analytics?
I researched this question and believe the answer is yes, but the answers I found were usually to more specific questions that didn't directly address this probably much more basic question. Thanks for any help!
I'm a little concerned about the iframe within an iframe situation, but I'm hoping that a visit within an iframe is simply tracked like any other page. Just didn't want to assume... :)

Google Analytics: Visitors flow: Only showing root with 100% drop off, no pages

I would like to use the google analytics visitors flow tool but it does not show any specific page. All visits are in one big block "/". If I click on "group details" pages are listed just fine.
My site uses url parameters like mypage.com?p=products to switch between pages. I have managed to set up analytics so that it understands this and works on the "content" page and everywhere. How can I make it also work with "visitors flow" to display specific pages?
this might be the same problem: Google Analytics: 100% Drop off from landing page
Just noticed that links on my page are missing the slash before the "?". will add the slash and report back.
Edit: Though I guess that was an improvement it did not solve the problem.
I am using absolute links (http:/mysite.com/?p=contact) all over the place. Should I try relative links to get this to work?
Yes, you need to put a / before the ? in your links or else Analytics could interpret your full URL as the domain/sub-domain and not report any page paths or levels (like you're observing).
Additionally, are you sure the Analytics script is firing whenever a new page is loaded? Clicking through your site it looks like the base page template may not be reloading whenever you click to a different page (only the content is reloaded). If this is the case and the Analytics script is part of your base template, it would only fire once when the visitor first enters the site and load the page template and never again. Since Google Analytics calculates pageviews and time on site/page based on the difference in time between when the _trackPageview() is fired, it could explain your problem.
I would suggest moving your Analytics script to a portion of the markup that is reloaded every time someone clicks to a new page to see if this does the trick.

Site is showing up as a referrer to its own domain in Google Analytics reports. Why?

I am having two GA reporting problems with a site I manage that I am not sure how to solve:
The site is showing up as a referrer to its own domain in GA reports.
My goal completions (sales conversions on 3rd party off-domain
ecommerce cart) are all showing the site's domain as "source" when I
obviously want to see the true "referers" who are sending traffic
that results in goal completions.
My thoughts on potential reasons why this could happening:
I am using absolute paths for internal links, like this:
<a href="http://example.com/contact.html">
as opposed to
<a href="/contact.html">
Could this be it? Users often do click around internally before they purchase.
Also, on several high traffic pages, I am using javascript history backlinks, like this ::
go back
Lastly, I'm doing a 301 redirect on "add to cart" traffic clicks so that
http://example.com/add_to_cart
redirects to:
http://paymentprocessor.com/ugly_url/cart_page.html
(Although this is an external 3rd party domain, my GA code still fires there)
Any guesses why I am experiencing the issues stated at the top here? ... thank you to all you GA wizards.
UPDATE UPDATE UPDATE
Thanks Eduardo for the great answer.
Thought I might share that now for href text links to 3rd party ecomm site I am tracking events with jquery via class, so my _gaq.push to track both the click event and copy the cookie data over from my site to the third party site looks like this:
$('a.index_addtocart_smallest').click(function(){
_gaq.push(['_trackEvent', 'Outbound Links', 'index_addtocart_smallest', 'buy_click'],['_link', 'ssl.thirdpartyecom.net/order/']);
});
And when I use the form action "add to cart" submit in the HTML look like this:
<form action="http://example.com/add_to_cart" method="post" onsubmit="that=this;_gaq.push(['_trackEvent','Outbound Links','index_big_buy_button', 'buy_click'],['_linkByPost', this]);setTimeout(function() { that.submit() }, 100);return false;">
... to track the event, and post the existing cookie to third party server, while adding a delay to the click to make sure it is captured by GA.
In my case I am using the asynchronous syntax for Tracking Between a Domain and a Sub-Directory on Another Domain: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#domainAndSubDirectory
In your case it's very clear that the problem is with the cart. When you redirect the user to your cart domain he lands on a new domain and lose access to the cookies that he was using on your site. Because GA needs to create a new set of cookies on the cart site it also creates a new visitor id and a new visit, that visit will be a self referral because that's where the visitor is coming from from GA point of view.
Google Analytics keeps state on cookies, __utm*. So when changing domains we need to copy the cookies from the domain you are currently in to the domain you are moving to. The google analytics API offers some methods to implement this. This is often known as "cross-domain tracking" or "multiple domain tracking". Google Analytics documentation offers a good explanation on how to implement it. You can also search Stack Overflow for several questions related to cross-domain tracking, people seem to have a hard time getting it right.
You are free to use absolute or relative links, it makes no difference for Google Analytics at all.
Javascript redirects are usually ok. Even though there are cases where they certainly make things a little bit more difficult your use case of a back button is fine and should not be causing any problems at all. Of course if the javascript redirect changes the domain you are in you are back to the same issue and needs to implement cross-domain tracking.
Sometimes internal referrers are legitimate. One example of legit self referrals: When a user visits a page on your site and stay there for over 30 min, then navigates to a second page. In that case after the 30 minutes the visit expires and when he navigates to that second page a new visit is created. This new visit will be a self referral and the second page will be considered a landing page. That might seem odd at first, but this is a self referral and it's usually fine.

Google Analytics referral triggered by a bookmarklet

I have a question regarding Google Analytics and unwanted referral stats generated by a bookmarklet.
I have a web service with GA installed. My users are using a bookmarklet to accomplish a certain task while visiting some other web page. Bookmarklet creates an iframe and opens up a page which is also on my domain and that page contains the same GA code.
For some reason GA sees those web sites (pages that bookmarklet was used on) as referral pages. That creates a problem for me since those pages are not real referrals (no actual links to my site). I have no desire to track pages my users marked with the bookmarklet.
It’s important to mention that bookmarklet page must be a part of the same domain as my main page. I can not move it on other domain or subdomain.
This is what I tried so far:
I’ve created a new GA account (subdomain.mydomain.com) and used it only on my bookmarklet page hoping that all stats related with the bookmarklet will appear on that account. This worked only partially. Stats for the bookmarklet started to appear on the new account but my original GA account continued to track referral pages.
We tried to use a pop up window to load a web page instead of the iframe. No difference.
Any help on how to get rid of unwanted referral sites would be appreciated.
See _setReferrerOveride:
_setReferrerOverride()
_setReferrerOverride(newReferrerUrl)
Sets the referrer URL used to determine campaign tracking values. Use this method to allow gadgets within an iFrame to track referrals correctly. By default, campaign tracking uses the document.referrer property to determine the referrer URL, which is passed in the utmr parameter of the GIF request. However, you can over-ride this parameter with your own value. For example, if you set the new referrer to http://www.google.com/search?hl=en&q=hats, the campaign cookie stores a new campaign with source=google, medium=organic, and keyword=hats.
_gaq.push(['_setReferrerOverride', 'URL-YOU-WANT-AS-REFERRER']);
Or, you could try
_addIgnoredRef():
_addIgnoredRef()
_addIgnoredRef(newIgnoredReferrer)
Excludes a source as a referring site. Use this option when you want to set certain referring links as direct traffic, rather than as referring sites. For example, your company might own another domain that you want to track as direct traffic so that it does not show up on the "Referring Sites" reports. Requests from excluded referrals are still counted in your overall page view count.
Async Snippet (recommended)
_gaq.push(['_addIgnoredRef', 'www.sister-site.com']);
You would have to grab the referrer and populate it dynamically. Probably with parent.document.referrer Of course this might make any referrals (non-bookmarklet) from these sites not record in the future. And, at some point you would need to clear them.
The most simple solution, if you don't need to track the hits from the bookmarklet at all, is to simply not include the GA code in the web page when it is opened by the bookmarklet.
Your bookmarklet can open the page like http://yoursite.com/?mode=bookmarklet
And in your server side code you can use something like
if ( mode != "bookmarklet" ) {
outputGaCode()
}

Resources