Skip to content

Instantly share code, notes, and snippets.

# Copyright (c) 2013-2018 Snowplow Analytics Ltd. All rights reserved.
#
# This program is licensed to you under the Apache License Version 2.0, and
# you may not use this file except in compliance with the Apache License
# Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
# http://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License Version 2.0 is distributed on an "AS
# IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
@sahava
sahava / customtask-builder
Last active February 26, 2019 09:53
customTask Builder
<div id="customTaskWrapper">
<table>
<thead>
<tr>
<th>Click to select which feature(s) to include</th>
</tr>
</thead>
<tbody>
<tr>
<td data-customtask-id='cid' data-customtask-selected='false'>Client ID as a Custom Dimension</td>
function() {
// Update this array with the class names
var classes = ['class1', 'class2', 'class3'];
// Fetch elements
var els = document.querySelectorAll('.' + classes.join(',.'))
return [].map.call(els, function(e) {
// Get first matching class name per element
return classes.filter(function(c) {
return e.className.indexOf(c) > -1;
@sahava
sahava / customTaskMonster
Last active August 6, 2020 20:58
One customTask to rule them all.
var _customTask = function () {
// customTask Builder by Simo Ahava
//
// More information about customTask: https://www.simoahava.com/analytics/customtask-the-guide/
//
// Change the default values for the settings below.
// clientIdIndex: The Custom Dimension index to where you want to send the visitor's Client ID.
// https://bit.ly/2Ms0ZcC
var clientIdIndex = 1;
@sahava
sahava / add-missing-datalayer-event.js
Created February 26, 2019 08:13
This piece of code adds a default 'event' key-value to each dataLayer.push() that hasn't got one.
(function() {
var oldPush = window.dataLayer.push;
window.dataLayer.push = function() {
var states = [].slice.call(arguments, 0);
states.forEach(function(s) {
if (!s.hasOwnProperty('event')) {
s.event = 'default';
}
});
return oldPush.apply(window.dataLayer, states);
@sahava
sahava / template.tpl
Last active February 13, 2021 19:23
Advanced Universal Analytics - Custom Template demo
___INFO___
{
"type": "CLIENT",
"id": "cvt_temp_public_id",
"__wm": "VGVtcGxhdGUtQXV0aG9yX0FkdmFuY2VkVW5pdmVyc2FsQW5hbHl0aWNzLVNpbW8tQWhhdmE\u003d",
"categories": [
"ANALYTICS"
],
"version": 1,
@sahava
sahava / template.tpl
Last active February 16, 2021 07:08
Advanced Universal Analytics (updated) - Custom Template demo
___INFO___
{
"type": "CLIENT",
"id": "cvt_temp_public_id",
"__wm": "VGVtcGxhdGUtQXV0aG9yX0FkdmFuY2VkVW5pdmVyc2FsQW5hbHl0aWNzLVNpbW8tQWhhdmE\u003d",
"categories": [
"ANALYTICS"
],
"version": 1,
@sahava
sahava / gtmContainerPolicy.js
Created February 20, 2021 21:23
Sample Server container policy file
gtag('policy', 'all', function(container, policy, data) {
switch (policy) {
// Only allow _ga cookie to be set.
case 'set_cookies':
return data.name === '_ga';
// All other permission requests are allowed.
case 'access_response':
case 'access_template_storage':
@sahava
sahava / template.tpl
Created March 4, 2021 08:56
Event Data To BigQuery - DEMO of the BigQuery API
___INFO___
{
"type": "TAG",
"id": "cvt_temp_public_id",
"version": 1,
"securityGroups": [],
"displayName": "Event data to BigQuery",
"brand": {
"id": "brand_dummy",
@sahava
sahava / template.tpl
Last active April 13, 2021 06:42
Facebook (updated) - Custom Template demo
___INFO___
{
"type": "TAG",
"id": "cvt_temp_public_id",
"version": 1,
"securityGroups": [],
"displayName": "Facebook",
"brand": {
"id": "brand_dummy",