Skip to content

Instantly share code, notes, and snippets.

View prabapro's full-sized avatar
🍃
Working from home

Praba Ponnambalam prabapro

🍃
Working from home
View GitHub Profile
@ZordnajelA
ZordnajelA / ga4_parameter_value_function.sql
Last active July 26, 2023 16:12
Bigquery SQL Function to obtain the value of a given parameter (as a string) from a Google Analytics 4 event and its original value type in case it's needed
CREATE OR REPLACE FUNCTION `YOUR_PROJECT.YOUR_DATASET.GA4_parameter_value_and_type`(
parameter_key_to_be_queried STRING,
event_params ARRAY<STRUCT<key STRING,
value STRUCT<
string_value STRING,
int_value INT64,
float_value FLOAT64,
double_value FLOAT64
>
>
@leighajarett
leighajarett / code.gs
Created November 15, 2021 15:05
Example of using Apps Script to populate Google Slides with data from BigQuery
//// Using BigQuery query results to populate a template slide deck ////
// This object defines the queries associate with each of the params used in the template
// Note that you may want to use functions defined within BigQuery instead of parameterized queries
var queryObj = {
"new_cust": "SELECT COUNT(*) FROM `looker-private-demo.retail.customers` as custs " +
"JOIN `looker-private-demo.retail.transaction_detail` as trans ON custs.id = trans.customer_id " +
", UNNEST(trans.line_items) as line_items " +
"WHERE TIMESTAMP_TRUNC(custs.created_at,WEEK) = @week " +
"AND line_items.product_id in (select id from `looker-private-demo.retail.products` where category = @team);",
@leighajarett
leighajarett / sample_slides_appscript.gs
Created August 18, 2021 02:28
sample_bq_slide_appscript
//// Using BigQuery query results to populate a template slide deck ////
// This object defines the queries associate with each of the params used in the template
var queryObj = {
"new_cust": "SELECT COUNT(*) FROM `looker-private-demo.retail.customers` as custs " +
"JOIN `looker-private-demo.retail.transaction_detail` as trans ON custs.id = trans.customer_id " +
", UNNEST(trans.line_items) as line_items " +
"WHERE TIMESTAMP_TRUNC(custs.created_at,WEEK) = @week " +
"AND line_items.product_id in (select id from `looker-private-demo.retail.products` where category = @team);",
"rep_rate": "WITH repeat_orders as " +
@prabapro
prabapro / readme.md
Created September 1, 2020 16:33
GTMTips: Prevent Clicks And Form Submits From Redirecting - Bookmarklet

GTMTips: Prevent Clicks And Form Submits From Redirecting

Extracted from Simo Ahava's Blog Post

Using Custom beforeunload script

Google Tag Manager offers us some nice built-in triggers so that we can automatically listen for specific user interactions on the website, reacting to them however we wish, though typically it would be to fire a tag. The tricky thing especially with the click triggers and form submission tracking is that the page has a nasty habit of redirecting you to the link or form target page before letting you see the respective data in Google Tag Manager’s excellent preview mode.

>This solution should work with all redirects regardless of how they’re implemented. The trick is to add an event listener to the beforeunload browser, opening a prompt that asks if you really want to leave the current page. You can then press “Cancel” (or equivalent) to stay on the current page to see what the browser event w

// Parse the IDs from the first four rows of the sheet
function getIds() {
const sheet = SpreadsheetApp.getActiveSheet();
const ids = {
accountId: sheet.getRange('B1').getValue().toString(),
containerId: sheet.getRange('B2').getValue().toString(),
workspaceId: sheet.getRange('B3').getValue().toString(),
variableId: sheet.getRange('B4').getValue().toString()
};
if (ids.workspaceId.toLowerCase() === 'default') ids.workspaceId = getDefaultWorkspaceId(ids.accountId, ids.containerId);
// Call with decorateUrl('https://www.domain.com/url', 'UA-12345-1');
// Outputs the URL string with the Universal Analytics cross-domain linker in place.
// Tracking ID is optional. If you leave it out, the linker will be built
// with the settings of the first tracker found on the page.
function decorateUrl(urlString, trackingId) {
var ga = window[window['GoogleAnalyticsObject']];
if (ga && ga.getAll) {
var trackers = ga.getAll().filter(function(t) {
return trackingId ? t.get('trackingId') === trackingId : true;
});
@misterhay
misterhay / bitly-api-with-google-apps-script.gs
Last active May 12, 2023 20:54
JavaScript code to interact with the Bitly API
function bitlyGroupId() {
var accessToken = ''; // paste in your access token from https://bitly.is/accesstoken
var headers = {'Authorization' : 'Bearer '+accessToken};
var params = {'headers' : headers};
var fetchUrl = 'https://api-ssl.bitly.com/v4/groups';
var response = UrlFetchApp.fetch(fetchUrl, params);
var group_guid = JSON.parse(response.getContentText()).groups[0].guid;
Logger.log(group_guid)
return group_guid
}
"use strict";
const express = require("express");
const app = express();
app.get("/", (req, res) => {
console.log(req.headers);
console.log(req.url);
console.log(req.ip);
console.log(req.hostname);
console.log(req.method); //get
@lucasjahn
lucasjahn / gtm-maps-initeraction-tracking.js
Created November 28, 2019 00:01
Google Tag Manager (GTM) - Google Maps Interaction Tracking
(function () {
/**
* sends a custom event with a given type to google analytics
*
* @param {String} type - type of the event to send
*/
function sendMapEvent(type) {
if(!readCookie('googleMapInteracted')) {
dataLayer.push({
'event': 'googlemaps',
@Beneboe
Beneboe / how-to-setup-verified-commits.md
Last active June 18, 2024 17:16
How to Setup Verified Commits on Github