Pass custom data to Google Analytics with Goal Tracking - javascript

I'm using Google Analytics with goal tracking to track when a user submits a form that is on every page of my website. Currently this tells me when the form has been submitted, but is there a way of passing through the page name as well so I can track what page the form has been sent from?
My goal tracking is set up with the Event goal type and I have configured the goal to use a category, action and label with the following code on the submit button, which works fine:
onclick="_gaq.push(['_trackEvent', 'Total Form Submits', 'Submit', 'Form Submit']);"

If you set the second dimension in the events report to "page" it will show you the path were the event was triggered. For goals you can see the info in the conversions->goal urls report. So you can see where your goal was triggered without additional code.

You could also replace your event action or label with a "form name" that would allow you to identify your form. No point in sending in "submit" and "form submit".
An example, for a contact us form:
onclick="_gaq.push(['_trackEvent', 'Total Form Submits', 'Contact Us', 'Submit']);"

Related

Pass multiple Field Values and submit through HTML Link

There is a website that I do not have access to on the back-end that I go to monthly, type in my email address, check a few boxes and hit a submit button.
A while ago I found out You can append
?fieldname=value
to the end of the url to have it automatically fill that value into the field with that name. But is there anyway I can expand on this and fill in multiple values and hit the submit button?
Thanks!
Adding ?fieldname1=fieldvalue1&fieldname2=fieldvalue2 etc.. can add many more parameters send to the server.
Some website use those parameters in the page so when you add the good parameters, you will get the page with the modifications that those parameters did on it.

Shopify - Adding Email Form to Add-to-Cart Button

Is there a way to add some kind of form requesting the customer email address when adding to the cart?
click 'add to cart'
popup asking for email (optional)
moving forward to the cart, passing along the add to cart product info.
My understanding is that with forms, you have your action attribute which says where the form's data will be sent and that your button's type attribute of submit will execute the form's action.
I know each theme is different and some don't have a button element with type="submit" to execute the action. But with a theme like "Debut", which has a very simple add-to-cart form, how would you go about this?
Note: I don't need help creating a lighbox, but I'm confused about how to refrain from executing the cart action until the popup is finished (meanign the customer has either entered their email or chosen to decline).
Please let me know if you need any more information! Thanks

Insert Google Analytics Tracking Code by way of Javascript

I'm trying to insert the GA Tracking Code in a form at Contact Form 7, but it isnt working by the "Additional settings"
on_submit: "ga('send', 'event', 'Contact', 'Send');"
^ ISN'T WORKING On "Additional settings"
I create an ID for the send button of my form to insert the tracking code by Js/jQuery, but i dont know the js code to insert it.
Someone can help me with it or another solution? Thanks a lot.
If you are trying to track form use, on a page Analytics tracking code is already installed on, you can attach to either of two events:
on_submit (executed when form is submitted regardless of outcome), or
on_sent_ok (mail sent successfully). All script must be on one line.
Contact Form 7 expects the format:
on_sent_ok: "alert('sent ok');"
on_submit: "alert('submit');"
http://contactform7.com/additional-settings/
If you are simply trying to add Analytics tracking code to the page, you are better off modifying the theme template files - either page or footer.

Google Docs - Autopopulate live form

i have a webpage that host events (example: http://www.mysite.com/test/events/5493.html) that page holds information such as event title and other info, using google docs i've created a form that fills out my spreadsheet (survey)
The issue is that how can i get the event information from "5493.html" and autopopulate the fields that i set up on the google docs form (live form)
Event Name: [auto populate from the "5493" page]
Date of Event: [auto populate from the "5493" page]
Please rate:
question:
question
[submit button]
What i want to do is to send the link (live form link) and when someone else wants to fill out the googel survey form, those 2 fields are auto-populated to avoid typo mistakes.
i know there is a way to manually modify the link however are there any automated options???
Thank you!!
Looks like google docs now supports it.
See: https://support.google.com/docs/bin/answer.py?hl=en&answer=160000

How to set up Google Analytics goal tracking of a contact form with no separate thank you page?

How do I set Google Analytics up to track visitors to my website who have submitted a contact form, that doesn't have a separate thank-you url?
Ive seen the code posted around blogs and GA help forums but so far have yet to come across how would I actually set the goal up in order to insert the snippet of code.
Code found on forums and such:
onsubmit="pageTracker._trackPageview('/Goa1-Button'); pageTracker._trackEvent('Goals','CLick-Button');"
Specifically, I would like to know things such as:
What goal type would I use?
If i named the campaign Contact form completions, where would it go and fit in to the code above?
Is the code above right and will it help me?
Any other advice, any one ever had to do this before?
So it looks like from the URL you posted in a comment on yahelc's answer, that you have a form that submits and gives back a response via AJAX.
Also, your on-page GA code is the async version, but the code you have in your question is the traditional, so you need to use the async syntax.
On your page, if the visitor does not fill something out, the area in question gets highlighted in red (sidenote: I see no "you need to fill this out" or "this is the correct format" messages if I do not fill out the form correctly..you should look into adding that...).
The main thing you need to make sure is that you only pop the 'success' code if the visitor successfully fills out the form. So you don't really want to attach the GA code to the onsubmit because this can produce false positives..it will trigger whenever the visitor clicks the submit button, regardless of whether or not they successfully filled out the form.
So it looks like the javascript that handles form validation is in your /custom.js, and you have on line 163 of custom.js viewsource the following:
success: function(response){
jQuery(".ajax_form").before("<div class='ajaxresponse' style='display: none;'></div>");
jQuery(".ajaxresponse").html(response).slideDown(400);
jQuery(".ajax_form #send").fadeIn(400);
jQuery(".ajax_form input, .ajax_form textarea, .ajax_form radio, .ajax_form select").val("");
}
});
This looks to be where the "thank you" message is displayed, after the form has been validated and submitted, so you should put your GA "success" code somewhere in this function.
The code you will want to insert should look something like this (based on the code in your question):
_gaq.push(['_trackEvent', 'Goals', 'CLick-Button']);
_gaq.push(['_trackPageview','/Goa1-Button']);
NOTE: For the event tracking, this will set the event category to "Goals" and the event action to "CLick-Button". There are other optional arguments you can pass to the _trackEvent for further granularity. Refer to GA's event tracker guide for more details.
As for the goal tracking, as yahelc mentioned, this is setup within the interface. The code above will send a virtual page view with a page name of "/Goa1-Button" and you will use this value in setting up your goal. There are a lot of ways you can set it up the goal. You can make it exactly match that value or start with that value if you anticipate URL params being added to it later, etc...(but also note, you cannot currently create goals based on events...which is lame, but I hear GA is working on making that happen eventually).
edit: Apparently you actually can set goals based on events, if you use the "New Version", as mentioned by yahelc in his answer comments. Nice!
Goals are configured from within the Google Analytics interface, and do not apply retroactively.
You should check out How do I set up goals and funnels?
You can specify a specific page, event or amount of time on site as your goal.
As far as how to configure the code that will track submission of your form, that requires more information (i.e. code samples) to help you with. But, most importantly: Is it an AJAX form, or a regular form that just posts to the same URL? Are you using async or traditional Google Analytics syntax?
EDIT:
Based on the form you just posted, it looks like its an AJAX POST that returns an HTML body.
So, all you need to do is add your "goal" code into that markup, something like:
<script>
_gaq.push(["_trackPageview", "/contact-us"]); //for a URL goal
_gaq.push(["_trackEvent", "Contact Us", "Submit"]); //for an event goal.
</script>

Categories