While tinkering with the SnowStorm plugin on my forums today, I got to thinking about how to schedule it so it automatically turns on and off when I want it to. For example, maybe you want it to only snow on your forum on Dec 25th and no other day. Or maybe you want it for the whole month of December. Maybe you want floaty hearts on your forum on Valentines Day. Whatever.
My solution was to use the Pockets plugin in combination with Google Tag Manager.
- choose to install the SnowStorm vanilla plugin and just not enable it
- download and unzip the js files themselves into a new subdir under the plugins directory (which is what I did as snow_js)
- or maybe even launch it from a CDN if you can find a hosted version somewhere that doesn't mind you stealing it
Anyway, once you have the URL of the code, create a new Custom HTML Tag type in GTM that contains:
(I add the versioning to the .js URL like Vanilla does, in case I want to edit the .js and avoid cache issues by incrementing it in GTM)
Set your GTM firing rules for the tag to "All pages," then Save, and Publish.
Test to make sure it works on your site as expected. Tinker with .js as necessary.
When you're happy, go back into GTM, edit the tag, and drop down the Advanced Settings. Select Enable custom tag firing schedule, pick your time zone, and your start and end dates.
Save and re-publish.
You can set a whole year's worth of holiday Javacsript fun on your forum without having to touch your site! Just go into GTM, set them for the year, and enjoy!