This plugin provides Integration with Google Tag Manager
Add the following maven dependency to your pom.xml file:
<dependency>
<groupId>org.cruxframework.plugin</groupId>
<artifactId>crux-google-tag-manager</artifactId>
<version>1.0.0</version>
</dependency>
Inherit the plugin module on your GWT module config file (YOUR_MODULE.gwt.xml):
<inherits name='org.cruxframework.crux.plugin.google.gtm.GTM' />
You can interact with the plugin programmatically through org.cruxframework.crux.plugin.google.gtm.client.GoogleTagManager
class.
First, you need to initialize the GTM on your site. To do this, you must call the initialize
method:
@Expose
public void onLoad()
{
GoogleTagManager.init("Your GTM code"); // something like GTM-XXXXXX
}
Then, you can push variables and events like:
GoogleTagManager.pushVariable("testVariable", "testValue");
GoogleTagManager.pushEvent("myEvent");
GoogleTagManager.pushVariables(new Variable("var1", "value1"),
new Variable("var2", "value2") //, ...
);