add utm source to outbound links
This commit is contained in:
		
					parent
					
						
							
								bf2b6b3ac4
							
						
					
				
			
			
				commit
				
					
						e8ec1a6ed4
					
				
			
		
					 1 changed files with 6 additions and 1 deletions
				
			
		| 
						 | 
					@ -1,9 +1,14 @@
 | 
				
			||||||
const {remote, shell} = require('electron')
 | 
					const {remote, shell} = require('electron')
 | 
				
			||||||
const path = require('path')
 | 
					const path = require('path')
 | 
				
			||||||
 | 
					const URL = require('url')
 | 
				
			||||||
const electronPath = path.relative(process.cwd(), remote.process.execPath)
 | 
					const electronPath = path.relative(process.cwd(), remote.process.execPath)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Array.from(document.querySelectorAll('a[href]')).forEach(link => {
 | 
					Array.from(document.querySelectorAll('a[href]')).forEach(link => {
 | 
				
			||||||
  const url = link.getAttribute('href')
 | 
					  // safely add `?utm_source=default_app
 | 
				
			||||||
 | 
					  let url = URL.parse(link.getAttribute('href'), true)
 | 
				
			||||||
 | 
					  url.query = Object.assign(url.query, {utm_source: 'default_app'})
 | 
				
			||||||
 | 
					  url = URL.format(url)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  link.addEventListener('click', (e) => {
 | 
					  link.addEventListener('click', (e) => {
 | 
				
			||||||
    e.preventDefault()
 | 
					    e.preventDefault()
 | 
				
			||||||
    shell.openExternal(url)
 | 
					    shell.openExternal(url)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue