What is the correct syntax for adding a custom cookie in Google Analytics? - seo

Google's own site seems to provide conflicting documentation.
I've found at least 4 variations for adding A custom cookie to GA.
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=6a452bd09455721a&hl=en
http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=4362f4d46e6e723a&hl=en
http://analytics.blogspot.com/2009/07/segment-your-traffic-with-user-defined.html
Here is the code I currently have embedded in my company's sharepoint site. I'm beginning to think that this will not work, and that I will have to create an "employee.html" page on my public webserver that I will have to request all employees load once to generate the cookie on their PC's. My secondary question, is after I setup a employee.html page as the example http://analytics.blogspot.com/2009/07/segment-your-traffic-with-user-defined.html here describes, how do I keep all the external traffic from accessing that same page?
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20842347-1']);
_gaq.push(['_setCustomVar',1,'visitor-type','employee']);
_gaq.push(['_setDomainName', '.sc-pa.com']);
_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);
})();
</script>
</HEAD>

None of those links talk about setting a custom cookie. Also, it seems to me that you aren't really needing to set a custom cookie. It looks like you are just wanting to be able to segment your traffic into different buckets.
You can do this many different ways, one of which you have in your code example: you can set a custom variable with different values, depending on the type of user.
So it would set the same cookie, etc.. and you pass different values in this line of code
_gaq.push(['_setCustomVar',1,'visitor-type','employee']);
Then in your reports you can setup filters based off of custom variable 1, or look at the custom variable reports directory, or use custom variable 1 as a metric in your reports.

Related

How to fetch data from Xero private app api to google sheet using google apps script

I create xero private api.
I need to know how to connect this api using google apps script for loading api data to google sheet
Here's a simple API connection:
function publicAPIs() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('publicAPIs.org')
sh.activate();
var rg=sh.getRange(1,1,3,2);
var vA=rg.getValues();
var apiObj={};
for(var i=0;i<vA.length;i++){
apiObj[vA[i][0]]=vA[i][1];
}
var r=UrlFetchApp.fetch(apiObj.baseurl + '/categories');
var cA=JSON.parse(r);
var catA=[];
for(var i=0;i<cA.length;i++){
catA.push([cA[i]]);
}
ss.getSheetByName('NamedRanges').getRange(2,1,catA.length,1).setValues(catA);
var url=apiObj.baseurl + apiObj.qry.replace('~~~',encodeURIComponent(apiObj.category));
Logger.log(url);
var result=UrlFetchApp.fetch(url);
var response=JSON.parse(result.getContentText());
Logger.log(response.count);
var hl=Utilities.formatString('<br />URL:%s', url);
hl+='<br /><input type="button" value="Exit" onClick="google.script.host.close();" />';
hl+='<style>td,th{border:1px solid #000;}</style><table><tr><th>No</th><th>API</th><th>Description</th><th>Auth</th><th>HTTPS</th><th>Cors</th><th>Link</th><th>Category</th></tr>';
for(var i=0;i<response.count;i++){
hl+=Utilities.formatString('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',i+1, response.entries[i].API, response.entries[i].Description,response.entries[i].Auth,response.entries[i].HTTPS,response.entries[i].Cors,response.entries[i].Link,response.entries[i].Category)
}
hl+='</table>';
var userInterface=HtmlService.createHtmlOutput(hl).setWidth(1000);
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'publicAPIs.org')
}
Here's what the spreadsheet looks like:
The function also loads the validation rule from a NamedRange.
alternatively, you may use one of the existing tools or add-ons to sync your data between Xero and Google Sheets. One of the suitable options is described in this article on how to link Xero to Google Sheets. However, you can also check out G-Accon add-on as well. Both tools will let you do it without writing a script.

Changing script on website

I was recently asked to change a script that is on this shopify website but I am unable to find it in either the backend settings or the actual code for the template. Could someone please point me in the right direction on how to change the code for this script? The pixel values are wrong here and it's causing SEO issues:
<script>
//<![CDATA[
(function() {
function asyncLoad() {
var urls = ["\/\/productreviews.shopifycdn.com\/assets\/v4\/spr.js?shop=myshop.myshopify.com","\/\/www.beetailer.com\/javascripts\/beecart.js?shop=myshop.myshopify.com","https:\/\/media.conversio.com\/scripts\/shopify.js?shop=myshop.myshopify.com","https:\/\/s3.amazonaws.com\/lastsecondcoupon\/js\/freeshippingbar.js?shop=myshop.myshopify.com","\/\/facebook.shopifycdn.com\/tracking_pixels\/123.js?shop=myshop.myshopify.com","\/\/facebook.shopifycdn.com\/conversion_pixels\/123.js?shop=myshop.myshopify.com","\/\/notifyapp.io\/js\/1463319629\/loader.js?shop=myshop.myshopify.com","https:\/\/embed.tawk.to\/widget-script\/58065fec304e8e75855e4cce\/default.js?shop=myshop.myshopify.com","https:\/\/www.affiliatly.com\/shopify\/shopify.js?affiliatly_code=AF-10200\u0026shop=myshop.myshopify.com"];
for (var i = 0; i < urls.length; i++) {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = urls[i];
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
}
window.attachEvent ? window.attachEvent('onload', asyncLoad) : window.addEventListener('load', asyncLoad, false);
})();
//]]>
</script>
This code is included by Shopify as a part of the {{ content_for_header }} Liquid variable in the layout files (e.g. theme.liquid.)
The JavaScript files would be ScriptTag scripts that have been added to the store by Shopify apps that you have installed. For example https://productreviews.shopifycdn.com/assets/v4/spr.js belongs to the Product Reviews app.
These scripts are hosted by the app developers so you won't be able to edit them directly. You can remove a ScriptTag script by uninstalling the Shopify app that placed it there.
It looks like the function above is loading the java script (.js files) dynamically in the code and adding the script to the domain:
var urls = ["\/\/productreviews.shopifycdn.com\/asse....
You would need to download the .js files (url are listed in the code), modify them, and change the path so that the above function can load them from a local path.
Following array is URL to all the JS scripts... Each of the item in this array is loaded after page loads.
var urls = ["\/\/productreviews.shopifycdn.com\/assets\/v4\/spr.js?shop=myshop.myshopify.com","\/\/www.beetailer.com\/javascripts\/beecart.js?shop=myshop.myshopify.com","https:\/\/media.conversio.com\/scripts\/shopify.js?shop=myshop.myshopify.com","https:\/\/s3.amazonaws.com\/lastsecondcoupon\/js\/freeshippingbar.js?shop=myshop.myshopify.com","\/\/facebook.shopifycdn.com\/tracking_pixels\/123.js?shop=myshop.myshopify.com","\/\/facebook.shopifycdn.com\/conversion_pixels\/123.js?shop=myshop.myshopify.com","\/\/notifyapp.io\/js\/1463319629\/loader.js?shop=myshop.myshopify.com","https:\/\/embed.tawk.to\/widget-script\/58065fec304e8e75855e4cce\/default.js?shop=myshop.myshopify.com","https:\/\/www.affiliatly.com\/shopify\/shopify.js?affiliatly_code=AF-10200\u0026shop=myshop.myshopify.com"];

Access Not Configured. The API (Drive API) is not enabled for your project. Please use the Google Developers Console to update your configuration

I got a bit of a problem.
i created a googlesheet and included a script, like this, to send it as a pdf to my email address:
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Custom Menu')
.addItem('Send summary', 'menuItem1')
.addSeparator()
.addItem('Send summary&Week', 'menuItem2')
.addToUi();
}
function menuItem1() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var subject = source.getSheets()[9].getRange('G1').getValue(); //cell for subject in sheet
var body = source.getSheets()[9].getRange('F1').getValue();
var sheetNumSummary = 9; // first sheet(tab) is zero, second sheet is 1, etc..
var source = SpreadsheetApp.getActiveSpreadsheet();
var thema = source.getSheets()[9].getRange('f3').getValue(); //
var mailTo = ('youremailaddress#here.com'); //source.getSheets() [0].getRange('D1').getValue(); // 'D1' cell which consists an emailaddress.
var name = source.getSheets()[9].getRange('G1').getValue(); // Name of Attachement
var sheets = source.getSheets();
sheets.forEach(function (s, i) {
if (i !== sheetNumSummary) s.hideSheet();
});
var url = Drive.Files.get(source.getId())
.exportLinks['application/pdf'];
url = url + '&size=letter' + //paper size
'&portrait=false' + //orientation, false for landscape
'&fitw=true' + //fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' + //hide optional
'&gridlines=false' + //false = hide gridlines
'&fzr=false'; //do not repeat row headers (frozen rows) on each page
var token = ScriptApp.getOAuthToken();
var response = UrlFetchApp.fetch(url, {
headers: {
'Authorization': 'Bearer ' + token
}
now comes the weird thing. I'm able to use it with the Google sheet i used it with, but if i do a copy of it and use the script from the menue i get the message:
Access Not Configured. The API (Drive API) is not enabled for your project. Please use the Google Developers Console to update your configuration.
I checked everything in the admin and developer console, but couldn't find anything. I also activate:
Two-legged OAuth access control Allow access to all APIs
The key and secret above are able to access any user's data for all Google Data APIs. Learn more
If i leave the copy of the 1st sheet and deactivate the API access, the 1st sheet (the origin) doesn't work anymore with the script and i get the above alert message. I have to delete the copy, reactivate the API access to make it work again. So, somehow i guess, the copy is working with the a script that only allows to work with one Project Sheet and not with the copy of that sheet. Is there somehow a way to make it work? Or, how can i add/attach the script to the copy. I used this script:
function getSpreadsheetKey() {
return SpreadsheetApp.getActiveSpreadsheet().getId();
};
and saw that it gives me the google key from the original sheet. that might be the reason why i cant use the script with the copy of the google sheet. But i still don't know how wire it correctly.
This message [(403) Access Not Configured] means that when you set up your Google Drive Access, you missed out "Activate the Drive API". You did not configure the Drive API to enabled in your Google account.
To Activate the Drive API, go to Developers Console and Enable the Google Drive API.
Regarding 'Two -legged OAuth access control' it is not necessary to activate. As stated in the document: to bypass any access control checks in the Google Data API when using the domain key.
You have to Set up API access credentials [OAuth].
Here's a link to enable Drive API: https://developers.google.com/drive/v3/web/enable-sdk
For Two-legged OAuth access control document, here's the link: https://support.google.com/a/answer/162105?hl=en
I just had this problem and it solved it self automatically.
It looks like there is some delay in allowing the API to being used (after it being enabled)
For reference I had enabled the API and setup the two stage OAuth.
Basically what happened was that I had a unit test to validate the access and:
the test failed
googled the error code
saw this SO thread
spent some time trying to figure out what was wrong
run the test again (and it passed)

Get tagged photo without access token

I have some problem on this. Can I get public tagged photo from Instagram api without getting any code or access token?
Please share any link for reading because I cannot found any. I feel it is less knowledge about Instagram api on web.
Thanks!
You can pull public media by tag without authentication.
Take a look at the API documentation for the get /tags/tag-name/media/recent endpoint. Here's the URL: http://instagram.com/developer/endpoints/tags/#get_tags_media_recent
The documentation can be confusing, it shows using an access_token for this endpoint in the example, but it is not required. You will need to register an application and get a client ID.
I use MeteorJS and call a method server side that returns essentially the 'view source' of the instagram page. So if you can run a server side scrape on the tag url you will be able to handle the response with what i have below and it will push all the images into an array.
//server side method
Meteor.methods({
'scrapeInst':function(tag){
return Scrape.url('https://www.instagram.com/explore/tags/'+tag+'/')
}})
//client side logic
Meteor.call('scrapeInst',Session.get('params').tag,function(err,resp){
var theInstResp = resp;
cleanOne = resp.replace(/>|window._sharedData = |;</|;|#47;|<|/g,'').split('script')
var splitter = cleanOne[22].split(',');
var theArr = [];
_.each(splitter,function(e){
var theFinal = {};
var theS = e.split(":");
if(theS[0].replace(/"| |/g,'') === "display_src"){
theFinal[theS[0].replace(/"| |/g,'')] = theS[2].replace(/%22/g,'');
theArr.push(theFinal)
}
});
Session.set('photos',theArr);
setTimeout(function(){
Session.set('loading',false)
},1000)
})

Google Analytics custom variables not showing on reports

I "inherited" this code that is using Google Analytics to track errors using custom variables but they are not showing up on the Google Analytics website. Unfortunately the guy who implemented this no longer works here and no one else knows how it works or can even tell me if these custom variables used to work. I have been reading the documentation and examples on this site and it appears he has it correct. Here is the code minus the account number:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXXX-1']);
_gaq.push(['_setCustomVar', 1, 'ErrorCode', 'BadPassword-05', 3]);
_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);
})();
</script>
This code is in the tags before any other javascript. When I go to the Google Analytics site I can see 18,000 visits and it shows me all of the URL information but when I go to Audience->Custom->Custom Variables it doesn't show anything and says there is "no data for this view". From what I understand from the documentation and my web searches that this is where the data should be. Can anyone give me advice on how this works or based on the code if the previous developer even coded it correctly?
This code stores a Custom Variable on the "page" scope ('3' as the last value), and the current GUI, there is no standard report showing page level custom variable reports.
You need to build a Custom Report (table format), with Custom Var value and Page.
This should show you the collected data.