How to test connection. JS script?

Good day!

All probably have seen many web services, such as Analytics, advertising, etc it is possible to obtain the js code to embed on the page and a button to check if it is installed on the site, and correctly or not.

Actually how is it done?
Of own options entail, for example, a php script that gets the page using file_get_contents (or curl), and then simply searches it for a pattern. Then this php script is served via js ajax url for validation and the results are displayed.

But what if the code zukommenden?
The website will show that all is installed successfully, but in practice it is not.

Are there other options?
Preferably with code examples.
July 2nd 19 at 18:04
2 answers
July 2nd 19 at 18:06
Solution
Ship website in phantomjs.org or analogues and look at your server, did us a request with a specific identifier that must be different for each site which give code in the box.
July 2nd 19 at 18:08
Solution
When the script installed on the website it automatically gives the server the http referer via php, you can check the referrer for your domain and set the database key (active / inactive) and time of last response, and not to forget the key to change the fase when the response was not a long time.
js can be in php, it all depends on the settings .htaccess

Find more questions by tags PHPJavaScript