This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let propertyId = '<<ENTER YOUR PROPERTY ID HERE>>'; | |
| // Get the day 31 days ago | |
| let today = new Date().getTime() - (60 * 60 * 24 * 31 * 1000); | |
| // Get the day, month and year | |
| let day = new Date(today).getDate(); | |
| let month = new Date(today).getMonth() + 1; | |
| let year = new Date(today).getFullYear(); | |
| // Put it in Google's date format | |
| let dayFormat = `${year}-${month}-${day}`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { BetaAnalyticsDataClient } from '@google-analytics/data'; | |
| // Creates a client. | |
| const analyticsDataClient = new BetaAnalyticsDataClient({ | |
| keyFile: './key.json' | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const sendNotifications = async function() { | |
| const allSubscriptions = await Subscription.Subscription.find(); | |
| allSubscriptions.forEach(function(item) { | |
| let ourMessage = JSON.stringify({ | |
| 'title' : req.body.titles[0].title, | |
| 'body' : req.body.description | |
| }); | |
| webpush.sendNotification(item.subscriptionEl, ourMessage).catch(error => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Service Worker Notifications | |
| const publicVapidKey = '<<<Public Vapid Key>>>'; | |
| const privateVapidKey = '<<<Private Vapid Key>>>'; | |
| webpush.setVapidDetails('mailto:someEmail@emailSite.com', publicVapidKey, privateVapidKey); | |
| app.post('/subscribe', jsonParser, async function(req, res) { | |
| try { | |
| let hash = objectHash(req.body); | |
| let subscription = req.body; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| npm i web-push -g | |
| web-push generate-vapid-keys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const vapidKey = '<<Your Public Vapid Key>>'; | |
| document.getElementById('subscribe').addEventListener('click', async function(e) { | |
| const registration = await navigator.serviceWorker.register('worker.js', {scope: '/'}); | |
| const subscription = await registration.pushManager.subscribe({ | |
| userVisibleOnly: true, | |
| applicationServerKey: urlBase64ToUint8Array(vapidKey) | |
| }); | |
| await fetch('/subscribe', { | |
| method: 'POST', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for f in $(find /link/to/your/directory/goes/here -name '*.png' -or -name '*.jpg' -or -name '*.jpeg'); do cwebp -q 60 $f -o ${f%.*}.webp; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <picture> | |
| <source srcset="241220204.webp" type="image/webp" /> | |
| <img src="241220204.png" alt="Some alt text goes here" /> | |
| </picture> |