Skip to content

Commit

Permalink
feat: add support for shopware 6.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tinect committed Apr 10, 2024
1 parent 841c772 commit bb85956
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pack-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
uses: FriendsOfShopware/actions/.github/workflows/github.yml@main
with:
extensionName: TinectMatomo
shopwareVersion: 6.4.11
shopwareVersion: 6.5.0
secrets:
ghToken: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions .shopware-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
build:
zip:
composer:
enabled: false
assets:
enabled: true
enable_es_build_for_admin: true
enable_es_build_for_storefront: true
pack:
excludes:
paths:
- .gitignore
45 changes: 22 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
{
"name": "tinect/matomo",
"version": "2.0.0",
"description": "Matomo plugin for shopware 6",
"type": "shopware-platform-plugin",
"license": "MIT",
"autoload": {
"psr-4": {
"Tinect\\Matomo\\": "src/"
}
},
"require": {
"php": "~8.0||~8.1||~8.2||~8.3",
"shopware/core": "~6.4.11"
},
"conflict": {
"jinya/matomo-shopware-plugin": "*"
},
"extra": {
"shopware-plugin-class": "Tinect\\Matomo\\TinectMatomo",
"label": {
"de-DE": "Matomo Tracking",
"en-GB": "Matomo Tracking"
}
"name": "tinect/matomo",
"version": "3.0.0",
"description": "Matomo plugin for shopware 6",
"type": "shopware-platform-plugin",
"license": "MIT",
"autoload": {
"psr-4": {
"Tinect\\Matomo\\": "src/"
}
},
"require": {
"shopware/core": "~6.5.0"
},
"conflict": {
"jinya/matomo-shopware-plugin": "*"
},
"extra": {
"shopware-plugin-class": "Tinect\\Matomo\\TinectMatomo",
"label": {
"de-DE": "Matomo Tracking",
"en-GB": "Matomo Tracking"
}
}
}
45 changes: 27 additions & 18 deletions src/Resources/app/storefront/src/plugin/MatomoAnalyticsPlugin.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
import Plugin from "src/plugin-system/plugin.class";
import CookieStorageHelper from "src/helper/storage/cookie-storage.helper";
import {COOKIE_CONFIGURATION_UPDATE} from "src/plugin/cookie/cookie-configuration.plugin";

export default class MatomoAnalyticsPlugin extends Plugin {
export default class MatomoAnalyticsPlugin extends window.PluginBaseClass {
init() {
this.cookieEnabledName = 'matomo-analytics-enabled';
window.matomoCookieActive = Boolean(CookieStorageHelper.getItem(this.cookieEnabledName));
window.matomoCookieActive = Boolean(this.getCookieItem(this.cookieEnabledName));

this.startMatomoAnalytics();
}
document.$emitter.subscribe('CookieConfiguration_Update', this.handleCookies.bind(this));

startMatomoAnalytics() {
window.mTrackCall();
}

handleCookieChangeEvent() {
document.$emitter.subscribe(COOKIE_CONFIGURATION_UPDATE, this.handleCookies.bind(this));
}

handleCookies(cookieUpdateEvent) {
const updatedCookies = cookieUpdateEvent.detail;

Expand All @@ -33,10 +23,6 @@ export default class MatomoAnalyticsPlugin extends Plugin {
}

removeCookies() {
if (!CookieStorageHelper.isSupported()) {
return;
}

const allCookies = document.cookie.split(';');
const gaCookieRegex = /^(_pk)/;

Expand All @@ -46,7 +32,30 @@ export default class MatomoAnalyticsPlugin extends Plugin {
return;
}

CookieStorageHelper.removeItem(cookieName);
document.cookie = `${cookieName}= ; expires = Thu, 01 Jan 1970 00:00:00 GMT;path=/`;
});
}

getCookieItem(key) {
if (!key) {
return false;
}

const name = key + '=';
const allCookies = document.cookie.split(';');

for (let i = 0; i < allCookies.length; i++) {
let singleCookie = allCookies[i];

while (singleCookie.charAt(0) === ' ') {
singleCookie = singleCookie.substring(1);
}

if (singleCookie.indexOf(name) === 0) {
return singleCookie.substring(name.length, singleCookie.length);
}
}

return false;
}
}

0 comments on commit bb85956

Please sign in to comment.