Skip to content

Instantly share code, notes, and snippets.

@DaveGoosem
DaveGoosem / Sitecore-CDP-Campaign-Audience.js
Created August 16, 2022 07:17
For usage with Sitecore CDP/Personalize - access some properties added to your page view events for UTM attribution to use with campaigns in CDP
// Use server-side JavaScript to filter your audience further
// You have full access to the guest context which can be accessed under guest, e.g. guest.email
// Any truthy return value will pass the audience filter, it is recommended to return an object
// The value returned can be accessed from the variant API response as 'filter'
(function () {
var converted = "[[Has/Has not | enum(has, has not) | has | { required: true }]]";
var campaignName = "[[Campaign(s) | multiselect() | | { required: true }]]";
var campaignValues = campaignName.split(',');
var expectedType = "WEB";
@DaveGoosem
DaveGoosem / DeveloperEnvironmentSetup.ps1
Last active September 28, 2020 03:18
Developer Environment Setup Scripts
#INSTALL CHOCOLATEY: https://chocolatey.org/docs/installation
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
#Install GIT FORK: https://chocolatey.org/packages/git-fork
choco install git-fork -y
#Install Visual Studio: https://chocolatey.org/packages?q=visual+studio+2019
choco install visualstudio2019enterprise -y
#Install Visual Studio Code: https://chocolatey.org/packages/vscode
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<contentSearch>
<!-- Configuration sections for indexes -->
<indexConfigurations>
<!-- If an index has no configuration specified, it will use the configuration below. The configuration is not merged if the index also has
configuration, it is either this configuration or the index configuration. -->
<customSolrIndexConfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
<!-- This flag will index all fields by default. This allows new fields in your templates to automatically be included into the index.
@DaveGoosem
DaveGoosem / copy_files_with_folders.ps1
Created October 24, 2016 11:41
Quick Powershell script to copy files and keep folder structure with file type filtering
$SourceFolder = "D:\Downloads"
$DestinationFolder = "D:\test"
$IncludeFiles = ("*.jpeg","*.jpg")
Get-ChildItem $SourceFolder -Recurse -Include $IncludeFiles | Where-Object {$_.LastWriteTime -gt $ChangesStarted} | ForEach-Object {
$PathArray = $_.FullName.Replace($SourceFolder,"").ToString().Split('\')
$Folder = $DestinationFolder
@DaveGoosem
DaveGoosem / switchSitecoreContext.cs
Created May 1, 2014 13:41
Switch Sitecore context
using (new SiteContextSwitcher(SiteContextFactory.GetSiteContext("shell")))
{
//perform actions
}
@DaveGoosem
DaveGoosem / faq.ascx.cs
Created January 25, 2014 08:27
Example FAQ Sitecore Sublayout built for Sitecore Page Editor using Edit Frame and repeater
namespace <insert namespace here>
{
public partial class FAQListing : SublayoutBaseExtended //this includes to get DataSourceItem or set to default item if none specified.
{
private Item[] DataItems { get; set; }
private string DataSourceItemPath { get; set; }
public virtual Item GetDataSourceItem()
{
@DaveGoosem
DaveGoosem / performance-analysis.js
Created November 12, 2013 14:55
Simple Javascript Performance Testing. Write the same code using different methods and then use this to test execution time (can output it to console). Dev tools may / may not give you same results.
/*
* We need to run the code sample more than once to get a better idea of running time during analysis.
* set this value to be however many times you want to run the code to get a good analysis
* of running time
*/
var maxCount = 20;
var start = new Date().getTime();
for (var n = 0; n < maxCount; n++) {
/* perform operation you want to measure */
}
@DaveGoosem
DaveGoosem / geolookup.js
Created November 5, 2013 01:23
geo lookup from google api sample code which uses callback query string to load <script> for gmaps api only if element exists on page
/*!
* GeoLocation
* @requires jQuery v1.7.2+
*
* Description
* auto-populates a field with geo-location data
*/
; (function ($) {
window.Motorama.geoLocation = window.Motorama.geoLocation || window.Motorama.BaseModule(function () {
@DaveGoosem
DaveGoosem / MediaLibraryExporter.aspx
Created August 21, 2013 00:21
Export Sitecore Media Library Images to file system
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MediaLibraryExporter.aspx.cs" Inherits="RBSM.MediaLibraryExporter" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
@DaveGoosem
DaveGoosem / javascriptModel.js
Last active August 4, 2023 05:30
JavaScript Module Model base. Pinched from Simon here: https://gist.github.com/captainclam/3290833
/*!
* ProjectName SomeModule
* @requires jQuery v1.7.2+
* @requires Underscore v1.3.3+
*
* This comment block is here to encourage you to properly document your modules
* USE IT!
* Particularly if it has odd dependencies they should be listed.
*/