1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Google Analytics feeder</ title >
6+ < script type ="text/javascript ">
7+
8+ function isAllowedOrigin ( origin ) {
9+ const allowedOrigins = [ "phtauri://localhost" , 'https://phtauri.localhost' , 'https://phcode.dev' ,
10+ 'https://dev.phcode.dev' , 'https://staging.phcode.dev' , 'https://create.phcode.dev' ] ;
11+ return origin . startsWith ( "http://localhost:" ) || allowedOrigins . includes ( origin ) ;
12+ }
13+
14+ // Get the gtag ID from the query string parameter named 'gtagID'
15+ const urlParams = new URLSearchParams ( window . location . search ) ;
16+ const analyticsID = urlParams . get ( 'analyticsID' ) || "G-VE5BXWJ0HF" ;
17+ if ( analyticsID && isAllowedOrigin ( location . origin ) ) {
18+ // for google analytics
19+ window . dataLayer = window . dataLayer || [ ] ;
20+ window . gtag = function ( ) { window . dataLayer . push ( arguments ) ; } ;
21+ let script = document . createElement ( 'script' ) ;
22+ script . type = 'text/javascript' ;
23+ script . async = true ;
24+ script . onload = function ( ) {
25+ gtag ( 'js' , new Date ( ) ) ;
26+
27+ gtag ( 'config' , analyticsID , {
28+ 'page_title' : 'Phoenix Analytics Feeder' ,
29+ 'page_path' : '/feeder.html' ,
30+ 'page_location' : window . location . origin
31+ } ) ;
32+ } ;
33+ script . src = 'https://www.googletagmanager.com/gtag/js?' + analyticsID ;
34+ document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( script ) ;
35+ } else {
36+ console . error ( "No analyticsID query string parameter. This page wont do any google analytics." ) ;
37+ }
38+
39+ window . addEventListener ( 'message' , function ( event ) {
40+ // Handle the received message here
41+ const sendEvent = event . data ;
42+ const origin = event . origin . toLowerCase ( ) ;
43+ // Check the origin to ensure that the message is from a trusted source
44+ if ( isAllowedOrigin ( origin ) ) {
45+ gtag ( 'event' , sendEvent . eventAct , {
46+ 'event_category' : sendEvent . category ,
47+ 'event_label' : sendEvent . label ,
48+ 'value' : sendEvent . count
49+ } ) ;
50+ }
51+ } ) ;
52+ </ script >
53+ </ head >
54+ < body >
55+ This page will be loaded in an iframe in tauri desktop builds to enable google analytics integration.
56+ This is because its almost impossible to run google analytics without an http or https url
57+ < a href ="https://www.simoahava.com/analytics/run-google-tag-manager-google-analytics-local-files/ "> For more details</ a > .
58+ </ body >
59+ </ html >
0 commit comments