This is a bit of a shot in the dark since I ran your code and the event will fire every time (I assume your Cookies object / function is working), but I wonder, 12,000 numbers might be wrong ...
Is the snippet here exactly that your site is working? Where do you submit your GA page view? I ask because I see the event right after your create function. Another potential reporting problem that I see is that the event is interactive, which means that it will affect the bounce rate if you also submit a pageview (which I assume).
What specific metric do you mean when you say 12,000 visits? Sessions?
Sending events before viewing pages will also give you a bunch of (not set) Landing Page sizes. This means that the event will not be associated with any landing page, and when viewing the page it will also increase your user counter ... Therefore, if you see more users than sessions that indicate that this is a problem.
Some things to try:
- Submit a pageview before the event.
- Set the event as an event with no interaction using
{nonInteraction: true} . - Another thing I would like to do is to put the event only in the
create conditional and the page should always be viewed regardless of the localstorage condition. - Edit: you also expect the DOM to be ready for
create . I would move it to the <head> tag so that the event is the only one waiting for the document to be ready.
<head> <script> </script> </head>
function isLocalStorageNameSupported() { var testKey = 'test', storage = window.localStorage; try { storage.setItem(testKey, '1'); storage.removeItem(testKey); return true; } catch (error) { return false; } } $(function() { if(isLocalStorageNameSupported()){ var version = Cookies.get("version"); if (version == null) { if (Math.random() >= 0.5){ Cookies.set("version", "A"); var version = "A" }else{ Cookies.set("version", "B"); var version = "B" } ga('send', 'event', 'Pricing Experiment', 'New Unique Visit', version, 0, {nonInteraction: true}); } } });
See how it brings your metrics closer together, and then consider an alternative way to track data:
Perhaps the event here is not the best solution. What you do sounds like a great candidate for using a user-limited user size.
I would recommend creating a custom parameter called “Price Experiment” with a user scope (because with GA Experiments the user will always see the same variations in successive sessions), and then after your create function replace the event with this: ga('set', 'dimension1', version); (remember to replace dimension1 with your actual number.
Finally, submit the page view after setting the dimension (custom sizes use hit types to transfer to GA).
<head> <script> </script> </head>
Now, when you look at some other report, you can apply the Secondary Dimension of the “Evaluation Experiment” and you can show which version they saw.
Thus, you can get contextual data without entering into the types of strokes that change reporting indicators.
Again, I apologize if this does not completely cover your problem - I take the fragment that you provided literally and fill in any gaps as possible.