Reputation: 474
I'm trying to find a solution to fire a pixel from Safari browser on iPhone
Here is my scenario:
I have a Web Site (not an native app) that needs to fire a pixel to a third party 10 seconds after clicking submit button (currently I'm using JavaScript ).
The problem is that when leaving to another App, the JavaScript stops running, therefore the pixel is not fired.
Is there any other way to trigger the pixel?
Upvotes: 0
Views: 1526
Reputation: 3043
Your question has no reasonable solution that can be implemented on the browser. This is due to (and you covered this already) the fact that mobile safari simply will not execute anything after a being backgrounded. Therefore you either need a 10s loading screen, which might tank conversion, or something like the following hack/last-resort:
1) Detect if you are on mobile
2) Make a pixel request to your server instead, along with the initial submit (or even piggy-back it off of the submit)
3) Create a callback on your server side code, with a delay of 10 seconds, then forward the request (headers and all) to the third party. This would have to include at the very least user-agent and IP. Depending on your server-side language, spoofing an IP may be difficult.
Drawbacks:
More code, and this is exceptionally brittle. I'm not saying this is a pretty solution by any means. Also, you will lose any cookie information the pixel would have sent to the third party since the pixel is presumably hosted on a domain that you do not control. If the third party's implementation requires cookie info in the request, this work around will not work. Also, any third party pixel-specific data like ETags on the pixel will not be passed.
Given that you are trying to circumvent a basic behavior (a.k.a. not executing javascript while in the background) of mobile safari, however, I don't see any options for doing this on the client with any reliability. Your other option is to set a cookie on your domain and the next time they load one of your pages, fire the pixel. This presupposes that the user will re-visit your page, which depending on your users may or may not happen with any frequency.
Upvotes: 0
Reputation: 3583
There is no way to do it in mobile browsers. The only thing I can think of is detecting you are on a mobile and only then trigger the gif on submit. If it must be after 10 seconds then maybe fire it from the server, faking the data sent in the request of the gif .
Upvotes: 1
Reputation: 14526
If I understand your problem, I think you have only two options:
The problem is that Mobile Safari puts tabs to sleep completely when they are not active. I believe that they go to sleep immediately (unlike a native webview, where you have two seconds to shut down your app and do any housekeeping you need to do before the app "resigns".)
Upvotes: 0