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
/* | |
* written by Nico Brooks - www.twooctobers.com | |
* use at your own risk | |
* | |
* This script provides a generic framework for scheduling | |
* monthly AdWords reports and writing them to a Google sheet. | |
* To use, copy the script, set the global variables at the top of the file | |
* and customize the function getData. See | |
* https://developers.google.com/adwords/api/docs/guides/awql | |
* for reporting options |
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
/* | |
updated 2018-04-28 | |
source lives here: https://gist.github.com/nicobrx/2ecd6fc9ca733dcd883afebba5cf200e | |
standalone script ID for use as a library: 1gZ78JObyrYiH0njoZ86fQ2NgMwavUgiXVhRDrIFetPZL256e31PSNiHq | |
Functions included here: | |
Sheets data array and object functions | |
objectifySheet(sheet,propertyNames,newPropertyNames) - Takes a sheet with a header row and converts it into an array of objects | |
arrayFromSheet(sheet,propertyNames,newPropertyNames) - creates an array from a sheet, can specify column headers |
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
/** | |
* Writes a list of AdWords accounts in an MCC to a Google Sheet | |
* Useful in conjunction with scripts that run on batches of accounts | |
* | |
* The label-batching portion of this script was adapted from: | |
* http://magentosupport.help/knowledgebase/using-labels-to-executeinparallel-exceeding-the-50-account-limit/ | |
*/ | |
var TIMEZONE = 'MST'; | |
var TODAY_STR = Utilities.formatDate(new Date(), TIMEZONE, 'yyyy-MM'); |
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
<script> | |
/* | |
* adapted from https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#iframes | |
* I include the GA object reference in my script, so that one version of | |
* the script works whether served in an iFrame or on a standalone page. | |
* I usually have to rely on the 3rd-party vendor to implement the code, so | |
* I like to keep implementation as simple as possible. | |
*/ | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
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
<script> | |
/* | |
* adapted from https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#iframes | |
* I wrapped the whole thing in a setTimeout, so I could observe the delayed execution time | |
* of the GA function in the JavaScript console, using the GA debugger Chrome plugin. | |
* alternatively, you could just wrap the frameWindow.postMessage in a setTimeout | |
*/ | |
setTimeout(function(){ | |
ga(function(tracker) { |
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
<script> | |
if(!(window.ga && ga.create)) { | |
dataLayer.push({'event': 'gaNotLoaded'}); | |
} | |
</script> |
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
SELECT | |
event_date, | |
COUNT(DISTINCT(session_id)) AS sessions, | |
SUM(ga4_resource_page_views) AS ga4_resource_page_views | |
FROM ( | |
SELECT | |
CONCAT(user_pseudo_id,(SELECT value.int_value FROM UNNEST(event_params) WHERE KEY = 'ga_session_id')) AS session_id, | |
COUNT((SELECT value.string_value FROM UNNEST(event_params) WHERE KEY = 'page_location' | |
AND value.string_value LIKE 'https://twooctobers.com/blog/ga4-resources/%')) AS ga4_resource_page_views, | |
PARSE_DATE('%Y%m%d',event_date) AS event_date |
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
SELECT | |
page_location, | |
SUM(engagement_time_seconds) AS engagement_time_seconds, | |
SUM(page_views) AS page_views, | |
SAFE_DIVIDE( SUM(engagement_time_seconds), SUM(page_views) ) AS average_engagement_time_per_page | |
FROM ( | |
SELECT | |
( | |
SELECT | |
value.string_value |
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
--Looker Studio BigQuery custom query to get sessions per user | |
with s as (select distinct | |
user_pseudo_id, | |
concat(user_pseudo_id,(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id')) AS session_id, | |
timestamp_micros(event_timestamp) as timestamp | |
from `yourbqproject.analytics_1234567.events_*` | |
where _table_suffix between @DS_START_DATE and @DS_END_DATE | |
and event_name = 'session_start') |
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
-- set dates here so we don't have to update them in multiple places | |
with dates as ( | |
select | |
'20230812' as start_date, | |
-- the next line gets yesterday | |
format_date('%Y%m%d',date_sub(current_date(), interval 1 day)) as end_date | |
), | |
-- get all events with event values | |
p as ( |
OlderNewer