JavaScript | ColdFusion - Facebook pixel - javascript

I'm trying to trigger my Facebook pixel.
This is the problem:
I have my own image pixel installed in a client website, when my pixel is triggered in the client website it sends a request to my server which after some inserts in a db I redirect the request to CFML page (HTML for ColdFusion) which has the pixel code from Facebook like below:
<script>
// Facebok Pixel Init Code
fbq('init', 'PIXEL_ID');
fbq('trackCustom', 'myCustomEvent', {});
</script>
<noscript>
<img src="THE_FB_URL/?id=PIXEL_ID&ev=myCustomEvent&noscript=1">
</noscript>
When I directly access the page via a browser it triggers the pixel successfully and I can see it in the Facebook pixel report. But when the request is redirected to the page after the insert to the db the pixel does not trigger.
I think its because the JavaScript and HTML is never added to the DOM so it never gets executed...
Do you know how can I achieve this?
I think if maybe I send an HTTP GET request to the <img> tag URL hopefully the Facebook accepts it..
UPDATE
So this is what happens, the request I send triggers the event, but #Jules is right. I can't find which ad led to a conversion using this method, the problem is that where pushing traffic to our clients website, in which we can't install any JavaScript code.
I tried to check what cookies Facebook stores so when I make the GET request I send those values too, but this happens:
1 - The ad sends the user to a link like this:
l.facebook.com/l.php?u=redirect_url&h=some_token_here
In this page I can check that there is some cookies (I assume these are the values Facebook needs to find which ad led to a conversion)
2 - Then the user is redirected to our clients form page
I tried to check the cookies here too but the cookies don't seem to exist..
I need help people!

So guys,
I made it work this way:
Instead of using CFLOCATION to redirect the request to the CFML page where the Facebook JS snippet is, I directly use CFHTTP to request the Facebook Tracking URL. Like so:
<cfif #source# eq 'facebook'>
<cfhttpparam type="url" name="id" value="PIXEL_ID">
<cfhttpparam type="url" name="ev" value="myCustomEvent">
<cfhttpparam type="url" name="noscript" value="1">
</cfif>
It worked! :)

Based on your comments, the below might work. You'll exploit the noscript image tag.
I think what you want to return with CFML is a CFLocation to the proper FB pixel URL - rather than cfhttp loading it. This way the client still loads the FB pixel, and you still track it's loading in between.
The browser loads
<img src="//your-server.net/trackPixel.cfm?some_vars=some_vals">
That CFML does...
<!--- DO YOUR STORAGE AND OTHER LOGIC --->
<cfquery>...</cfquery>
<!--- THEN REDIRECT --->
<cflocation url="the_official_fb_image_url.gif" addToken="no">
So when the user's browser loads your cfm as an image, reply is to load a different image.

You should not write HTML/Javascript code.
The first conversion pixel is called via an img tag so you cannot respond with HTML/Javascript.
All you have to do is return a redirect (301) to your final image pixel. In this case:
Redirect 301 THE_FB_URL/?id=PIXEL_ID&ev=myCustomEvent&noscript=1

If you're using CFlocation then no, the scripts will not fire. Instead use a javascript relocation. Give the browser enough time to load the page and fire off the script. Something like so:
<script>
fbq('init', 'PIXEL_ID');
fbq('trackCustom', 'myCustomEvent', {});
setTimeout(
function(){
window.location.href='';
// or simply: history.go(-1);
},
3000
);
</script>
<noscript>
<img src="THE_FB_URL/?id=PIXEL_ID&ev=myCustomEvent&noscript=1">
</noscript>

Related

Untraceable HTTP redirection?

I'm currently working on a project to track products from several websites. I use a python scraper to retrieve all the URLs related to the listed products, and later, regularly check if these URLs are still active.
To do so I use the Python requests module, run a get request and look at the response's status code. Usually I get 200, 301, 302 or 404 as expected, except in the following case:
http://www.sephora.fr/Parfum/Parfum-Femme/Totem-Orange-Eau-de-Toilette/P2232006
This product has been removed and while opening the link (sorry it's in French), I am briefly shown a placeholder page saying the product is not available anymore and then redirected to the home page (www.sephora.fr).
Oddly, Python still returns a 200 status code and so do various redirect tracers such as wheregoes.com or redirectdetective.com. The worst part is that the response URL still is the original, so I can't even trace it that way.
When analyzing with Chrome DevTools and preserving the logs, I see that at some point the page is reloaded. However I'm unable to find out where.
I'm guessing this is done client-side via Javascript, but I'm not quite sure how. Furthermore, I'd really need to be able to detect this change from within Python.
As a reference, here's a link to a working product:
http://www.sephora.fr/Parfum/Parfum-Femme/Kenzo-Jeu-d-Amour-Eau-de-Parfum/P1894014
Any leads?
Thank you !
Ludwig
The page has a meta tag, that redirects the page to the root URL:
<meta http-equiv="refresh" content="0; URL=/" />

Put 2 Links on Background Image HTML Mail Message

I need two pages to be open at once when the user clicks on an image that is being sent in an email message.
I tried to use window.open but when the message is sent to the recipient the link on the image does not work.
Could you help me or tell me a better way to make this possible??
The code:
<img width="500" align="center" src="img_1">
Within email app, it's not possible. As Quentin mentioned above, all of the email consumption software, including Outlook, webmail and iPhone native email app will block your JavaScript in the message.
However, in theory, the result could be achieved using an intermediary landing page, which would perform the all the JS you need, opening two tabs.
I once had a similar project where we implemented intermediary landing page that sniffed the user agent and redirected to the deep-linked mobile website or a different desktop landing page. For example, you would link to your landing page like:
http://yourlandingpage.com?tab1toopen=http://page1.com&tab2toopen=http://page2.com
This raises new issues around:
* URL tracking (and automating encoding and/or optional URL shortening and admin of all of this),
* URL length (which is limited on Windows desktop Outlook clients),
* security of that landing page (lander should sanitize the strings, maybe even do some secret hand-shaking via unique encrypted var), and,
* can it sustain the heavy traffic (which is larger problem that it appears if you work with big brands).
Due to major security issues, scripting is not available in emails. Many clients will strip the scripting completely while others can mark it as spam or block it entirely.
Your best bet would be to have it link to a static landing page that then runs a script to open the two windows for you.
http://javascript.about.com/od/reference/a/jsemail.htm
Some other good sources on what is allowed and not allowed in HTML email:
http://kb.mailchimp.com/campaigns/design/limitations-of-html-email
http://kb.mailchimp.com/templates/code/common-html-mistakes
https://www.campaignmonitor.com/dev-resources/guides/coding/
How about this?
HTML
<img width="500" align="center" src="img_1">
JS
<script type="text/javascript">
function DoThis() {
window.open('http://www.foo.com', _blank); //open link 1 in new tab
window.open('http://www.g1.com.br', _blank); //open link 2 in new tab
}
</script>

How to get data from an external site inside a cordova application?

Scenario:
I've an application made in angularJS and ionic for cordova 3.5
This application loads trough an iframe a web to make some things with a step by step form. This web is on other site.
The code for the html is:
<div id="IframeContainer">
<iframe src="URL" style="width:100%;height:90%" onLoad="checkforclose(this);"></iframe>
</div>
This step-by-step form returns a result that the cordova application needs to know what happens in the form. It can return a json, a text/plain or even an HTML that auto-post to another site (This is linked with this non-answered question: Post and redirect FROM Web Api)
Said this, in my cordova application I've a javascript function in order to close the iframe and take over again the control of my application, detecting if the url contains the word "close". This is the code:
<script type="text/javascript">
function checkforclose(pageURL) {
var urlFrame = pageURL.contentWindow.location;
if (urlFrame.href.indexOf('close') > -1) {
window.location = "#/employees/";
}
}
</script>
Question:
Trying avoid CORS (So I think I can't read the iframe content on load, or I'm wrong?),
without using jQuery (AngularJS is welcome, plain javascript even more)
Taking over the control again to the application
How can I get the data returned by the step-by-step external form?
UPDATE 1:
I tried coding a "onload" reading (CORS errors), and posting to a cordova-html page, but without any respectable result.
A possible solution is Web messaging or cross-document messaging. Here's a blog post where someone used this method to gain access to a mobile device's camera from an external page loaded in an iframe. Although this person had the opposite goal (get data from Cordova to page loaded in iframe), they were able to accomplish cross domain communication between a page in an iframe and Cordova; which is what I believe you are trying to do.

Javascript redirection / domain specify

I found an nice script while searching and inspecting the elements of some websites.
This is what I have found:
<script type="text/javascript">
//redirect browser to fullscreen preview
if (/^http:\/\/codecanyon\.net/.test(document.referrer))
window.top.location.href = 'http://www.gravitysign.com/backslider/';
</script>
So if I understood from this script it tells jquery if the website is opened over codecanyon redirect them to specifed website for preview.
Now... I was wondering if there is possibility to make something like this.
If we specify an website for example http://google.com and we input that into javascript... And then if that website is uploaded to any other domain, other then google.com ... It will redirect to specified site (google) ?
So to clear things out a little bit let me make an example.
If I made a website for "an-website.com" and then someone take their website and upload it to "another-website.com", it will automatically redirect all visitors from another-website.com to an-website.com.
Hope I was clear enough and hope that this is possible. Cheers!
You can of course redirect any user accessing your site from a domain not matching yours but using javascript. This should work just fine:
if (window.location.hostname !== 'yourdomain.com'){
window.top.location.href = 'http://yourdomain.com';
}
You can also use match, if you host your site on a subdomain, etc.
Keep in mind that any person with write access to the file on the server will be able to remove this "copy protection". Copy protecting client side content is impossible, as you need to serve the content in a way a browser understands, effectively making the content available to anyone.
If you are looking for solution for single domain protection, here you can see my
Redirect Website if its not specified domain in script - Protection using Javascript
I am looking for solution for multiple domain.

Can I use Javascript to get a web page Without the use of XMLHttpRequest or document object?

web server send HTML(1) ---> Browser get the HTML(1) ---> script engine starts to work and so on..
I need to get a HTML(1) in my project.
'XMLHttpRequest.responseText' can do it. I think it's great!
But it have to make an another request.
And 'document.getElementsByTagName()' return a rendered HTML. It's not that I want.
we can see the HTML(1) in 'script' tab on IE developer tool.(not 'html' tab)
Then I guess that it could be possible to get HTML(1) without another request.
Is there any way to get the HTML(1) with javascript?
Added-----------------------------
there is sample.html
&ltscript&gt
document.write('AAAAAA');
&lt/script&gt
&ltbody&gt
body content
&lt/body&gt
document.getElementsByTagName('html') return like following.
&ltscript&gt
document.write('AAAAAA');
&lt/script&gt
&ltbody&gt
AAAAAAbody content
&lt/body&gt
But I need... pure source of the web page
If you want to get the current page as a string use document.documentElement.innerHTML
I don't think browsers actually keep the original HTML which was sent by web server, because if you try to view a page source the browser actually makes a request to the server.

Categories