How detect when received a notification - angularjs

I need know the function to detect the notifications. I can send and receive notifications, but i need a function to detect when receive the notification.

The notificationOpenedCallback will fire when a notification is either opened or if one is received while the app is in focus. Example below.
var notificationOpenedCallback = function(jsonData) {
console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
};
window.plugins.OneSignal.init("b2f7f966-d8cc-11e4-bed1-df8f05be55ba",
{googleProjectNumber: "703322744261"},
notificationOpenedCallback);
There isn't an event for when a notification is receive in the background through Corodva. You will need to use native code for this by setting up a NotificationExtenderService in Java by following the OneSignal Background Data and Notification Overriding documentation for Android. For iOS set content_available to true and setup a
- application:didReceiveRemoteNotification:fetchCompletionHandler: selector.

Related

GA4 Google Analytics event doesn't appear as conversion

I'm using Google Tag Manager(react-gtm-module) package) to push custom events to Google Analytics. In code i do it like this:
GTM.dataLayer({ dataLayer: { event: 'Custom event' } });
Then, in GTM i have trigger for this Custom event (event name is the same everywhere) and tag which sends event to Google Analytics. Then in GA i marked that event as conversion, but when i trigger that event on website it shows up as regular event but not as conversion.
This works perfect for every other event but not for this one. I tried to rename event and mark new event as conversion but it didn't help.
Could anyone by any chance know the reason why it doesn't work as expected only for this event?
I am not sure follow the actual issue you are having but you're missing a ' in your code after the event name
this
GTM.dataLayer({ dataLayer: { event: 'Custom event } });
should change to
GTM.dataLayer({ dataLayer: { event: 'Custom event' } });
Otherwise, are you saying that you are specifically using the string "Custom event" as the event parameter value? Perhaps that is a reserved value in the system used for something else, but it seems unlikely.

How can I prevent hammerspoon hotkeys from overriding hotkeys in other applications?

I'm looking at having a certain hotkey only available in Google Chrome:
hs.hotkey.bind({"cmd"}, "0", function()
if hs.window.focusedWindow():application():name() == 'Google Chrome' then
hs.eventtap.keyStrokes("000000000000000000")
end
end)
The issue with this approach is the hotkey will become un-usable on other apps. E.g. CMD+0 will not trigger the Reset Zoom command in Discord.
How can I prevent that?
The hs.hotkey API doesn't provide functionality to be able to propagate the captured keydown event. The hs.eventtap API does, but using it would involve watching for every keyDown event.
I'll point to what is mentioned in a somewhat related GitHub issue:
If you're wanting the key combo to do something for most applications, but not for a few specific ones, you're better off using a window filter or application watcher and enabling/disabling the hotkey(s) when the active application changes.
In other words, for what you're trying to achieve, it's recommended you use the hs.window.filter API to enable the hotkey binding when entering the application, and disable it when leaving the application, i.e. something like:
-- Create a new hotkey
local yourHotkey = hs.hotkey.new({ "cmd" }, "0", function()
hs.eventtap.keyStrokes("000000000000000000")
end)
-- Initialize a Google Chrome window filter
local GoogleChromeWF = hs.window.filter.new("Google Chrome")
-- Subscribe to when your Google Chrome window is focused and unfocused
GoogleChromeWF
:subscribe(hs.window.filter.windowFocused, function()
-- Enable hotkey in Google Chrome
yourHotkey:enable()
end)
:subscribe(hs.window.filter.windowUnfocused, function()
-- Disable hotkey when focusing out of Google Chrome
yourHotkey:disable()
end)

Ionic Background to Foreground using Local Notification

First sorry for my bad English.
I'm new on Ionic and I'm trying to pass my app from background to foreground when local notification trigger. I'm using the Katzer API (https://github.com/katzer/cordova-plugin-local-notifications), and I want to show a view (skype style incoming call) for stop or postpone a notification. This example works ok, but I need a method or something in order to show the postpone screen even when the screen is locked.
cordova.plugins.notification.local.on('trigger', function (notification) {
alert("triggered");
}
Thanks in advance.
After more deeper researching I managed to do it, so I'll answer to myself and leave it here for anybody who needs it.
If you want to show your application in foreground when the notification is triggered you should modify the AbstractTriggerReceiver.java
I added this method in AbstractTriggerReceiver.java:
public void launchApp() {
Context context = getContextForApp();
String pkgName = context.getPackageName();
Intent intent = context
.getPackageManager()
.getLaunchIntentForPackage(pkgName);
intent.addFlags(
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
So in your TriggerReceiver.java you can call launchApp(); in your onTrigger() method.
There isn't an easy solution for this, since you need to work mainly in the native layer.
E.g. In Android you should create an activity visible over the default lock screen, show it when the notification is triggered and start the Cordova activity on a button click.

Trigger Google Analytics pageview for Angular App while using Google Tag Manager

I am building a SPA using Angular.js. We use Google Tag Manager to load in most of our analytics/marketing scripts, which includes Google Analytics. I am also using ui-router to manage states/views.
I would like to send pageview events off to Google Analytics whenever a user browses to a different state in my app. Part of the complexity in doing this with GTM is that GTM creates a named tracker. That means that all GA events need be prepended with the tracker name. That would usually look like this:
ga('trackerName.send', 'pageview', {page: '/a/path/', title: 'A Title'});
GTM uses a randomly generated tracker name, so the tracker name needs to be grabbed at runtime. That can be done fairly simply with GA's getAll function. If you want to send the pageview event to all trackers, you would simply do:
var allTrackers = ga.getAll();
for(var i=0; i<allTrackers.length; i++) {
ga.send(allTrackers[i].getName()+".send", "pageview", {page: '/a/path', title: 'A Title'});
}
This works great for most of my pageview events. However, there is a race condition between when ui-router fires the initial view's $stateChangeSuccess (which is where I trigger the GA pageview), and when analytics.js is loaded.
Prior to analytics.js being loaded, Google Analytic's snippet creates a faux ga object, that you can send events to. This faux object does not have the rest of the ga functions on it, so you can not run getAll. Without the getAll function, I cannot get the tracker name and I cannot send pageview events.
As far as I can tell, Google Analytics does not provide any callbacks or events for when analytics.js is finished loading, so there is no way to tell when I will be able to start sending events. Right now I am using an $interval to check for the existence of ga.getAll, but that is not a very performant or ideal solution. This is what I've got:
gaCheckInterval = setInterval(function() {
if(typeof(ga) !== 'undefined' && typeof(ga.getAll) == 'function') {
clearInterval(gaCheckInterval);
sendBackloggedEvents();
}
}, 200);
Is there any other way to recognize when analytics.js has finished loading? Or any other way to send events to a named tracker, without having access to getAll?
Attempting to configure and trigger individual trackers circumvents the purpose of using a tag manager. Instead do:
dataLayer.push({event:'spa.pageView', page:..., title:...});
Where:
dataLayer is optionally renamed in the gtm snippet
spa is a handy abbreviation for your app/project/company/whatever in case you need to distinguish its actions later.
page and title can be whatever you like, you will reference them by adding dataLayer macros in your GTM container.
Then, in the tag manager you configure:
rule of {{event}} ends with pageView.
dataLayer macros for the page, title you are pushing into the dataLayer.
UA Tag (and later whatever else) to fire (1) and use the macros in (2) for the TAG parameters they override.
Repeat (3) as many times as you like for different UA properties with additional blocking rules, alternate macros or more granular firing rules as necessary.
Now you can configure the specifics and add other tag types that reuse the rules and macros without modifying the application for each change.

How can I tame multiple event listeners in a Fennec extension?

I'm trying to write a restartless add-on for Firefox Mobile that will insert content onto specific web pages. It all seems to work OK until I try disabling then re-enabling the add-on, at which point I get multiple responses to the page load event, and I can't figure out a way to sort them out.
Since Fennec uses the Electrolysis multi-process platform, I know that I need to split my code into chrome and content scripts. My bootstrap.js looks something like this (trimmed for clarity):
function startup(data, reason) {
mm = Cc["#mozilla.org/globalmessagemanager;1"].getService(Ci.nsIChromeFrameMessageManager);
mm.loadFrameScript(getResourceURISpec('content.js'), true);
}
function shutdown(data, reason) {
let mm = Cc["#mozilla.org/globalmessagemanager;1"].getService(Ci.nsIChromeFrameMessageManager);
mm.sendAsyncMessage("GeoMapEnh:Disable", {reason: reason});
}
function install(data, reason) {}
function uninstall(data, reason) {}
Basically, the bootstrap.js just launches a content script, and sends a message to tell it to clean up on shutdown. The content.js sets up an eventListener to watch for page loads, that looks a bit like this:
addMessageListener("GeoMapEnh:Disable", disableScript);
addEventListener("DOMContentLoaded", loadHandler, false );
function loadHandler(e) {
LOG("Page loaded");
// Do something cool with the web page.
}
function disableScript(aMessage) {
if (aMessage.name != "GeoMapEnh:Disable") {
return;
}
LOG("Disabling content script: " + aMessage.json.reason);
try {
removeEventListener("DOMContentLoaded", loadHandler, false );
removeMessageListener("GeoMapEnh:Disable", disableScript);
} catch(e) {
LOG("Remove failed: " + e);
}
}
function LOG(msg) {
dump(msg + "\n");
var consoleService = Cc["#mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
consoleService.logStringMessage(msg);
}
When I first run the extension, everything works fine. An instance of content.js is executed for each browser tab (and any new tabs I open) and my eventListener detects the page loads it is supposed to via the DOMContentLoaded event. When I disable the extension, everything still seems OK: page loads stop being detected.
When I re-enable the extension, it all goes wrong. I still get an instance of content.js executing for each open tab, but now, if I open new tabs, DOMContentLoaded triggers mutiple eventListeners and I can't distinguish which one should handle the event. Worse yet, some of the eventListeners are active, but do not give debug info via my LOG function, and do not all of them get removed if I disable the extension a second time.
I do want to watch all browser tabs, including any new ones, but I only want my extension to insert content on the page that triggers it, and only once per page load. I've tried the following without success:
Calling e.stopPropagation() to stop the event being passed to other listeners. No effect.
Calling e.preventDefault() and testing e.defaultPrevented to see if the event has already been handled. It never has.
Testing if (this === content.document) to see if the eventListener has been triggered by its own page content. Doesn't work, as I get multiple "true" responses.
Making the eventListener capturing. No effect.
Using the load event rather than DOMContentLoaded.
I can't set a shared variable to say the event has been handled as under Electrolysis, the different eventListeners will be executing in different contexts. Also, I wouldn't be able to distinguish between multiple tabs loading the same page and one page load being detected multiple times. I could do this via IPC message passing back to the chrome bootstrap script, but I then I wouldn't know how to address the response back to the correct browser tab.
Any ideas? Is this a Firefox bug, or am I doing something silly in my code? I am using Fennec Desktop v4 for development, and will target Fennec Android v6 for production.

Resources