How do I get Custom Variables in Google Analytics to work using Async method? - asp.net-mvc

So, I'm researching how to use Google Analytics by applying it to a test site I've built using VB.NET and MVC5. I'm using the Async method since that seems to be what the Google Developers site is recommending.
In my _Layout.vbhtml (which Visual Studio automatically generated for me) I have the following code between my <head> and </head> tags:
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>#ViewBag.Title - My ASP.NET Application</title>
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
<script>
window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments) }; ga.l = +new Date;
ga('create', 'UA-75489237-2', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<script>
_gaq.push(['_setCustomVar',
5, // This custom var is set to slot #5. Required parameter.
'CusVarTest', // The top-level name for your online content categories. Required parameter.
'Successful', // Sets the value of "Section" to "Life & Style" for this particular aricle. Required parameter.
3 // Sets the scope to page-level. Optional parameter.
]);
</script>
</head>
Now, theoretically, this should be working, but when I go to the Google Analytics site, and go to "Reporting --> Audience --> Custom --> Custom Variables" I am seeing no sign of my variable.
Any thoughts?

A few things:
you are mixing older classic GA syntax (_gaq.push(['_setCustomVar', ...) with the new UA syntax (ga('create', 'UA-75489237-2', 'auto');). That's not going to work. I advise you to make sure you are using only UA code.
Custom Variables have been phased out of UA, so you will need to use the UA analogs called "Custom dimensions" (cf. https://support.google.com/analytics/answer/2709828?hl=en). This includes no longer using the Custom Variables in the reports.
data takes up to 24 hours to process, so you won't see things right away in your reports unless you wait a day, or you could try using GA Debugger or console tools to verify that your data is properly set and sent.

Related

How to style input box(use codemirror) of ThebeLab?

I am trying to integrate the ThebeLab javascript library with my web application. Now so far, using their example code, I am able to integrate successfully. ThebeLab uses a Codemirror editor for its input field. And as per ThebeLab's official documentation, we can even customize the Codemirror editor using the configuration settings provided by Codemirror itself.
Now, when I am trying to customize the Codemirror editor using the example provided by ThebeLab, it is not working. It doesn't even throw any kind of error in console either. Even, the example provided by the ThebeLab on their official web page is itself doesn't work.
Now, this issue is already raised and closed on their official GitHub repository. And as per them, the solution is already provided with the newer version(0.5.1) of ThebeLab javascript. And I am also using the newer version which is 0.5.1, but still, it is not working.
This is my code:
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<title>Thebe Lab examples</title>
<!-- Configure and load Thebe !-->
<script type="text/x-thebe-config">
{
bootstrap: true,
requestKernel: true,
kernelOptions: {
name: "python3",
serverSettings: {
"baseUrl": "http://127.0.0.1:8888",
"token": "test-secret"
}
},
codeMirrorConfig: {
theme: "abcdef"
},
}
</script>
<script type="text/javascript" src="https://unpkg.com/thebelab#latest" ></script>
</head>
<body>
<h1>Thebe Lab: using a local server</h1>
<p>This page illustrates how to setup Thebe Lab, using a local Jupyter server as kernel provider. This assumes that you have started the local server as:
<pre>
jupyter notebook --NotebookApp.token=test-secret --NotebookApp.allow_origin='<span id="origin">*</span>'
</pre>
and that it's running on port 8888
</p>
<pre data-executable="true" data-language="python">print("Hello!")</pre>
<script type="text/javascript">
document.getElementById('origin').innerHTML = location.origin;
</script>
</body>
</html>
Kindly help me out here soon. Thank you.

Initialize VSS.SDK from TS class

I need to initialize the VSS.SDK from a .ts class (outside the html page). I have analyzed some examples from Microsoft and all are initialize under html page.Is it possible to do this outside html page?
You can refer to this link for details: Visual Studio Services Web Extension SDK.
Types
Types of VSS.SDK.js, controls and client services are available in typings/vss.d.ts.
REST Client types for VSTS are available in typings/tfs.d.ts
REST Client and extensibility types for Release Management are available in typings/rmo.d.ts
Using tsd
Although TypeScript declare files do not exist at DefinitelyTyped repo, they can still be used through tsd.
First, make sure that the dependencies are loaded using below
command:
tsd install jquery knockout q --save
Next, run below command to get
vss-web-extension-sdk types added to tsd.d.ts:
tsd link
Finally, add only reference to typings/tsd.d.ts in your
TypeScript files.
Yes, you could to do it outside the html and put it in the JavaScript file or other (e.g. ts), then add the reference to corresponding JS file to the html page.
For example:
VSS.init();
$(document).ready(function () {
VSS.notifyLoadSucceeded();
});
<!DOCTYPE html>
<html>
<head>
<title>Hello word</title>
<meta charset="utf-8" />
<script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.js"></script>
<script src="Scripts/VSSInit.js"></script>
</head>
<body>
<!--<script type="text/javascript">
VSS.init();
</script>-->
<h1>Hello word</h1>
<!--<script type="text/javascript">
VSS.notifyLoadSucceeded();
</script>-->
</body>
</html>

Integrating Activiti Explorer with Ruby on Rails project

I have tried several different methods to accomplish this and none have been successful. Ive tried jruby, the rest api for activiti (this does not update the UI and is thus not suited for my purposes), and the mechanize gem. The mechanize gem did not work because of the VAADIN UI that activiti explorer ships with or so I think. I currently have activiti hosted in an iframe in my rails app, and am trying to find a way to communicate between the two. I used the gem like this:
agent= Mechanize.new
agent.redirection_limit= 10
//page is used three times to illustrate different routes taken.
page= agent.get('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/)
page= agent.post('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/ui/APP/2/login',{'username'=>'kermit', 'password'=>'kermit'} )
page=agent.put('http://127.0.0.1:8080/activiti-webapp-explorer2-5.18.0/ui/1/loginHandler',{'username'=>'kermit', 'password'=>'kermit'})
here is a sample response from activiti explorer when mechanize is used:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">html, body {height:100%;margin:0;}</style><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/favicon.ico" /><link rel="icon" type="image/vnd.microsoft.icon" href="/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/favicon.ico" /><title>Activiti Explorer</title>
</head>
<body scroll="auto" class="v-generated-body">
<script type="text/javascript">
//<![CDATA[
if(!vaadin || !vaadin.vaadinConfigurations) {
if(!vaadin) { var vaadin = {}}
vaadin.vaadinConfigurations = {};
if (!vaadin.themesLoaded) { vaadin.themesLoaded = {}; }
}
vaadin.vaadinConfigurations["activitiwebappexplorer25180ui-1091631569"] = {appUri:'/activiti-webapp-explorer2-5.18.0/ui', standalone: true, themeUri:"/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti", versionInfo : {vaadinVersion:"6.8.8",applicationVersion:"NONVERSIONED"},"comErrMsg": {"caption":"Communication problem","message" : "Take note of any unsaved data, and <u>click here<\/u> to continue.","url" : null},"authErrMsg": {"caption":"Authentication problem","message" : "Take note of any unsaved data, and <u>click here<\/u> to continue.","url" : null}};
//]]>
</script>
<iframe tabIndex='-1' id='__gwt_historyFrame' style='position:absolute;width:0;height:0;border:0;overflow:hidden;' src='javascript:false'></iframe>
<script language='javascript' src='/activiti-webapp-explorer2-5.18.0/VAADIN/widgetsets/org.activiti.explorer.CustomWidgetset/org.activiti.explorer.CustomWidgetset.nocache.js?1444407987049'></script>
<script type="text/javascript">
//<![CDATA[
if(!vaadin.themesLoaded['activiti']) {
var stylesheet = document.createElement('link');
stylesheet.setAttribute('rel', 'stylesheet');
stylesheet.setAttribute('type', 'text/css');
stylesheet.setAttribute('href', '/activiti-webapp-explorer2-5.18.0/VAADIN/themes/activiti/styles.css');
document.getElementsByTagName('head')[0].appendChild(stylesheet);
vaadin.themesLoaded['activiti'] = true;
}
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
setTimeout('if (typeof org_activiti_explorer_CustomWidgetset == "undefined") {alert("Failed to load the widgetset: /activiti-webapp-explorer2-5.18.0/VAADIN/widgetsets/org.activiti.explorer.CustomWidgetset/org.activiti.explorer.CustomWidgetset.nocache.js?1444407987049")};',15000);
//]]>
</script>
<div id="activitiwebappexplorer25180ui-1091631569" class="v-app v-theme-activiti v-app-ExplorerApp" ><div class="v-app-loading"></div></div>
<noscript>You have to enable javascript in your browser to use an application built with Vaadin.</noscript></body>
</html>
I have tried all of the possible url's I could see on the UI, but none of them work. I have tried all of post, get, and put with each of these three urls .I found these URL's by looking at the loaded page, and noticing that they are nested iframes. Any help in seeing the feasiblity of the mechanize gem would be great, as feel as if this would be an easy fix to my problem. As a side note, I have changed the tomcat properties to allow for CORS requests. Also, http requests from rails to activiti explorer do not work either, so that form of communication is also out.
Also if you are familiar with activiti- I have edited the authenticate method in default login handler to try and parse http requests to get the username and password to login automatically. This however returns the same html code as printed above. Any help would be greatly appreciated. Here is a sample of the http requests I make from rails:
auth = {:userid=> "kermit", :password => "kermit"}
puts HTTParty.get("http://activiti.testing.com:8080/activiti-webapp-explorer2-5.18.0/", :content_type => "application/json",
:basic_auth => auth)
I think integrating Activiti Explorer in iframe is not a good idea. Since your username and password are exposed! And the requirements of the frontend are various.
I like Activiti Explorer at first, Modeler is really awesone! But I use Rails and find it hard to customize and integrate Activiti Explorer later. I tried integrate with Activiti REST, while I prefer Activiti Java API for the following reasons:
Activiti REST is a subset of Activiti Java API. eg: SetProcessDefinitionVersionCmd is not availiable in Activiti REST.
Performance concerns. I develop a task web page, but it needs over 10 http requests.
I like Acitivi Modeler and Diagram Viewer. I need Activiti Explorer running and make them work together.
So I develop a gem named jruby_activiti, integrating Activiti Engine, Modeler and Diagram Viewer. All these are availiable in JRuby on Rails! Hope my experiences could help you.

jQuery UI Autocomplete can't figure it out

I decided to use jQuery UI for my autocomplete opposed to a plugin because I read that the plugins are deprecated. My overall goal is to have an autocomplete search bar that hits my database and returns users suggestions of city/state or zipcodes in a fashion similar to google. As of now I am not even sure that the .autocomplete function is being called. I scratched everything I had and decided to start with the basics. I downloaded the most recent version of jQuery UI from http://jqueryui.com/download and am trying to get the example that they use here http://jqueryui.com/demos/autocomplete/ to work. All the scripts that I have included seem to be connected at least linked through Dreamworks so I am fairly certain that the paths I have included are correct. The CSS and Javascripts that I have included are unaltered straight from the download. Below is my HTML code and my backend PHP code that is returning JSon formated data. Please help me. Maybe I need to include a function that deals with the JSon returned data but I am trying to follow the example although I see that they used a local array.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQueryUI Demo</title>
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.8.17.custom.css" type="text/css" />
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
</script>
<script type="text/javascript">
$(document).ready(function() {
$("#tags").autocomplete({
source: "search_me.php"
});
});
</script>
</head>
<body>
<div class="demo">
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags" />
</div>
</div><!-- End demo -->
<div class="demo-description">
<p>The Autocomplete widgets provides suggestions while you type into the field. Here the suggestions are tags for programming languages, give "ja" (for Java or JavaScript) a try.</p>
<p>The datasource is a simple JavaScript array, provided to the widget using the source-option.</p>
</div><!-- End demo-description -->
</body>
</html>
Below the PHP part.
<?php
include 'fh.inc.db.php';
$db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or
die ('Unable to connect. Check your connection parameters.');
mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db));
$location = htmlspecialchars(trim($_GET['term'])); //gets the location of the search
$return_arr = array();
if(is_numeric($location)) {
$query = "SELECT
zipcode_id
FROM
user_zipcode
WHERE
zipcode_id REGEXP '^$location'
ORDER BY zipcode_id DESC LIMIT 10";
$result = mysql_query($query, $db) or die(mysql_error($db));
while($row = mysql_fetch_assoc($result)) {
extract($row);
$row_array['zipcode_id'] = $zipcode_id;
array_push($return_arr, $row_array);
}
}
mysql_close($db);
echo json_encode($return_arr);
?>
Thanks for the ideas. Here is an update.
I checked the xhr using firebug and made sure that it is responding thanks for that tip. also the above php code I hadn't initialized $return_arr so i took care of that. Also thanks for the clarification of the js required or rather not required. Now when I type in a zipcode a little box about a centimeter shows up underneath it but I can't see if anything is in there, I would guess not. I went to my php page and set it up to manually set the variable to "9408" and loaded the php page directly through my browser to see what it returned. This is what it returned.
[{"zipcode_id":"94089"},{"zipcode_id":"94088"},{"zipcode_id":"94087"},{"zipcode_id":"94086"},{"zipcode_id":"94085"},{"zipcode_id":"94083"},{"zipcode_id":"94080"}]
I then went to a JSON code validator at this url http://jsonformatter.curiousconcept.com/ at it informed me that my code is in fact returning JSON formatted data. Anymore suggestions to help me troubleshoot the problem would be terrific.
Wow after more research I stumbled across the answer on someone another post.
jquery autocomplete not working with JSON data
Pretty much the JSON returned data must contain Label or Value or both. Switched the zipcode_id to value in my $row_array and... boom goes the dynamite!
Your scripts (js files) references are not correct, should only be:
<!-- the jquery library -->
<script type="text/javascript" src ="js/jquery-1.7.1.min.js"></script>
<!-- the full compressed and minified jquery UI library -->
<script type="text/javascript" src ="js/jquery-ui-1.8.17.custom.min.js"></script>
The files "jquery.ui.core.js", "jquery.ui.widget.js" and "jquery.ui.position.js" are the separated development files, the jquery ui library is splitted into modules.
The file "jquery-ui-1.8.17.custom.min.js" contains them all, compressed and minified !
Concerning the data source, as stated in the "Overview" section of the Autocomplete documentation: when using a an URL, it must return json data, either of the form of:
an simple array of strings: ['string1', 'string2', ...]
or an array of objects with label (and a value - optionnal) property [{ label: "My Value 1", Value: "AA" }, ...]
I'm really not familiar with PHP so just make sure your php script returns one of those :-)

Linkedin REST API Auth and JSAPI call, Rails/Omniauth

I lost my temper few days ago because of this simple problem. Can you help me on this?
I'm suppose, since it's written in the Linkedin JS API documentation here, to be able to logion with REST and launch calls with JSAPI :
https://developer.linkedin.com/documents/inauth-inevent-and-inui
Authorization Tokens
While the easiest method of authenticating a user for the JSAPI is to
use one of the login buttons, some sites have implemented the OAuth
1.0a flow used by the REST API. Whichever type of authentication you use for the user, the JSAPI will recognize that the member has already
logged in, as long as the key and hostname are the same. This happens
automatically, requiring no additional code by the developer.
But this is NOT working, I have this weird console error :
Cannot call method 'Profile' of undefined
when I call this right after REST auth:
IN.API.Profile("me").fields(["id", "..."]).result(linkedin_connect_save);
Any ideas?
That console error doesn't have anything to do with authentication - I'm guessing you're loading another javascript framework which is interfering with the LinkedIn framework and the IN object isn't getting properly loaded.
The following page works with a key that I've previously authenticated using REST in the same browser here: http://developer.linkedinlabs.com/tutorials/testing.html
<html>
<head>
<title>Connections App Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body class="yui3-skin-sam yui-skin-sam">
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: MY_API_KEY
onLoad: loadData
authorize: true
</script>
<script type="text/javascript">
function loadData() {
IN.API.PeopleSearch()
.fields("firstName", "lastName", "distance", "publicProfileUrl","pictureUrl")
.params({"keywords": "princess", "count": 10, "sort": "distance"})
.result(function(result) {
alert(JSON.stringify(result));
});
}
</script>
</body>
</html>
your code might call before js load..
include js before ur code..

Resources