|
| 1 | +--- |
| 2 | +title: "Plugins" |
| 3 | +sidebar_position: 300 |
| 4 | +--- |
| 5 | + |
| 6 | +[Plugins](/docs/sources/trackers/google-tag-manager/plugins/index.md) provide an easy way to distribute custom behavior for the tracker. |
| 7 | +Each Plugin can be loaded from external URLs or provided inline within GTM, and can optionally take some custom configuration. |
| 8 | +A Plugin may add new methods to the tracker that can be called via [Custom Commands](#custom-commands). |
| 9 | + |
| 10 | +:::note |
| 11 | + |
| 12 | +Snowplow Plugins are updated alongside the tracker SDK to ensure compatibility. For best results, keep the SDK and plugin versions in sync: |
| 13 | + |
| 14 | +- CDN Users: Use a GTM Variable to manage versions in URLs. |
| 15 | +- Self-Hosting: Update plugin files whenever you update the SDK. |
| 16 | + |
| 17 | +::: |
| 18 | + |
| 19 | +## `Load Plugins` table |
| 20 | + |
| 21 | +Plugins are configured by using the **Load Plugins** table, within the Snowplow tag. Each row takes three values to load a plugin. |
| 22 | + |
| 23 | +:::tip |
| 24 | + |
| 25 | +Plugins are loaded by the tracker SDK directly, not via the Tag Template: |
| 26 | +You do not need to adjust the Template permissions to allow loading plugins from these URLs. |
| 27 | + |
| 28 | +::: |
| 29 | + |
| 30 | +### Plugin URL |
| 31 | + |
| 32 | +The URL to load the Plugin from, e.g. `https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-link-click-tracking@latest/dist/index.umd.min.js` |
| 33 | + |
| 34 | +The tracker will try to load plugins each time they are requested. |
| 35 | +This is usually acceptable as the browser will have cached the first request; if you don't want this behavior we suggest creating an empty **Custom Command** Tag with no commands that loads the plugins; you can make this Tag fire [once per page](https://support.google.com/tagmanager/answer/6279951) and add it as a [Setup Tag](https://support.google.com/tagmanager/answer/6238868) to any other Tags that use its commands. |
| 36 | + |
| 37 | +### Plugin Configuration |
| 38 | + |
| 39 | +The name of the Plugin to load. These values can be found on the respective plugin documentation. |
| 40 | + |
| 41 | +For example, for the `Link Click Tracking` plugin, the values (`'snowplowLinkClickTracking,LinkClickTrackingPlugin'`) can be found in the snippet [here](https://docs.snowplow.io/docs/sources/trackers/javascript-trackers/web-tracker/tracking-events/link-click/#enable-link-click-tracking). |
| 42 | + |
| 43 | +### Additional Configuration (optional) |
| 44 | + |
| 45 | +Finally, the optional **Additional Configuration** field allows you to add any configuration the Plugin may require. |
| 46 | + |
| 47 | +There are two ways to format additional configuration: |
| 48 | + |
| 49 | +- A single comma-seperated string value, which will be split into an array of strings and passed as arguments to the Plugin. (e.g. `arg1,arg2,arg3`) |
| 50 | +- A reference to a GTM Variable containing an Array of arguments to pass to the Plugin. |
| 51 | + |
| 52 | +Plugins are loaded in order, and processed before the configured **Tag Type** configuration is executed -- so you can load a plugin in the same Tag that uses its functionality via Custom Commands. |
| 53 | + |
| 54 | +The plugins will remain configured in the tracker and be accessible to later Tags. |
| 55 | + |
| 56 | +:::warning |
| 57 | + |
| 58 | +The Tag Template will try to call `.indexOf(',')` on the **Additional Configuration** value, so values of types other than Array or String may fail and break the Tag. |
| 59 | +String values (before or after splitting) of `true`, `false`, `null`, and numeric values will become their respective typed JSON values. |
| 60 | +It is not possible to pass a single `null`, `undefined`, or empty string value as a parameter to a Plugin, instead no arguments will be passed to the plugin. |
| 61 | + |
| 62 | +::: |
| 63 | + |
| 64 | +## Inline Plugins |
| 65 | + |
| 66 | +[Inline Plugins](/docs/sources/trackers/javascript-trackers/web-tracker/plugins/creating-your-own-plugins/index.md#inline-plugins) are plugins that don't require being fetched from an external file to load. |
| 67 | + |
| 68 | +You can create Inline Plugins in GTM by using Custom JavaScript Variables in the **Plugin URL** field. |
| 69 | +The Variable should return an Object with a method that returns another Object meeting the [Plugin Interface](/docs/sources/trackers/javascript-trackers/web-tracker/plugins/creating-your-own-plugins/index.md#plugin-interface) (any other methods on the outer Object will become tracker methods). |
| 70 | + |
| 71 | +For **Plugin Configuration**, the UI enforces the comma-seperated values syntax required for external Plugins and unconditionally calls `.split(',')` on the string. |
| 72 | +The SDK requires that for inline-plugins only a single string may be used. |
| 73 | +To work around this limitation, create another Custom JavaScript Variable that returns your constructor method name wrapped in an Object with a fake `split()` method: |
| 74 | + |
| 75 | +```javascript |
| 76 | +function() { |
| 77 | + return { |
| 78 | + split: function() { |
| 79 | + return "myInlineConstructorMethodName"; |
| 80 | + } |
| 81 | + }; |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +:::info |
| 86 | + |
| 87 | +If your configuration includes functions, GTM will wrap those functions in [its sandbox](https://developers.google.com/tag-platform/tag-manager/templates/sandboxed-javascript), even when passed to the SDK for execution. |
| 88 | + |
| 89 | +Complex values like DOM elements will be replaced by `null` when passed to or returned from your function, which may make some plugins not function as intended. |
| 90 | + |
| 91 | +::: |
0 commit comments