Google analytic with iframe. Campaign tracking does'n work - javascript

I have problem with custom campaign tracking in Google analytic.
In sns my app embedded with inframe and all link looks like:
http://www.odnoklassniki.ru/game/tunerlife?utm_source=source1&utm_medium=Medium1&utm_campaign=CompName
but for iframe this param send like custom_args:
http://cdn.tuner-life.com/tl/frame_od.htm?authorized=1...custom_args=utm_source%3Dwork%26utm_medium%3Dwork1%26utm_campaign%3Dworkwork&session_...
in javascript i parse this param and push _setCampSourceKey and other 2 parameters like in a google documentation :
var custom_args = decodeURIComponent(flashvars["custom_args"]);
var custom_pairs = custom_args.split('&');
for (var i = 0; i < custom_pairs.length; i++)
{
var c_pair = custom_pairs[i].split('=');
if (c_pair[0] == "utm_source")
_gaq.push(['_setCampSourceKey', c_pair[1]]);
else if (c_pair[0] == "utm_medium")
_gaq.push(['_setCampMediumKey', c_pair[1]]);
else if (c_pair[0] == "utm_campaign")
_gaq.push(['_setCampNameKey', c_pair[1]]);
}
but i dont see my custom campaign in GA.
What wrong?

It looks like you're trying to change the key values but in reality you're changing the key names; don't do that. The utm_source keyname is still "utm_source" with a value of "work" but you're changing the keyname to "work", and theres no "work=work" in the URL so GA isn't recording a hit. Just delete that javascript code entirely.

Related

Pulling revenue data from a Google Analytics e-commerce snippet into another revenue tracking snippet

We currently have Google Analytics ecommerce tracking set up on our form thank-you pages. We're also using Optimizely to run A/B/n tests on our website. Optimizely's an online split-testing platform, that also has revenue tracking you can configure.
We'd like to get Optimizely revenue tracking up and running, but are limited with what the form can push out code-wise. I'm hoping to find a solution where we can pull the revenue data from the GA ecommerce snippet into the Optimizely snippet on the same page.
Here is the GA e-commerce snippet:
//Ecommerce Tracking Code
if (pageName == 'thankyou') {
//Pull apart and use pieces of the HTML Document.Title
//where proposed convention is :: Fund - eventName - eventVersion
//changes based on provided example:
var pageIdentity = document.title;
var parsePageName = pageIdentity.split(" - ");
var fundName = parsePageName[0];
var eventName = parsePageName[1];
var eventVersion = parsePageName[2];
var paymentType = "oneTimeCreditCard";
var donationAmount = "$5.00";
var constituentID = "13921362";
var eventID = gup('eventid')||gup('eid');
//handles ecommerce transaction variables populated for GA
amount = getPaymentAmount("#ctl00_ctl00_mainContent_bodyContentPlaceHolder_hidDonationAmount");
pageTracker2._addTrans(constituentID, "PaymentNew", amount,"","","","","");
pageTracker2._addItem(constituentID, eventID,fundName+"-"+eventName,paymentType,amount,"1");
pageTracker2._trackTrans();
} // if donatethankyou
and we're trying to pull the donationAmount variable (or equivalent) into the Optimizely snippet:
window.optimizely = window.optimizely || [];
window.optimizely.push(['trackEvent', 'eventName', {'revenue': valueInCents}]);
Is this possible with the current setup? My JS is (clearly) very rusty.
Thanks in advance!
It is possible with your current setup.
//initiates Optimizely code if it's been loaded, if not queue the function calls in a JavaScript array.
window.optimizely = window.optimizely || [];
//takes the string for donationAmount variable, replaces the $, converts to string, and multiplies by 100
var totalPrice = Number(donationAmount.replace(/\$|,/g, '')) * 100;
//pushes event to optimizely with total.
window.optimizely.push(['trackEvent', 'thankYouPage', {
'revenue': totalPrice
}]);
You'll also need to set up two goals:
Custom event (responsible for getting the event into optimizely)
Revenue (for seeing revenue in your experiment)

How can i get all URL's of a google chrome window

im currently developing an extension, but im kind of lost by the moment.
Basically, what i want it to do, its kind of what "OneTab" extension does.
So my first question is, after adding the listener to the extension button, and executing the function, i want to get all the url's of the current window, and store them in an array and the show them in the html file.
So im using this:
chrome.tabs.getSelected(null,function(tab) {
var tablink = tab.url;
console.log(tablink);
});
but its not working and im not sure how it will check all the tabs one by one.
Thanks in advance.
chrome.tabs.getSelected() will only get you the current tab.
In order to get the list of all the tabs in the current window, you need to use the chrome.windows API. This API will return an object of the current window which will have the list of tab objects.
Here is the sample code:
chrome.windows.getCurrent({"populate":true}, function(currentWindow) {
var tabURLs = [];
var tabs = currentWindow.tabs;
for (var i=0; i<tabs.length; i++) {
tabURLs.push(tabs[i].url);
}
console.log(tabURLs);
});
For details check:
http://developer.chrome.com/extensions/windows.html#method-getCurrent

Google Analytics: How to track hits to mobile site as hits to main site

We are developing a completely new mobile version of our site, it is a HTML5 site written using Sencha Touch 2 (Ext JS, JavaScript).
We are using Google Analytics on our main site, and we would like to use GA on the mobile site as well. However our desired use case is a little special:
We would like hits to articles on the mobile site to be tracked as hits to the corresponding article on the main site.
The reasoning behind this is the desire to aggregate the statistics, and not have the data tracked separately.
The domains and URL structure is different for the two sites, although the site hierarchy is somewhat similar (they both get content from a Sharepoint backend), and herein lies the challenge. We cannot only change the domain using something like 'setDomainName'.
On every page in the mobile version, we have available the full URL to the original page/article on the main site. What we would like to do is tell Google to track the view as a hit to that URL instead of the one we are actually on.
I've seen some threads (f ex here) regarding 'trackPageView' and it may be sufficient for our needs, however I am not entirely sure. It sounds a little too simple, but it may also be that I am not seeing the obvious solution here.
Could we provide this method with the desired hit URL and that's it? Would it work then to have a script in the header that checks for a set variable with this URL, and if it exists call 'trackPageView' with it as a parameter, if not just track a regular hit?
Any help with syntax for this approach is welcome.
All help & suggestions appreciated here!
I've scoured GA docs without much helping information on this special case.
Yes it is that simple use the track page view event and pass the corresponding URL parameters. In sencha all your views are going to exist in the same HTML page so you need to call this programmatically.
Include the same tracking code as you use in your live site with the same ID... This should work as you expect...
Very good question...Hope it helps...
Here's GA Tracking spelled out and made simple for ST2+. I've included how to initialise, set up basic navigation tracking, and several alternatives including custom variable & event tracking.
/*
Standard method to init GA tracking.
These can be fired from launch.
*/
initialiseGoogleAnalytics : function() {
//Add Google Analytics Key
window._gaq = window._gaq || [];
window._gaq.push(['_setAccount', MyApp.config.googleAnalytics.code]);
window._gaq.push(['_setDomainName', MyApp.config.googleAnalytics.domain]);
window._gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
},
/*
This method can be set to a globally accessable reference.
For instance:
MyApp.Util = {}; // reference for common utility functions
MyApp.Util.gaTrackEvent = function(data) {};
Thus allowing MyApp.Util.gaTrackEvent(data) from anywhere in app.
Alternatively, add as function to Application for
this.getApplication().gaTrackEvent(data);
*/
gaTrackEvent : function(data) {
//Push data to Google Analytics
// optional prefix for mobile devices - unnecessary for your interest
var prefix = 'mobile/';
// don't track homepage/default hits
if (data == 'home') {
//Ignore Home
return;
}
// basic tracking
_gaq.push(['_trackPageview', prefix + data]);
// OPTIONAL ALTERNATIVES FOR DETAILED TRACKING
// detailed tracking - condensed
_gaq.push(['_setCustomVar',
1, // custom variable slot
'customEventName', // custom variable name
'value1|value2|value3', // multiple values using 1 slot
2 // sets scope to session-level
]);
_gaq.push(['_trackEvent',
'ParentEventName',
'SomeValue'
]);
// detailed tracking - each variable using own slot
_gaq.push(['_setCustomVar',
1,
'stage1',
'value1',
2
]);
_gaq.push(['_setCustomVar',
2,
'stage2',
'value2',
2
]);
_gaq.push(['_setCustomVar',
3,
'stage3',
'value3',
2
]);
_gaq.push(['_trackEvent',
'ParentEventName',
'SomeValue'
]);
}
/*
Set up a controller to handle GA tracking.
This way you can keep the unique events you wish to track central,
while also handling default tracking and SEO.
For example, a controller for Registration might want tracking on success.
this.getRegistration().fireEvent('registrationsuccess');
*/
config: {
control: {
"navigationview": {
activeitemchange: 'generalSEOhandler'
},
"#registration": {
registrationsuccess: 'onRegistrationSuccess'
},
...
},
},
generalSEOhandler: function(container, value, oldValue, eOpts) {
if (value === 0) {
return false;
}
// ignoreDefaultSeo - boolean custom config that can be applied to views.
var ignoreDefaultSeo = value.getInitialConfig('ignoreDefaultSeo');
if (Ext.isDefined(ignoreDefaultSeo) && ignoreDefaultSeo == 1) {
// optional handler for special cases...
} else {
// Use default
var itemId = value.getItemId();
itemId = itemId.replace(/^ext-/,''); // Remove the prefix ext-
itemId = itemId.replace(/-[0-9]?$/,''); // Remove the suffix -1,-2...
// Alternatively use xtype of the view (my preference)
// This will require the xtypes of your views to match the main site pages.
var itemId = value.config.xtype;
this.trackEvent(itemId);
//console.log('USE DEFAULT', value.getId(), value.getItemId(), value);
}
},
onRegistrationSuccess: function(eventOptions) {
var app = this.getApplication(),
trackUrl;
trackUrl = 'new-member';
if (Ext.isDefined(app.accountReactivated) && app.accountReactivated == 1) {
trackUrl = 'reactivated-member';
}
if (Ext.isDefined(app.registeredUsingFacebook) && app.registeredUsingFacebook == 1) {
trackUrl += '/facebook';
} else {
trackUrl += '/non-facebook';
}
// console.log('onRegistrationSuccess', trackUrl);
this.trackEvent(trackUrl);
},
trackEvent: function(data) {
// if using MyApp.Util.gaTrackEvent() technique
MyApp.Util.gaTrackEvent(data);
// if gaTrackEvent() an application method
this.getApplication().gaTrackEvent(data);
}
}
I found this article talking about Google Analytics and Sencha Touch
http://wtcindia.wordpress.com/2013/03/21/using-google-analytics-in-sencha-touch-based-mobile-website/

Retrieving which tabs are open in Chrome?

Is there a way to retrieve all the tabs open and sort them in to an array in Chrome? So if Gmail and YouTube were open, there would be two entries in the array entitled "gmail.com" and "youtube.com".
Yes, here is how you can do this:
Note: this requires permission "tabs" to be specified in your manifest file.
chrome.windows.getAll({populate:true}, getAllOpenWindows);
function getAllOpenWindows(winData) {
var tabs = [];
for (var i in winData) {
if (winData[i].focused === true) {
var winTabs = winData[i].tabs;
var totTabs = winTabs.length;
for (var j=0; j<totTabs;j++) {
tabs.push(winTabs[j].url);
}
}
}
console.log(tabs);
}
In this example I am just adding tab url as you asked in an array but each "tab" object contains a lot more information. Url will be the full URL you can apply some regular expression to extract the domain names from the URL.
Unless you are building a plugin, there isn't a way that I know of to retrieve all of the names of the open tabs, especially if the tabs contain content from separate domains. If you were able to do such a thing, it could be quite a security issue!
You can check the Chrome documentation here: http://developer.chrome.com/extensions/devguide.html

Custom Google Maps location hotlink

I have a custom map using the Google Maps API to navigate it, and I was looking into getting an address for hot-linking to the current location on the map (like the Maps link such as the following; http://maps.google.com/?ie=UTF8&ll=37.0625,-95.677068&spn=64.880423,135.263672&t=h&z=4 )
I'm not quite sure what the feature is called or how to go about this as I've yet to find anything relevant in the API documentation, does anyone know if this is doable with custom maps, and alternatively how to go about this/pointers on what I should be reading up on?
I've never seen it in the documentation and don't think it's possible. Been looking for it my self without luck.
You probably need to look on the url's query params and navigate to it with javascript.
Do this onload (let's presume that the var map is you google maps object):
var queryArray = window.location.search.substring(1).split('&'),
query = {},
parseQueryByKey = (function () {
var subQuery = '',
i = 0;
for (i = 0; i < queryArray.length; i += 1) {
if (queryArray[i] && queryArray[i].indexOf('=') !== -1) {
subQuery = queryArray[i].split('=');
query[subQuery[0]] = subQuery[1];
}
}
}());
// presumed url http://localhost/?lat=58.1323&lng=18.1231
if (window.location.search && 'lat' in query && 'lng' in query) {
map.setCenter(new google.maps.LatLng(parseFloat(query['lat']), parseFloat(query['lng'])))
}
Hope it helps.
..fredrik

Categories

Resources