What is getParameterByName in Firebase? - javascript

Firebase says that in the customize email action handler that they will implement getParameterByName. What does that exactly mean?

firebaser here
I'll assume you're referring to this page of the Firebase Authentication documentation, which contains the following code snippet:
// TODO: Implement getParameterByName()
// Get the action to complete.
var mode = getParameterByName('mode');
// Get the one-time code from the query parameter.
var actionCode = getParameterByName('oobCode'};
// (Optional) Get the API key from the query parameter.
var apiKey = getParameterByName('apiKey'};
Note that I only copied enough of the code to answer your question. Refer to the link for full code.
The custom email handler is an HTML page that is invoked by Firebase when there is an action that you may want to respond to. The Firebase back-end informs your page of the action and its data, by passing these as URL parameters when invoking your page.
So say you have your custom handler in a page called my_email_handler.html, it may invoked your page as: my_email_handler.html?mode=resetPassword&oobCode=123456&apiKey=AZdfshjsdfhj
The/your page then parses these URL parameters and takes the appropriate (custom) action.
The comment is a TODO for you as the application developer, you will need to implement a getParameterByName() method that retrieves the value from a URL parameter with the given name. If you do a search for getParameterByName you'll find quite some implementations of such a function.

Related

Sanitize url in an object rather than single url

I have an object having success, summary and detail elements used for displaying message in PrimeNG message (p-messages) after record is created. After record is created I call displayMessage method in order to set msg variable
form.ts:
...
this.displayMessage(data);
baseForm.ts:
displayMessage(data: string) {
var success = data["success"];
var summary = data["summary"];
var detail = data["detail"]; // name
this.msg.push({ success: success, summary: summary, detail: detail });
}
and then display message as shown below in html:
<p-messages [value]="msg"></p-messages>
However, the hyperlink tag “<a” is changed to “<a” and I think I need to sanitize the url by using something as explained on Angular 6 sanitize local drive url. Although I tried to use that method, I did not succeed because I need to sanitize the url in the detail variable and the related method is on the base class. So, how can I make the url display correctly? And what changes should be made in the given example?
You must tell primeNG not to escape the detail:
<p-messages [value]="msg" [escape]="false"></p-messages>

Obtain Adobe Marketing Cloud ID when Cookies not set previously using DTM?

I'm trying to figure out how to capture the Adobe Marketing Cloud ID (MID) when a page first loads using a Data Element (or by whatever alternative method will work). My Data Element logic works fine, if the Marketing Cloud cookie already exists. If there is no Marketing Cloud Cookie already existing, my data element reads the Marketing Cloud ID cookie as it is being written but the MID is not populated in the cookie at the time the Data Element reads it.
Is there any way I can access the value and report it in an eVar on the initial page load? I actually take the MID and combine it with an additional value to create the eVar value. As stated my code works unless the Marketing Cloud ID doesn't exist and has to be created during the page load.
You can use Visitor.getInstance() to get the Visitor instance, and then and then Visitor.getMarketingCloudVisitorID() to get the MC ID (what you see in the mid= param)
example:
var visitor = Visitor.getInstance("[mcorgid]#AdobeOrg")
s.eVar1 = visitor.getMarketingCloudVisitorID(); // set v2 with mid= value
If you implemented the MC ID service as a DTM tool, you can alternatively use _satellite.getVisitorId() instead of Visitor.getInstance(), e.g.:
s.eVar1 = _satellite.getVisitorId().getMarketingCloudVisitorID();
So for your Data Element, instead of doing a Cookie type (I assume that's what you did), you will need to use Custom Script type and return the value, e.g.
try {
return _satellite.getVisitorId().getMarketingCloudVisitorID();
} catch(e) {console.log(e);}
(Update) Alternatives
From your comment below (my bold for emphasis):
Just to be clear, this only happens to me on the first page when the
Marketing Cloud cookies don't exist. I do see the MID in the server
call.
Since you have confirmed that AA is getting an mid= value in its request, instead of trying to push the actual value of it to your eVar, you can pop it indirectly in other ways.
Dynamic Variables
dynamic variable syntax to reference the mid= param:
s.eVar1 = "D=mid";
Note: D= is the default dynamic variable prefix syntax. Check your AA tool config/other custom code to ensure it is not being set to something else.
Processing Rules
If you have access to create processing rules, you can setup a processing rule to set your eVar to mid= value there.

Google Tag Manager - read cookie just after they are set

I need to read cookie that are set by Google Tag Manager.
Right now if Google Tag Manager is loaded first time for end-user I can't read cookies (because it happens later, but not immediately).
Is there a good way (callback?) that can help me to read cookies once they are set? This issue is only relevant if user visits page first time.
From the discussion in the comments below the question, I would suggest the following solution (assuming you also send Pageviews to Google Analytics). Examples are based on Simo Ahava's (excellent) blog.
(Please note that I haven't had the opportunity to test it thoroughly, as I am currently unable to create a complete test case for this setup -- there might be some hiccups)
1. Create a Variable to read the _ga cookie
Reference: https://www.simoahava.com/analytics/macro-magic-google-tag-manager/#1-client-time
This will return the value for the cookie with name specified (be careful in where you use the value read, as there is always a chance that cookies are rejected by the User's browser policies).
Create a new Variable, with:
Variable Name of GA Cookie
Cookie Name of _ga
(source: simoahava.com)
2. Define a callBackFunction
Reference: https://www.simoahava.com/analytics/macro-magic-google-tag-manager/#8-hitcallback-with-a-universal-analytics-tag & https://www.simoahava.com/analytics/macro-magic-google-tag-manager/#6-get-clientid-using-_ga-cookie
This callback function will be executed right after the Pageview is sent (i.e. after the _ga cookie is set).
Create a Custom JavaScript Macro with the following code:
function () {
return function () {
// Code to be executed in order to read the cookie:
try {
var gaCookie = {{GA Cookie}};
// Do what you need to with the cookie here:
// ...
return gaCookie;
} catch (e) {
console.log('No Universal Analytics cookie found.');
return 'N/A';
}
}
}
3. Define a hitCallback after sending the Pageview
Reference: https://www.simoahava.com/analytics/macro-magic-google-tag-manager/#8-hitcallback-with-a-universal-analytics-tag
This will execute the callback function you just defined right after the Pageview is sent.
In the Fields to set option of your Pageview Tag, set:
Field Name to hitCallback
Value to {{callBackFunction}}
Hope it can help you move forward.

How do I post a tweet using javascript, twitter api and node.js?

Ok...I'm new to this >.<
I have my npm from github.com (node-twitterbot...whose dependency is twit)
I've looked at the twitter api..
What I'm trying to do is add an action which is post a tweet.
I can't seem to find out how to define the string for the actionName (which might be...)
var tweet = ("https://api.twitter.com/1.1/statuses/update.json");
and the actionFunction. Then I need to put it all together to post. Also, I have my instructions written below, however I'm not sure how to apply them. My actionName could be "tweet"? I have no idea how to define my actionFunction either...Can someone explain this? I NEED TO KNOW WHAT TO PUT WHERE. I have the twitterbot.js file open and ready to edit along with with all my oauth keys...access and consumer stuff. Please help anyway you can. I can paste my twitterbot.js file if that helps. Below are the instructions on the npm site reads:
Actions
In order to get your node-twitterbot to actually do something, you need to define actions. It is done through the addAction() method. It takes 2 parameters:
actionName: a string value for the name of an action
actionFunction: a function to be called when a given action is scheduled. (See below for method signature)
So our addAction method might look like this:
Bot.addAction("tweet", function(twitter, action, tweet) {
Bot.tweet("I'm posting a tweet!");
});
The twitter variable passed into the function is the Twit object associated with a given node-twitterbot, and can be managed directly. The same Twit object is available as [TwitterBot].twitter as well.
The action variable passed into the function is the TwitterBotAction created by addAction.
And the tweet object is the tweet passed into the action (if there was one)
TwitterBotActions
addAction() returns a TwitterBotAction object.
var tweetAction = Bot.addAction("tweet", function(twitter, action, tweet) {
Bot.tweet("I'm posting a tweet!");
});
But you will rarely need to directly hold onto the tweetAction directly. You can always get a reference to the action by calling
Bot.actionWithName("tweet");
Which will return the TwitterBotAction object, or null if the name is invalid (or the action already removed)
Again, I'm trying to put all of this together so i can post a tweet using the javascript in node.js Thank you for your time and consideration.

How do I catch an invalid API key for google maps

I have this code:
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=babab" type='text/javascript'></script>
If the key is invalid then it pops up an alert, but I want to perform some action in this case. I'm not sure how to hook into it though. Any ideas?
Google does not offer an external method of checking the Google Maps API key. Hence you cannot query some service with e.g. "Is this code valid abcde1234" and get a TRUE/FALSE response.
There is a discussion on how the Maps API key is generated. But I suggest you look at a post from Mike Williams about the GValidateKey function. This is the function actually doing the magic validation - what it exactly does, like creating a hash from your Google account / domain - we don't know.
I see two solutions for your problem of checking whether the API key provided is correct:
Overwrite the incoming alert with some custom code (check for the content of the alert, or check if an alert occurs withing X seconds after page load)
Somehow get the GValidateKey function to validate your key beforehand. Maybe you can call it before referencing the API Javascript? Sounds kind of hackish to me...
The problem you will likely have is that you don't know what Google actually checks. The referrer, the referring site, the host - many possibilities (it is not the IP address of the server, but the name plus some additional information).
I just ran across the need to perform an action if an invalid API key was used. Google's documentation states:
If you want to programmatically detect an authentication failure (for example to automatically send an beacon) you can prepare a callback function. If the following global function is defined it will be called when the authentication fails.
This was all I needed to do:
function gm_authFailure() { // Perform action(s) }
For modern browsers (IE9+ and others) you may use DOMNodeRemoved event. You just need to add event handler to the element that you pass to the map constructor:
var map = new google.maps.Map(element, myOptions);
element.addEventListener("DOMNodeRemoved", function(e){
if (e.target === element){
//your code here
element.removeEventListener("DOMNodeRemoved", mapWasRemovedHandler, true);
}
}, false);

Categories

Resources