Migrating _setDomainName from Classic to Google Analytics 4 - google-analytics-4

I am migrating to Google Analytic 4 and I have the legacy code below.
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXX']);
_gaq.push(['_setDomainName', 'none'])
I am looking to replace _gaq.push(['_setDomainName', 'none']) I have tried below code and is
resulting in error. I have looked all over the internet without success any suggestion will help.
function gtag(){
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-XXXX');
gtag('_setDomainName', 'none');

Related

Where do I find the JavaScript API docs for window.IPython.*?

I wanted to be able to paste an image from the clipboard into IPython.
Being new to Python, but having solved this problem before in web-apps, I hacked a solution using JavaScript after spending a lot of time poking around in Firefox's inspector.
I found window.IPython and used trial-and-error to guess at which functions to avoid too much DOM hacking. I tried looking for documentation for the JS API but couldn't find anything.
Is there documentation for the IPython/Jupyter JS API somewhere?
Code FYI. Draft only but good enough for me. Use in your own notebooks at your own peril:
%%javascript
// remove the paste listener if it already exists
if (window.paste_listener)
{
window.removeEventListener('paste',window.paste_listener);
}
// (re)declare the paste listener
window.paste_listener = function(event)
{
if (event instanceof ClipboardEvent)
{
var file = event.clipboardData.items[0].getAsFile();
if (file && file.type.substr(0,6) == "image/")
{
var reader = new FileReader();
reader.onloadend = function() {
var cell = IPython.notebook.insert_cell_below('code');
cell.set_text("%%html\n<img src='" + reader.result + "' />");
cell.execute();
};
reader.readAsDataURL(file);
}
}
}
// and add it
window.addEventListener('paste', window.paste_listener);

Calling a plug-in via an add-on

Scenario:
I have developed an firefox add-on. I want my add-on to call another plug-in present in firefox.
Problem:
I am not able to figure it out how the plug-in can be called. In chrome, extensions can call plug-in by message passing. Can message passing can be used for firefox add-on.If it can be done can anyone provide guidance.
Following is the code:
Here is main.js file:
var {data} = require("sdk/self");
var pageMod = require("sdk/page-mod");
pageMod.PageMod({
include: "*",
attachTo: ["top"],
contentScriptFile: [data.url("jquery-2.1.0.js"),data.url("cwic.js"), data.url("my- script.js")]
});
and Here is the my_script.js file:
//MAIN REGEX
var regex = /\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/g;
var text = $("body:first").html();
var textNodes = $("body:first").find('*').contents().filter(function(){
if(this.nodeType == 3 && regex.test(this.nodeValue) && this.parentElement.tagName !== "A"){
var anchor = document.createElement('a');
//alert(this.nodeValue.match(regex)[0]);
//anchor.setAttribute('href', this.nodeValue);
anchor.setAttribute('href', this.nodeValue.match(regex)[0]);
anchor.appendChild(document.createTextNode(this.nodeValue.match(regex)[0]));
//alert(this.nodeValue.match(regex));
if(this.nextSibling)
this.parentElement.insertBefore(anchor, this.nextSibling);
else
this.parentElement.appendChild(anchor);
this.nodeValue = this.nodeValue.replace(regex, '');
}
return this.nodeType === 3;
});
$('a').click(function() {
// When user clicks on the number it should call another plug-in to initiate communication
});
grab the window and use chromeWindow.gBrowser.selectedTab.linkedBrowser.contentWindow.wrappedJSObject.$
the wrappedJSObject gives you access to all the js in that window

Google Analytics Realtime report shows no data for GWT Application

I've just created an account to use to track my GWT application and in the process of adding tracking code so I'm looking for some real time feedback on if any of my tracking code is working properly. My application is not public (deployed on my local machine with firewalls), and I haven't seen any javascripts error after adding the tracking code. However when I hit my website on my machine there's no indication in the realtime report that there's an active user, page viewed or any data at all. In my application html I have:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'Account number']);//I have real account number in my project
_gaq.push(['_setSiteSpeedSampleRate', 0]);
_gaq.push(['_trackPageView', 'name']);
(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>
which should at least set up page views tracking for me.
I'm assuming that Google Analytics don't need access to my website since I'm the one sending. However I'm new to both GWT and Google Analytics so I could be completely wrong. Please help!
Try replacing this line:
_gaq.push(['_trackPageView', 'name']);
by this one:
_gaq.push(['_trackPageview', 'name']);
Note the lowercase "v" in _trackPageview. Method names are case-sensitive (reference).

can't tap on item in google autocomplete list on mobile

I'm making a mobile-app using Phonegap and HTML. Now I'm using the google maps/places autocomplete feature. The problem is: if I run it in my browser on my computer everything works fine and I choose a suggestion to use out of the autocomplete list - if I deploy it on my mobile I still get suggestions but I'm not able to tap one. It seems the "suggestion-overlay" is just ignored and I can tap on the page. Is there a possibility to put focus on the list of suggestions or something that way ?
Hope someone can help me. Thanks in advance.
There is indeed a conflict with FastClick and PAC. I found that I needed to add the needsclick class to both the pac-item and all its children.
$(document).on({
'DOMNodeInserted': function() {
$('.pac-item, .pac-item span', this).addClass('needsclick');
}
}, '.pac-container');
There is currently a pull request on github, but this hasn't been merged yet.
However, you can simply use this patched version of fastclick.
The patch adds the excludeNode option which let's you exclude DOM nodes handled by fastclick via regex. This is how I used it to make google autocomplete work with fastclick:
FastClick.attach(document.body, {
excludeNode: '^pac-'
});
This reply may be too late. But might be helpful for others.
I had the same issue and after debugging for hours, I found out this issue was because of adding "FastClick" library. After removing this, it worked as usual.
So for having fastClick and google suggestions, I have added this code in geo autocomplete
jQuery.fn.addGeoComplete = function(e){
var input = this;
$(input).attr("autocomplete" , "off");
var id = input.attr("id");
$(input).on("keypress", function(e){
var input = this;
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(37.2555, -121.9245),
new google.maps.LatLng(37.2555, -121.9245));
var options = {
bounds: defaultBounds,
mapkey: "xxx"
};
//Fix for fastclick issue
var g_autocomplete = $("body > .pac-container").filter(":visible");
g_autocomplete.bind('DOMNodeInserted DOMNodeRemoved', function(event) {
$(".pac-item", this).addClass("needsclick");
});
//End of fix
autocomplete = new google.maps.places.Autocomplete(document.getElementById(id), options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
//Handle place selection
});
});
}
if you are using Framework 7, it has a custom implementation of FastClicks. Instead of the needsclick class, F7 has no-fastclick. The function below is how it is implemented in F7:
function targetNeedsFastClick(el) {
var $el = $(el);
if (el.nodeName.toLowerCase() === 'input' && el.type === 'file') return false;
if ($el.hasClass('no-fastclick') || $el.parents('.no-fastclick').length > 0) return false;
return true;
}
So as suggested in other comments, you will only have to add the .no-fastclick class to .pac-item and in all its children
I was having the same problem,
I realized what the problem was that probably the focusout event of pac-container happens before the tap event of the pac-item (only in phonegap built-in browser).
The only way I could solve this, is to add padding-bottom to the input when it is focused and change the top attribute of the pac-container, so that the pac-container resides within the borders of the input.
Therefore when user clicks on item in list the focusout event is not fired.
It's dirty, but it works
worked perfectly for me :
$(document).on({
'DOMNodeInserted': function() {
$('.pac-item, .pac-item span', this).addClass('needsclick');
}
}, '.pac-container');
Configuration: Cordova / iOS iphone 5

YUI AutoComplete Example Problem

I was hunting for an implementations of YUI AutoComplete and I came across this script from the site asklaila.com -
<script type="text/JavaScript">
YAHOO.example.ACJson = new function() {
this.oACDS = new YAHOO.widget.DS_XHR("/AutoComplete.do",
["Suggestions[0].Results","Name"]);
this.oACDS.queryMatchContains = true;
this.oACDS.scriptQueryAppend = "city=Mysore"; // Needed for YWS
function fnCallback(e, args) {
document.searchForm.where.focus();
acSelected = true;
return false;
}
this.oAutoComp = new YAHOO.widget.AutoComplete('what','whatContainer', this.oACDS);
this.oAutoComp.itemSelectEvent.subscribe(fnCallback);
this.oAutoComp.formatResult = function (oResultItem,sQuery) {
return oResultItem[0];
}
this.oAutoComp.queryDelay = 0;
this.oAutoComp.useIFrame = true;
this.oAutoComp.prehighlightClassName = "yui-ac-prehighlight";
this.oAutoComp.minQueryLength = 2;
this.oAutoComp.autoHighlight = false;
this.oAutoComp.textboxFocusEvent.subscribe(function() {
this.oAutoComp.sendQuery("");
});
this.oAutoComp.doBeforeExpandContainer = function(oTextbox, oContainer, sQuery, aResults) {
var pos = YAHOO.util.Dom.getXY(oTextbox);
pos[1] += YAHOO.util.Dom.get(oTextbox).offsetHeight + 2;
YAHOO.util.Dom.setXY(oContainer,pos);
return true;
};
}
</script>
It is implenting the YUI AutoComplete Dropdown. What I want to understand is what this
this.oACDS = new YAHOO.widget.DS_XHR("/AutoComplete.do", ["Suggestions[0].Results","Name"]);
does and its effects on code.
That's using an older version of YUI, but it is setting up a DataSource for the autocomplete to read from. This particular DataSource uses XHR to request information from the server to populate the autocomplete field.
"Autocomplete.do"
Is a relative URL that is being queried by the DataSource every time the autocomplete fires while the user is typing.
["Suggestions[0].Results","Name"]
Is the responseSchema that tells the DataSource how to parse the results from the request to the URL. It needs to know how to parse the data so that it can show the proper results.
this.oACDS = new YAHOO.widget.DS_XHR("/AutoComplete.do", ["Suggestions[0].Results","Name"]);
On every key press, it fetches a json response from the server, and uses it to populate the autocomplete dropdown. The json contains names to display only at this node, "Suggestions[0].Results" in the "name" field.
If you have any trouble, ask ahead. I wrote that piece of code for asklaila.com
I was hunting for implementations of
YUI Autocomplete and I came across
this script...
Why not take a look at YUI AutoComplete page for in-depth examples.
Yahoo! UI Library: AutoComplete